Simple Network Monitor With Blinkt

In my ongoing quest to try and learn Python, I’ve put together a very simple network monitor set-up which I thought I’d share with everyone. It’s running on an old Pi Zero, and monitors the availability of 8 servers or sites on my local intranet and the wider internet and sets the 8 LEDs on a Blinkt to either red or green depending if the relevant servers are up or down.

I’ve uploaded the code to Pastebin, and would appreciate any inputs from more experienced Python coders as to if/where if can be improved -

It initially sleeps for 30s to allow time for the network connections etc to get set up (during which time the LEDs are turned blue), and then afterwards it pings each server once at a 60s interval. The script runs at boot-up via a crontab job (as detailed in Sandy’s blog post on the subject). Also during the debugging I had it output the status of each server to the console, but that is commented out in the final script. However it would be quite simple to redirect either or both of the up/down messages into a log file along with a timestamp for more detailed records.

One thing I did notice is that if you shut the Pi down with the LEDs lit, they stay lit even when the Pi has fully shut down (at least as long as it’s still powered). So I’ve added a SIGTERM handler into the script to catch that and turn them all off.

Share and enjoy…

1 Like

Really nice work! :-)