Push RouterOS metrics to InfluxDB

Here is a really simple and easy way to push metrics (or any value) from RouterOS right into InfluxDB:

I needed this to grab some simple numbers to put on a Grafana dashboard so I set the script above to run every 5 minutes. So far this has worked really well.

Stream to youtube from Unifi NVR

Here is a short script which uses ffmpeg to stream video from a Unifi NVR straight to Youtube. I experimented with a few different ffmpeg options and found this one produces the best stream with the best audio.

The first stream URL is generated by creating a stream for the camera in Unifi video. The second URL is the stream URL from youtube.

Fix for nonfunctioning power window in 2007 Mazda3

I’ve been having trouble with the driver’s side power window on my 2007 Mazda3 for a while. The window would go down, but wouldn’t go back up. Researching the problem online, this is a super common issue, but the suggested fixes are to replace whole assemblies, slam the door hard (to release a jammed mechanism), or to ‘recalibrate’ the motor controller.

I was able to fix it for zero cost so I am documenting the solution online here in the hope that it will help others: Completely disassemble the switch assembly, and then apply some pencil (graphite) to the contact pads of the tactile membrane switch. It’s an old trick, and this perfectly fixed my issue, was very quick and simple, and cost nothing, so I am documenting it here. More detail/pics below:

Continue reading

Sonoff, meet powerstrip

I recently became super fascinated with ESP8266 hardware, and it wasn’t long before I also found out about and ordered a couple of ESP8266-based Sonoff AC switches to play with (immediately flashing them with some generic MQTT firmware). They work wonderfully and are just too cheap to resist.

It also wasn’t very long until I began wondering whether I could jam the bare PCB from the Sonoff right into a power strip. I took apart the closest one and was pleased to find that (with only a little bit of creative modification of the plastic ribs and bosses) the bare Sonoff PCB fit inside perfectly. Too perfectly:

SDIM1329

Obviously, this is extremely unsafe, so don’t ever do this – or will burn your house down, kill your pets and loved ones and so on. More pictures of how not to do this follow..

Continue reading

Netinstall for RouterOS in Virtualbox (on Mac OS)

I recently ‘bricked’ my Mikrotik HAP AC Lite router – the router didn’t have enough room on its flash memory to install an update, but – in an unexpected turn of events – tried to apply the firmware update anyway, and became un-bootable.

Fortunately, Mikrotik supply a bit of software (‘Netinstall’) which is able to re-flash the devices using BOOTP, but this software won’t run in Wine (it requires root to bind to the low BOOTP port, yada yada).

For Mac users, this means it’s really only possible to run it in a VM (in my case, in Windows 8.1, in Virtualbox on Mac OS 10.11 El Cap). Since this added a few additional layers of very un-wanted hassle at a quite stressful time, I thought I would leave some hints here – tips and screenshots below. Happy flashing! Continue reading

Quick RouterOS script for hurricane electric 6to4 tunnel dynamic updating

If your ISP doesn’t offer IPv6 you may have set up an IPv6 6to4 tunnel using Hurricane Electric’s free ‘tunnelbroker.net‘ service.

To operate the tunnel, tunnelbroker.net requires that you configure an IPv4 endpoint/client IP in their tunnel configuration. Additionally, the Mikrotik RouterOS ‘6to4’ tunnel interface requires this same IPv4 address is (redundantly) entered as the 6to4 interface’s 'local-address' property value. If you are given a dynamic public IP address by your ISP, this is a bit messy!

Here is a quick script (I suggest running it periodically) which will:

    • Use Mikrotik’s Cloud IP service (which obviously must be enabled) to resolve your WAN IP,
    • Check that IP against the local-address value in your 6to4 interface (which is assumed to be the only interface, named ‘sit1’) and
    • If the IPs do not match, will update tunnelbroker.net with your new WAN IP (using their dyn-compatible GET request method) and
    • Update the ‘local-address’ of your 6to4 interface

You can obtain the necessary values (<USERNAME>, <PASSWORD> (which is hashed) and <TUNNELID>) by logging into the tunnelbroker.net website, opening your tunnel details, then clicking the ‘advanced’ tab.

Note that it might be unnecessary to force the cloud IP service to update – I believe it does this every minute anyway.

Something worth noting too is that the endpoint/client IP for the tunnelbroker.net tunnel (ie. your WAN IP) must respond to ICMP pings from tunnelbroker before it can be set up on the tunnelbroker.net website. If you’re blocking ICMP, configuring the tunnel endpoint on the tunnelbroker.net website will just mysteriously fail.

