Monitoring Room Temperatures with a Raspberry Pi and Nagios

Over the past couple months I’ve been implementing and building out a monitoring solution for our development and production systems. Since nagios is the most loved / hated monitoring solution I felt obliged to learn how it works. After fighting with user permissions, firewall rules, broken dependencies and basically any other problem it could throw my way I finally have a working Nagios system. Since I like bootstrap and making configuration as painless as possible I took the time to install Adagios to sit on top of Nagios. I highly recommend it as it makes dealing with Nagios a much more enjoyable experience and looks a hell of a lot better.

Now to the fun stuff: as the trend continues, I love using raspberry pi’s wherever I can. They are small, draw little power, and have enough inputs for attaching sensors. Recently I was scrolling through r/sysadmin when I came upon the following post Last month the cleaning ladies hurt my beloved servers. It got me thinking… now that I’m monitoring disk space, memory usage, CPU load, maybe I should start monitoring server room temps.Monitoring Room Temperatures with a Raspberry Pi and Nagios

Tools Required

  • Raspberry Pi
  • 4.7k ohm resistor
  • DS18B20

Wiring

I first tested my setup using a breadboard and jumper cables before soldering anything together. If that’s not an option for you go a head and solder the 4.7k ohm resistor between the 3.3v (red wire) and data line (yellow wire).

Below is a diagram of how everything should be wired up taken from adafruits tutorial.

Setting up NRPE

For nagios to monitor the temperature it will need an NRPE agent installed on the Raspberry Pi. Here is a quick guide to getting NRPE installed.

    1. Download and extract NRPE-2.x from the following site:

http://sourceforge.net/projects/nagios/files/nrpe-2.x/

    1. Extract the contents:

tar -zxvf nrpe-2.15.tar.gz

    1. Change into the extracted directory:

cd nrpe-2.15/

    1. You will need to create a symbolic link so that nrpe can find the arm SSL library:

sudo rm /usr/lib/libssl.so
sudo ln -s /usr/lib/arm-linux-gnueabihf/libssl.so /usr/lib/libssl.so

    1. Run the configuration process, if you are missing any dependencies it will let you know (go deal with them):

./configure

    1. Before installing go ahead and create a nagios user and group. You will need this for the install process. Make sure to build and install it as root:

sudo useradd nagios
sudo make all
sudo make install
sudo make install-plugin
sudo make install-daemon

    1. Copy the sample configuration file over to the NRPE install directory:

sudo mkdir /usr/local/nagios/etc
sudo cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg
sudo chown -R nagios:nagios /usr/local/nagios/etc/

    1. Copy the debian init.d script and give it executable permission:

sudo cp init-script.debian /etc/init.d/nrpe
sudo chmod 700 /etc/init.d/nrpe

      1. Edit the nrpe.cfg config file and make sure to add your Nagios server to the allowed_hosts. Let’s also go ahead and add our check_temp command
      2. sudo vim /usr/local/nagios/etc/nrpe.cfg
        > allowed_hosts=127.0.0.1,YOUR_NAGIOS_SERVER_IP_HERE
        > command[check_temp]=/usr/local/nagios/libexec/check_temp.sh -w 30 -c 40
      3. Make sure access through port 5666 is allowed nrpe 5666/tcp #nrpe

Monitoring Room Temperatures with a Raspberry Pi and Nagios schematic

    1. Start the NRPE service:

sudo service nrpe start

    1. Let’s confirm its running:

ps aux | grep nrpe
The above command should output something along the lines of:

root@devpi:/tmp/nrpe-2.15# ps aux | grep nrpe
nagios    8869  0.0  0.2   4084   980 ?        Ss   21:43   0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
    1. Lastly let’s make sure NRPE starts on reboot:

sudo update-rc.d nrpe defaults

You are now all done with installing the NRPE agent on your Raspberry Pi so it’s time to get the check_temp script installed.

Code

Save the following script as check_temp.sh inside /usr/local/nagios/libexec/
Make sure it has executable permissions: chmod +x /usr/local/nagios/libexec/check_temp.sh

 

For more detail: Monitoring Room Temperatures with a Raspberry Pi and Nagios


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top