Building Nagios on a Raspberry Pi

I thought it would be a fun exercise to build Nagios at home. It was fairly straightforward to spin up a low-resource VM and build it on CentOS. However, it was kind of pointless to have my monitoring on a virtual machine, as when the virtual host would go down then alerts would stop entirely.

So, I dug up my old Raspberry Pi (1st Generation) and decided to put it to some use for once, rather than having it sitting around the house collecting dust.

I stuck a 4GB SD card into it with NOOBS loaded on it, and installed Raspbian. Here’s what I did in the shell to get Nagios up and running:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## Update the server, and install the prerequisites
sudo su
apt-get update -y && sudo apt-get upgrade -y
apt-get install php5 apache2 -y
apt-get clean

## Create Nagios User
adduser nagios
{Nagios_Password}
{Nagios_Password}
[Enter]
[Enter]
[Enter]
[Enter]
[Enter]
Y
usermod -G nagios nagios
usermod -G www-data,nagios www-data
mkdir /usr/local/nagios
chown -R nagios:nagios /usr/local/nagios

## Nagios Installation
cd /tmp
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
tar xzf nagios-4.0.8.tar.gz
cd nagios-4.0.8
./configure --with-command-group=nagios
make all
make install
make install-init
make install-commandmode
make install-webconf
make install-config

## Nagios Plugin Installation
apt-get install nagios-plugins nagios-snmp-plugins -y
apt-get clean

## Configure Nagios
sed -i 's/nagios@localhost/alerts@example.com/g' /usr/local/nagios/etc/objects/contacts.cfg
sed -i 's\# Allow from 127.0.0.1\ Allow from 192.168.1.0/24\g' /etc/apache2/conf.d/nagios.conf

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
{Nagios_Admin_Password}
{Nagios_Admin_Password}

## Restart the Services
/etc/init.d/apache2 reload
service nagios restart

After this point, Nagios should be listening on localhost/nagios and you can authenticate using the nagiosadmin account that was created. Of course then you need to define hosts, services, etc. so this is only the beginning of the configuration.

Here’s it running after configuration, with some sensitive info omitted:

Nagios GUI

I have a problem now in that my Pi has about 100mb of space left, so I’ll look into either finding a way to reduce the space consumed by the system or to get a larger SD card for it.