Send Slack messages from Mikrotik RouterOS

This is a quick RouterOS script hack which I just wanted to get up online; it’s not anywhere near perfect but it might be useful to others. My objective here was to post a message to any Slack channel from Mikrotik RouterOS:

RouterOS to Slack

Slack has a super-simple to use ‘incoming webhook‘ integration but unfortunately, this requires that your app make a HTTP POST request – unfortunately not actually possible with RouterOS. Luckily, you can alternatively send messages using a HTTP GET request to Slack’s chat.postMessage API method. All you’ll need to do this is an API test token, which you can generate here.

Once you have your test token (beginning xoxp-..) you can form a HTTP GET request, including your message and any additional args (username, icon, channel..) as per the script below. Submitting a message is as easy as making a /tool fetch url command in your script.

To actually implement this usefully, the script below will parse the log file (ref.) for topics of interest, URL-encode any unsafe ASCII characters (non-exhaustive…) then post a message to your nominated Slack channel.

Todo: Read multiple log lines and post them as a single message using newlines, make logging topics and keywords better.

Quota-based traffic usage alerts in LibreNMS

Out of the box, LibreNMS does not readily expose traffic transfer measurements – it is geared towards network operators who buy (and sell) transit bandwidth wholesale, and not really for the home-gamer who just wants to stay under their ISP’s data cap.

As per the documentation, LibreNMS’ billing module can be enabled in config.php, and this will allow us to track and historise data usage for an interface in a nice billing page. Once billing is enabled we can add a new bill: under Ports > Bills, hit ‘add new’ and select a device and interface to measure against (you can add more than one interface per bill). Select ‘quota’ if, like me, you are interested in total transfer (not 95th percentile traffic).

