How-to: Nagios on Raspberry Pi

How-to: Nagios on Raspberry Pi

What is Nagios?

Nagios is a network monitoring and alerting system. Nagios Core is free and open-source.

1. Install OS and configure basic setup

This is a topic worthy of an article that applies to a wider audience so I’ve written it separately – drop this entire article in here if you need these instructions

2. Install Nagios

I installed on Raspberry Pi Zero. It’s wireless only so any wireless issues mean it thinks everything is down. And installation takes a while in places but it runs absolutely fine. Perfectly adequate for my home network.

Start by installing some required components:

sudo apt install -y autoconf build-essential wget unzip apache2 apache2-utils php libgd-dev snmp libnet-snmp-perl gettext libssl-dev wget bc gawk dc libmcrypt-dev

Then download, unzip and install the latest version of Nagios itself:

wget https://github.com/NagiosEnterprises/nagioscore/archive/refs/heads/master.zip
unzip master.zip
cd nagioscore-master
./configure --with-httpd-conf=/etc/apache2/sites-enabled

The next step takes a while (14 minutes on my Pi Zero)

make all

Finish the installation and setup of Nagios as follows, you’ll need to decide on a password at the password step – remember what you choose:

sudo make install-groups-users
sudo usermod -a -G nagios www-data
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
sudo a2enmod rewrite
sudo a2enmod cgi
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
sudo systemctl restart apache2
sudo systemctl enable nagios
sudo systemctl start nagios

Before installing plug-ins, ensure the system has DNS tools so as to be able to use check_dns plug-in

sudo apt install dnsutils

Next, check the latest version of the plug-ins at:

https://github.com/nagios-plugins/nagios-plugins/releases

Substituting the latest version from the last step, install the Nagios plug-ins and note, again, that the configure step and the make step take around 7-8 minutes each on the Pi Zero:

cd /tmp
wget -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/releases/download/release-n.n.n/nagios-plugins-n.n.n.tar.gz
tar zxf nagios-plugins.tar.gz
cd /tmp/nagios-plugins-n.n.n
./configure
make
sudo make install
sudo systemctl restart nagios

At this point you should have a working Nagios installation which is, by default, monitoring only the machine on which it is running. To verify that, and see the dashboard, go to:

http://ipaddress/nagios

and log in with nagiosadmin and the password you chose above.

If you have a red cross on the first page to load follow these steps, and log in again:

sudo mkdir /usr/local/nagios/var/rw
sudo chown nagios:nagios /usr/local/nagios/var/rw/
sudo reboot

At this point you will want to configure Nagios to monitor the specific hosts and services important on your network. That involves providing config files for each of the hosts and enabling those by invoking them from the main Nagios config file – more detail in another post

sudo nano /usr/local/nagios/etc/objects/myfirsthost.cfg
sudo nano /usr/local/nagios/etc/nagios.cfg 
sudo systemctl restart nagios.service

3 Replies to “How-to: Nagios on Raspberry Pi”

Leave a Reply

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