«

»

Jun 21

Print this Post

Raspberry PI and Nagios Open Source monitoring

Nagios and Raspberry Pi

Nagios and Raspberry Pi

You may all ask what does security have to do with Nagios? Well, it does. If you can’t know the status of your network / server, you won’t see a problem coming. So, here comes Nagios – an open source monitoring system that includes tons of popular plug-ins.

Well, what about Raspberry PI? Raspberry PI is a project aimed at making computing more interesting to the young generation. The first model that they have launched costs only 25$ and can replace lots of the PC’s that run in all sorts of areas where you simply don’t need all the 4 cores. So, with the accessible cost of a Raspberry PI one can create a small server for all sorts of things such as monitoring jobs or network scanning or network  sniffing jobs.

In this part of the tutorial I will start treating the subject of the Nagios installation on the Raspberry PI.

As an OS, I have used a SD card preloaded with Debian “squeeze” 6 (download it from here: torrent  or direct download).  The setup of the card can be found here. You will need an SD with at least 2 GB of space just for the install!

 

Once you have the SD ready attach-it to the Raspberry PI and power it up! It would be a good idea to start the ssh daemon so you can work from a remote server, but it’s your choice.

 

We will be using a lot apt-get, so it’s better to refresh its repository (if you are behind a proxy use “export http_proxy=http://xxx.xxx.xxx.xxx:yyyyyy” to set the proxy for apt-get).

RaspBerry PI upp and running

My RaspBerry PI up and running

 

 

Please take into account that Debian comes with a pre-compiled Nagios (3.2) that can be installed with-out any trouble with this command: apt-get install nagios3.

But I wish to have the latest version, so we will need to do a little compiling. It all really depends on what you want :) .

 

 

 

Preparing for the installation:

 

First thing we need to do is to update the package list:

root@raspberrypi:/home/pi#apt-get update

 

Before we can compile Nagios, we will need to do a small shopping list for the missing packages.  These are the requisites for the installation:

apt-get install php5 apache2 libgd2-xpm libgd2-xpm-dev libgd2-dev libpng12-dev libjpeg62-dev libgd-tools libpng12-dev libgd2-xpm libgd2-xpm-dev libssl-dev gnutls-bin iputils

We will also need to create the apache and Nagios group:

root@raspberrypi:/home/pi# groupadd www-data

root@raspberrypi:/home/pi# groupadd nagios

Then we will need to add the Nagios user:

root@raspberrypi:/home/pi# adduser nagios

Adding user `nagios’ …

Adding new group `nagios’ (1001) …

Adding new user `nagios’ (1002) with group `nagios’ …

Creating home directory `/home/nagios’ …

Copying files from `/etc/skel’ …

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

Changing the user information for nagios

Enter the new value, or press ENTER for the default

Full Name []: Nagios

Room Number []: Nagios

Work Phone []:

Home Phone []:

Other []:

Is the information correct? [Y/n] Y

root@raspberrypi:/home/pi# grep nagios /etc/passwd

nagios:x:1002:1001:Nagios,Nagios,,:/home/nagios:/bin/bash

And modify the users so they are included in the new groups:

root@raspberrypi:/home/pi# usermod -G nagios nagios

root@raspberrypi:/home/pi# usermod -G www-data,nagios www-data

Double check the operation:

root@raspberrypi:/home/pi# grep nagios /etc/group

nagios:x:1001:www-data,Nagios

Prepare the install directory:

root@raspberrypi:/home/pi# mkdir /usr/local/nagios

root@raspberrypi:/home/pi# chown -R nagios:nagios /usr/local/Nagios

We will also need to install GD-Utils:

root@raspberrypi:/tmp# wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz

root@raspberrypi:/tmp# tar -zxvf gd-2.0.33.tar.gz

root@raspberrypi:/tmp/gd-2.0.33# ./configure

root@raspberrypi:/tmp/gd-2.0.33# make && make install

 

Nagios Install:

 

I think we are done preparing. Let’s start the actual Nagios installation:

root@raspberrypi:/tmp# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz

root@raspberrypi:/tmp# tar xzf nagios-3.4.1.tar.gz

root@raspberrypi:/tmp/nagios# ./configure –prefix=/usr/local/nagios –with-cgiurl=/nagios/cgi-bin –with-htmurl=/nagios/ –with-nagios-user=nagios –with-nagios-group=nagios –with-command-group=nagios

 

 

……………….

*** Configuration summary for nagios 3.4.1 05-11-2012 ***:

 

General Options:

————————-

Nagios executable:  nagios

Nagios user/group:  nagios,nagios

Command user/group:  nagios,nagios

Embedded Perl:  no

Event Broker:  yes

Install ${prefix}:  /usr/local/nagios

Lock file:  ${prefix}/var/nagios.lock

Check result directory:  ${prefix}/var/spool/checkresults

Init directory:  /etc/init.d

Apache conf.d directory:  /etc/apache2/conf.d

Mail program:  /bin/mail

Host OS:  linux-gnu

 

Web Interface Options:

————————

HTML URL:  http://localhost/nagios/

CGI URL:  http://localhost/nagios/cgi-bin/

Traceroute (used by WAP):  /usr/sbin/traceroute

 

 

Review the options above for accuracy.  If they look okay,

type ‘make all’ to compile the main program and CGIs.

 

 

And make:

root@raspberrypi:/tmp/nagios# make all

 

 