But what if we also want to generate alerts when a device/interface exceeds a given threshold? Well, then we also need to add the following macro in config.php (thanks to laf on ##librenms):

More detail – including screenshots – after the break:

Continue reading

Reverse-engineering the IKEA “Ledberg” LED

This is an “Ledberg” LED downlight from IKEA:

ledberg

I really like it – the LED is a nice, warm white, it has a very high output (up to 3W) and the diffuser lens makes a nice soft spot. It’s low-profile, easy to mount, doesn’t require heatsinking, and is a complete solution including a 24VDC power supply, inline switch and driver circuit. And it’s only about $8. You can buy a three-pack (single power supply) for about $16.

I bought it with a little project in mind which will be the topic of a future post.

I was very curious about how the LED is being driven so I cracked this thing open while I was still on the bus home and spent the rest of the bus ride itching to get home to get it apart properly and satisfy my curiosity. Inside the puck enclosure is a tiny PCB with just 5 discrete surface mount components driving the single LED chip:

Continue reading

Read the RFCs

I recently moved a bunch of websites over to a VPS (likely the one you are reading this from). It runs Ubuntu with a LEMP stack.

I ran into some problems when I went to reconfigure my DNS Zones to reflect the change. The zones (combined) I created looked more-or-less like this:

There’s a lot of records pointing to vps.mydomain.com, and only one ‘A’ record for vps.mydomain.com that points to my VPS’s actual IPv4 address.
This way I just have to update the one record if my VPS’ IP address changes. Makes sense, doesn’t it?

I thought so, but could not make this configuration work. After some research, I learned that according to RFC 1912 s.2.4, a ‘TLD cannot be a CNAME’. When I adjusted the zone as below, it all worked again.

What’s frustrating is that both strategies actually seem to work when the NS records point to a cPanel server hosting the zone file, but do not when the zone is served directly by my registrar’s “free DNS hosting”. This led to an argument with my registrar/host where I declared that their DNS server was broken (when it was actually just following RFC strictly), and they maintained that there was “no way to have an A and an MX record in the same zone, which wasn’t right either. In the end, we were both wrong!

Monitoring and reporting 3G radio signal-strength (RSSI, dBm) on Mikrotik Routerboards

Monitoring a large number of Mikrotik Routerboards is easy using software and tools like LibreNMS and Oxidized, but it is unfortunately not possible to retrieve values for 3G/4G/etc signal-strength RSSI (in dBm) via SNMP when using interfaces like the Sierra MC8705 Mini-PCIe card.

However, using some RouterOS scripts, we can read and push the value for signal strength to a remote listening server using HTTP GET requests. In my case, the server is running Mango Automation software, which also handles the historising, trending and event-detection handling.

3g-signal

Continue reading

Raspberry Pi internet streaming radio station

My partner has been overseas for a few months and was desperately missing a local radio station. It doesn’t have an online stream that she can listen to and so she asked me whether I could record the station for ten hours – this just sounded like a hassle, so I set up an internet streaming station to permanently re-stream the local broadcast over the internet using my Raspberry Pi, a cheap USB sound card, a cheap DAB digial radio, and darkice/icecast to run the streaming server.

The output of lsusb showed the cheap USB sound card to be a “C-Media Electronics, Inc. CM108 Audio Controller”. I found that I could access the device using ALSA and the arecord utility (as long as I didn’t specify 2 channels):

Next, I tried to set up icecast2 with darkice. I’m using Raspbian and the standard raspbian-distributed package for darkice is not compiled with ALSA support, and I nearly fell down a rabbit-hole trying to get OSS-compatible emulation working.

In the end, I was able to compile and install darkice with ALSA and mp3 support by following the excellent instructions here:

Continue reading

Modbus TCP Temperature Sensor with Arduino and LM335

I used to hate on Arduino a bit, but have recently come around. I was having a conversation with a work colleague along the lines of how super easy it would be nowadays to build a temperature sensor with ethernet connectivity and a modbus interface. Remembering that I had an old Arduino board (with Ethernet) kicking around from some abandoned project years ago, I laid myself a little personal challenge: to see how quickly I could prototype such a device. The answer is: Really, surprisingly quickly!

Gluing together other people’s hard work together made this a trivial exercise, and it was kind of too easy. It felt a bit like cheating. And I think this kind of plug-n-play, lego block engineering has made me lazy – I know someone else has already done the legwork so all my time is spent evaluating the relative merit of one library against another, rather than engineering something tricky from first principles. I guess this is both the blessing and the curse of the Arduino phenomenon.

Continue reading

LibreNMS network monitor with Slack integration and Oxidized config versioning

I used to use Observium for network monitoring. After evaluating a couple of options – Cacti, Zabbix, Nagios – I found Observium, and loved its beautiful, well organised and extremely usable interface. Observium has two main drawbacks for me though:

A few months after running Observium, and being largely happy with it despite the shortcomings above, I found LibreNMS. LibreNMS is an earlier forked version of Observium, and basically exists to ensure the project is run by friendly, community-minded folks. They’ve also implemented a lot more functionality, making it a much more complete and rounded product.

Continue reading

Install Request Tracker 4 from source with lighttpd and postfix on Ubuntu 14.04

Request Tracker is a tried-and-tested ticketing system, written in Perl. The manual installation documentation is pretty clear but not tailored to any particular distribution or configuration and I still had to do a bit of digging around to complete the installation, so I am posting my notes in case they help others.

Unpack the latest release of the application to /usr/local/src:

After building you have to install the extra dependencies. Unfortunately make fixdeps didn’t do a great job. Here’s all the extra packages I installed:

For my installation I’m also using Postfix as MTA to Sendgrid.

SMTP for Sendgrid on Postfix can be configured as per:
https://www.linode.com/docs/email/postfix/postfix-smtp-debian7#settings-for-sendgrid

In /etc/postfix/main.cf add:

In /etc/postfix/sasl_passwd:

Then, generate the password hash as per the link above.

Here’s the configuration for /opt/rt4/etc/RT_SiteConfig.pm:

I chose to use Lighttpd as my webserver. After installing it, I placed the following in /etc/lighttpd/lighttpd.conf:

Then (as I was installing on Ubuntu) I removed apache2 from startup:

Terrariums are fun

I’ve been playing with terrariums. I made a lot, to try out different ideas. One was made with a LED in the bottom of the lid providing illumination.

IMG_20160306_145021

A few months on and a friend is looking after it for me. The plants (well – the weed) has gone crazy and a little mushy has grown:

Continue reading

3G Weather Station using MangoES and RouterBoard

I thought I would share a recent little side-project that I did at work, putting together a neat and tidy solution to take wind measurements over a three month period for a customer who is interested in installing small wind turbines at some of their rural radio repeater sites.

With a tame sparky on hand to do the fabrication and mounting, I built two almost-identical boxes for the customer, using a MangoES to log data from a Davis Instruments “Vantage Pro 2” weather station. All the equipment in the box is powered by an external DC supply (one site has 48VDC, one has 12VDC) provided by the customer.

mango-weather-station

Continue reading