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 Nagios itself:

cd /tmp
wget -O nagios.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz
tar xzf nagios.tar.gz
cd /tmp/nagioscore-nagios-4.4.6/
./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

Next, 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-2.3.3/nagios-plugins-2.3.3.tar.gz
tar zxf nagios-plugins.tar.gz
cd /tmp/nagios-plugins-2.3.3
./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.

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.