make[1]: Leaving directory `/tmp/nagios/module’

 

*** Compile finished ***

 

If the main program and CGIs compiled without any errors, you

can continue with installing Nagios as follows (type ‘make’

without any arguments for a list of all possible options):

 

make install

- This installs the main program, CGIs, and HTML files

 

make install-init

- This installs the init script in /etc/init.d

 

make install-commandmode

- This installs and configures permissions on the

directory for holding the external command file

 

make install-config

- This installs *SAMPLE* config files in /usr/local/nagios/etc

You’ll have to modify these sample files before you can

use Nagios.  Read the HTML documentation for more info

on doing this.  Pay particular attention to the docs on

object configuration files, as they determine what/how

things get monitored!

 

make install-webconf

- This installs the Apache config file for the Nagios

web interface

 

make install-exfoliation

- This installs the Exfoliation theme for the Nagios

web interface

 

make install-classicui

- This installs the classic theme for the Nagios

web interface

 

 

*** Support Notes *******************************************

 

If you have questions about configuring or running Nagios,

please make sure that you:

 

- Look at the sample config files

- Read the documentation on the Nagios Library at:

http://library.nagios.com

 

before you post a question to one of the mailing lists.

Also make sure to include pertinent information that could

help others help you.  This might include:

 

- What version of Nagios you are using

- What version of the plugins you are using

- Relevant snippets from your config files

- Relevant error messages from the Nagios log file

 

For more information on obtaining support for Nagios, visit:

 

http://support.nagios.com

 

*************************************************************

 

Enjoy.

Almost there:

root@raspberrypi:/tmp/nagios# make install

By default Nagios comes installed with Exfoliation theme.

We will need to install the init script:

root@raspberrypi:/tmp/nagios# make install-init

Install and configure the directory for that holds the external command file:

root@raspberrypi:/tmp/nagios# make install-commandmode

Install the apache configuration:

root@raspberrypi:/tmp/nagios# make install-webconf

And at the end install the sample config files:

root@raspberrypi:/tmp/nagios# make install-config

 

Restart the apache daemon:

root@raspberrypi:/tmp/nagios# /etc/init.d/apache2 reload

 

 

Install Nagios plugins:

We can install them in two modes:

The package way (remember to modify the “$USER1$” in the nagios plugins to point to the default install directory):

apt-get install nagios-plugins nagios-snmp-plugins

Or by compiling them:

root@raspberrypi:/tmp# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz

root@raspberrypi:/tmp# tar xzf nagios-plugins-1.4.15.tar.gz

root@raspberrypi:/tmp/nagios-plugins-1.4.15# ./configure

root@raspberrypi:/tmp/nagios-plugins-1.4.15# make && make install

 

 

That should be all! Let’s check the configuration:

root@raspberrypi:/tmp# /usr/local/nagios/bin/nagios -v  /usr/local/nagios/etc/nagios.cfg

Nagios pre-flight check

And start the daemon:

root@raspberrypi:/tmp#service nagios start

 

Nagios Core - web interface

Nagios Core – web interface

Voilà! You have Nagios on the Raspberry PI installed!

Oh… and if you see the load too big (in the screenshot), don’t worry! That’s because I gave it a stress test: at the time of the screenshot it was running almost 700 services, on almost 173 hots made from the default nagios-snmp-plugins (Perl scripts SNMP checks).

 

That’s all!

Permanent link to this article: http://i-security.ro/linux/raspberry-pi-and-nagios-open-source-monitoring/

13 comments

Skip to comment form

  1. Zachary

    Thanks for posting this. I hoping someone would configure Nagios on a Raspberry pi!

    1. Mihai

      Glad you liked it!

  2. Biscuit

    Great post and very good instructions

    One suggestion I have would be to move this line

    root@raspberrypi:/tmp/nagios# make install

    out of the large block of text. I missed it first time round because it was at the bottom of a big block of screen output.

    1. Mihai

      Ok. Thanks for the suggestions! I have inserted in the text some formatting on the commands part. It should improve the visibility.

  3. Manunc

    Hello, thanks for your post on Nagios and RPI.
    I did the same and it works too. My aim is to connect Nagios to the Centreon monitoring software (www.centreon.com) for this we need to install NDOUtils but altthough I succeed to compile also NDOUtils I have a segmentation fault when trying to start it.
    Did you try to use NDOUtils ?
    I would be interested to get some help on this.

    Regards

    Emmanuel

  4. Ale

    ey thanks for the tutorial!

    Also i’ve found that through apt is possible to install too :)

    just:

    $ sudo aptitude install nagios3 -y

    1. Mihai

      You can. Depends if you want or not the latest version.

  5. andydis

    The download you have suggested can only login as pi and raspberry
    This then brings up and error when running the commands permission denied , Are you root?

    Whats the root username and pass?

    1. Mihai

      Yep! You can do: sudo bash (& insert your user password) and then you will have a root shell. Then you can proceed with the install.

  6. Robert

    sudo apt-get install nagios

    1. Mihai

      Yep! But you get an old version.

  7. cesco73

    hi,
    On raspbian server edition, i have this problem,

    sudo apt-get install php5 apache2 libgd2-xpm libgd2-xpm-dev libgd2-dev libpng12-dev libjpeg62-dev libgd-tools libpng12-dev libgd2-xpm libgd2-xpm-dev libssl-dev gnutls-bin iputils
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package libgd2-dev is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘libgd2-dev’ has no installation candidate
    E: Unable to locate package iputils

    what source add to install ‘libgd2-dev’?

    Thanks

    1. Mihai

      Try this one: libgd2-xpm-dev or libgd2-noxpm-dev

      I didn’t had time to test it myself on a new installation but it seems to work fine for the guys in this forum:

      https://github.com/fsphil/fswebcam/issues/4

      Let me know if it worked for you.

      Have a nice day!

Leave a Reply

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