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.
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.
-
- Download and extract NRPE-2.x from the following site:
http://sourceforge.net/projects/nagios/files/nrpe-2.x/
-
- Extract the contents:
tar -zxvf nrpe-2.15.tar.gz
-
- Change into the extracted directory:
cd nrpe-2.15/
-
- 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
-
- Run the configuration process, if you are missing any dependencies it will let you know (go deal with them):
./configure
-
- 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
-
- 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/
-
- 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
-
-
- 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
- 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 - Make sure access through port 5666 is allowed nrpe 5666/tcp #nrpe
-
-
- Start the NRPE service:
sudo service nrpe start
-
- 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 |
-
- 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