Display Network Status on a Raspberry Pi LCD

The other day, a service on one of my computers quit and it took me a few days to actually notice it. Wanting to change that, I began looking into network monitoring options. An option I found was Nagios, and I just happened to have a Raspberry Pi B that I wasn’t currently using.

Getting Nagios installed on the Pi would be relatively easy, but made even easier by a ready made image file found here. Once I had Nagios running, I added some check_http services specifying the port of the running service on my PC and I had a system that could notify me.

Next step was to get email working. I wanted to use Gmail, so I made a new email account and followed the instructions here for getting Gmail to work. some of the issues I ran into was first, apt-get would not install the Perl modules, so I had to use cpan to install them. The other issue is that the instructions were old and TLSv1 wasn’t working with Gmail. So I had to edit the package file, which is not the best option, but worked in this case.

After that I was able to send a test email

Now that I had Nagios sending emails, I had a Adafruit LCD display that wasn’t being used and I thought this would be an excellent project to use it for. But, in order to use the Python libraries, I had to have a way to access the data and using Livestatus and Sockets seemed like the perfect solution. I started here following the instructions but I had an issue with the g++ compiler. I had 4.6 installed and apt-get told me that was the newest version, even though I knew I needed at least version 4.8 to compile. I ended up having to manually install version 4.8

After getting it to compile and adding the module to the nagios.cfg, I was able to test it with a simple python script. I made sure to add a failed service in order to get good feedback.

Now I’m getting results from Nagios into Python, I can go about writing the python file that will actually display the information on the LCD using the Adafruit libraries. Don’t forget to enable the I2C kernel support!

Now, I am not a Python programmer, in fact, I mainly deal with ladder logic in industrial AllenBradley PLCs, so don’t be too harsh if you’re judging the code. Maybe went a little overboard in the functions and could have done more with classes. Not really sure what best practice for Python is. But, either way, the code works!

It will turn on the screen whenever there is a change in the errors and allow you to scroll left or right through the errors. The up and down will change between showing the Nagios service and the error. Select turns the screen on or off. Nothing too fancy and a pretty simple scroll in use, but it works good enough to hang on the wall and if the screen is on, I know there is a change to look at. Hopefully I can take some much needed video soon.

 

 

Be Sociable, Share!

Leave a Reply