Home Server Nagios

Index.

11-Dec-2011: initial release.
18-Jan-2012: Added nginx configuration.
18-Jan-2013: Adjusted for Slackware
16-Apr-2015: Added nginx fix for bug since version 4.0.6.

 

Introduction.

Nagios is a IT infrastructure monitoring program. On the Home Server it can be useful to check the state of the virtual servers and services that are available for your external users. If there is a service problem you can be notified by email, sms  or page.

 

Core installation.

You could install Nagios on it’s own server, but for these articles I will install the Nagios core on the Home Server. Remote instances will be installed on the gateway and the web server. I have the following packages and buildscripts available:

  • nagios
  • nagios-plugins
  • nagios-plugins-amanda
  • nagios-plugins-asterisk
  • nagios-plugins-clamav
  • nagios-plugins-cups
  • nagios-plugins-dovecot
  • nagios-plugins-e2fs
  • nagios-plugins-hddtemp
  • nagios-plugins-md_raid
  • nagios-plugins-nginx
  • nagios-plugins-nrpe
  • nagios-plugins-postfix
  • nagios-plugins-sip
  • nrpe

On the Home Server you need at least the nagios, nagios-plugins and nagios-plugins-nrpe packages. Depending on your needs you can add some nagios-plugins-xxx packages.

To protect the nagios web interface against unauthorized access you need to add a password file. Since nginx is the web server, there is no htpasswd program. This program is in the apache httpd package that is shipped with Slackware. Then creating the password file goes like this:

root@homsrv:~# cd /etc/nagios
root@homsrv:/etc/nagios# htpasswd -c htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
root@homsrv:/etc/nagios# htpasswd  htpasswd.users admin
New password:
Re-type new password:
Adding password for user admin
root@homsrv:/etc/nagios# htpasswd  htpasswd.users username
New password:
Re-type new password:
Adding password for user username
root@homsrv:/etc/nagios#

 

Nginx configuration.

When you use the nginx webserver the easiest way to run the web interface is to give nagios it’s own domain so that you can run it as a virtual server. Add the FQDN name nagios.wpl.ym to the DNS server with IPv4 address 10.126.160.253 and IPv6 address 2001:1af8:fecf:7ea0::203. Add that IPv6 address to the interface br0 in /etc/rc.d/rc.inet1.conf so that this address is available.

Add the virtual server to /etc/nginx/conf/nginx.conf and reload nginx:

    # nagios.wpl.ym
    server {
        listen                  10.126.160.253:80;
        listen                  [2001:1af8:fecf:7ea0::203]:80;
        server_name             nagios.wpl.ym;
        root                    /usr/share/nagios/share;
        access_log              /var/log/nginx/nagios_access_log;
        error_log               /var/log/nginx/nagios_error_log;
        auth_basic              "Nagios Access";
        auth_basic_user_file    /etc/nagios/htpasswd.users;
        index                   index.php;

        location ~ \.php$ {
            include             fastcgi.conf;
            fastcgi_pass        php;
        }

        location ~ ^/nagios/cgi-bin/(.*\.cgi)$ {
            root                /usr/share/nagios/sbin/;
            rewrite             ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
            fastcgi_param       AUTH_USER $remote_user;
            fastcgi_param       REMOTE_USER $remote_user;    
            include             fastcgi.conf;
            fastcgi_pass        cgi;
        }

        # Only for the home page after upgrade to 4.0.6
        #
        location ~ ^/cgi-bin/(.*\.cgi)$ {
            root                /usr/share/nagios/sbin/;
            rewrite             ^/cgi-bin/(.*)\.cgi /$1.cgi break;
            fastcgi_param       AUTH_USER $remote_user;
            fastcgi_param       REMOTE_USER $remote_user;
            include             fastcgi.conf;
            fastcgi_pass        cgi;
        }

        # Strange path offsets.
        rewrite ^/nagios/images/(.*) /images/$1;
        rewrite ^/nagios/stylesheets/(.*) /stylesheets/$1;
    }

 

 

Client installation.

On the gateway and web server install at least the nrpe remote and nagios-plugins packages.

The nrpe service is called via inetd. Add the following line to /etc/services:

nrpe            5666/tcp        # nagios nrpe service

 

Then enable the following line in /etc/inetd.conf:

#:nrpe
nrpe stream tcp nowait nagios /usr/sbin/nrpe nrpe -c /etc/nrpe/nrpe.cfg --inetd

 

These lines should be present if the package from this site is used, but it doesn’t hurt to check. The only configuration part on the client is that you need to add all the commands that you want to execute. For example on the gateway server add the file /etc/nrpe/conf.d/gateway.cfg:

# gateway commands
#
command[check_ipv6]=/usr/share/nagios/libexec/check_ping -6 -H 2001:1af8:fe00:2a
b::1 -w 250.0,20% -c 1500.0,60% -p5
command[check_users]=/usr/share/nagios/libexec/check_users -w 3 -c 5
command[check_load]=/usr/share/nagios/libexec/check_load -w 5,4,3 -c 10,8,6
command[check_root]=/usr/share/nagios/libexec/check_disk -w 20% -c 10% -p /dev/s
da3
command[check_boot]=/usr/share/nagios/libexec/check_disk -w 20% -c 10% -p /dev/s
da1
command[check_home]=/usr/share/nagios/libexec/check_disk -w 20% -c 10% -p /dev/s
da4
command[check_swap]=/usr/share/nagios/libexec/check_swap -w 40% -c 20%
command[check_zombie_procs]=/usr/share/nagios/libexec/check_procs -w 5 -c 10 -s
Z
command[check_total_procs]=/usr/share/nagios/libexec/check_procs -w 80 -c 100

 

You can now test these commands from the Home Server like this:

root@homsrv:~# /usr/share/nagios/libexec/check_nrpe -H gateway -c check_load
OK - load average: 0.00, 0.01, 0.05|load1=0.000;5.000;10.000;0; load5=0.010;4.00
0;8.000;0; load15=0.050;3.000;6.000;0;
root@homsrv:~#

 

If you get a response like the one above, your client configuration works.

 

Windows client.

If you use some windows machines as servers you can install NSClient++ on these machines. Download the .msi installer file and install NSClient++. In the NSCLient++ Configuration screen add the IP address of the Nagios server and select “Enable common check plugins”, “Enable NRPE server (check_nrpe)” and “Enable WMI checks”.

After it is installed you must edit C:\Program Files\NSCLient++\NSC.ini and set allow_arguments=1 in the [nrpe] section. After that you need to restart the NSCLient++ service.

 

Nagios configuration.

There is a lot of documentation about how to setup and configure a Nagios server. If you start with copies of the sample configuration files you can come far. Of coarse all the configuration files that I have used are in the download archive.

 

Download.

See the download page for the script and configuration files.