Nagios is a free open-source monitoring software/platform.

Install

A quick method of installation on Debian/Ubuntu based systems, is to simply type: sudo apt-get install nagios . A more recent version could be available.

It is easy to complile Nagios from source using the latest version:

Debian/Ubuntu quickstart
Fedora quickstart
OpenSUSE quickstart

Install the Nagios-plugins release

Install the OpenSSL Development package if you require SSL monitoring. This is usually - if not always - on Debian and variants as openssl-dev and RHEL and variants as openssl-devel. Go to http://www.nagios.org/download/plugins/ and wget the latest release, in this example it is 1.4.13:

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
tar zxf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13/
sudo apt-get install build-essential
./configure --enable-perl-modules --prefix=/usr/local/nagios --with-nagios-user=nagios --with-openssl=/usr/bin
make all
sudo make install
sudo chown nagios:nagios /usr/local/nagios/libexec

Nagios Files/Dirs

Config files

If installed via a package the config fies are /etc/nagios by default. The default location when compiled and setup with ./configure is /usr/local/nagios/etc.

Verify config

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Plugins

Plugins are stored in the libexec folder. It is pissible to run pluigns from any folder but for the sake of permissions it is best best to run them from here. The $USER1$ macro (variable) also piints to this location by default. The default location when compiled and setup with ./configure is /usr/local/nagios/libexec .

Mail notifications

Ensure package mailx is installed.

Setup exim to email to remote domains:

dpkg-reconfigure exim4-config

Install NSClient++ for Windows machines

NSClient++ is a monitoring client for Windows that works with Nagios. Download: nscplus from sourceforge

The MSI installer will setup the service, ask for your Nagios server IP to restrict requests to that IP as well as ask for a password for use with check_nt. It is recommended that you enable all the modules apart from the NSCA client.

MySQL Monitoring

Connection Check

  • Ensure the check_mysql plugin is installed.
  • Create a username on MySQL for nagios to use, see Access rights/Privileges/Grants for MySQL
  • If your mySQL setup is one server, disable skip-networking or set mysql to listen on its IP address, instead of 127.0.0.1 .
  • Add the following to your commands.cfg:
define command{
        command_name    check_mysql
        command_line    $USER1$/check_mysql $ARG1$
}
  • Add the following to your hosts.cfg:
define service{
        use                             service
        host_name                       dbserver
        service_description             MySQL connection check
        check_command                   check_mysql!-d test -H dbserver -u nagios -p passwordhere
}

Load/health monitoring

If more advanced monitoring is required follow these steps:

define command{
        command_name            check_mysql_health_db01
        command_line            $USER1$/check_mysql_health --host 127.0.0.1 -P 3335 --mode $ARG1$ -u nagios -p passwordhere -w $ARG2$ -c $ARG3$ --database dbhere
}

define command{
        command_name            check_mysql_health_db02
        command_line            $USER1$/check_mysql_health --host 127.0.0.1 -P 3336 --mode $ARG1$ -u nagios -p passwordhere -w $ARG2$ -c $ARG3$ --database dbhere
}


define service{
        use                             service
        host_name                       db01
        service_description             MySQL Connection time
        check_command                   check_mysql_health_db01!connection-time!1!5
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Open connections
        check_command                   check_mysql_health_db01!threads-connected!50!70
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Uptime
        check_command                   check_mysql_health_db01!uptime!10:!5:
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Query-cache hitrate
        check_command                   check_mysql_health_db01!qcache-hitrate!70:!50:
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Query-cache pruning
        check_command                   check_mysql_health_db01!qcache-lowmem-prunes!1!10
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Myisam key-cache hitrate
        check_command                   check_mysql_health_db01!keycache-hitrate!98:!95:
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Thread-cache Hitrate
        check_command                   check_mysql_health_db01!threadcache-hitrate!90:!80:
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL InnoDB buffer pool hitrate
        check_command                   check_mysql_health_db01!bufferpool-hitrate!99:!95:
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL InnoDB buffer pool waits
        check_command                   check_mysql_health_db01!bufferpool-wait-free!1!10
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL InnoDB log waits
        check_command                   check_mysql_health_db01!log-waits!1!10
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Table cache hitrate
        check_command                   check_mysql_health_db01!tablecache-hitrate!99:!90:
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Table lock contention
        check_command                   check_mysql_health_db01!table-lock-contention!1!2
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Index usage
        check_command                   check_mysql_health_db01!index-usage!90:!80:
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Tables on disk
        check_command                   check_mysql_health_db01!tmp-disk-tables!25!50
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Slow queries
        check_command                   check_mysql_health_db01!slow-queries!0.1!1
        }
define service{
        use                             service
        host_name                       db01
        service_description             MySQL Long running processes
        check_command                   check_mysql_health_db01!long-running-procs!10!20
        }



define service{
        use                             service
        host_name                       db02
        service_description             MySQL Connection time2
        check_command                   check_mysql_health_db02!connection-time!1!5
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Open connections2
        check_command                   check_mysql_health_db02!threads-connected!50!70
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Uptime2
        check_command                   check_mysql_health_db02!uptime!10:!5:
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Query-cache hitrate2
        check_command                   check_mysql_health_db02!qcache-hitrate!70:!50:
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Query-cache pruning2
        check_command                   check_mysql_health_db02!qcache-lowmem-prunes!1!10
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Myisam key-cache hitrate2
        check_command                   check_mysql_health_db02!keycache-hitrate!98:!95:
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Thread-cache Hitrate2
        check_command                   check_mysql_health_db02!threadcache-hitrate!90:!80:
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL InnoDB buffer pool hitrate2
        check_command                   check_mysql_health_db02!bufferpool-hitrate!99:!95:
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL InnoDB buffer pool waits2
        check_command                   check_mysql_health_db02!bufferpool-wait-free!1!10
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL InnoDB log waits2
        check_command                   check_mysql_health_db02!log-waits!1!10
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Table cache hitrate2
        check_command                   check_mysql_health_db02!tablecache-hitrate!99:!90:
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Table lock contention2
        check_command                   check_mysql_health_db02!table-lock-contention!1!2
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Index usage2
        check_command                   check_mysql_health_db02!index-usage!90:!80:
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Tables on disk2
        check_command                   check_mysql_health_db02!tmp-disk-tables!25!50
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Slow queries2
        check_command                   check_mysql_health_db02!slow-queries!0.1!1
        }
define service{
        use                             service
        host_name                       db02
        service_description             MySQL Long running processes2
        check_command                   check_mysql_health_db02!long-running-procs!10!20
}

Exchange 2007 Monitoring

See full page: Monitoring Exchange 2007 using Nagios

Nagios can be configured to extensively monitor Exchange 2007 through the use of monitoring services and perfmon counters with tailored thresholds. Details on how to monitor the following are explained:

  • Exchange services: AD Topology, Information Store, Mail Submission, Mailbox Assistant, Replication, MSExchangeSearch, Service Host, System Attendant, Remote Transport Log Search, msftesql-Exchange, MSExchangeAntispamUpdate, MSExchangeFDS, Pop3, IMAP, MSExchangeTransport
  • Replication health / Status: Replication is used if CCR, LCR, or SCR is enabled for any of your Exchange DBs.
  • Connectivity of Mailbox server(s) to Hub Transport server(s)
  • Database health: TLog generation checkpoint depth, Page fault stalls, Version buckets, TLog Record Stalls, Cache hit ratio

Exchange 2003 Monitoring

Check Exchange 2003 services are running:

#ex2003 Servers
define service{
        use                     generic-service
hostgroup_name  ex2003-servers
        service_description     Ex IS
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l MSExchangeIS
        }
define service{
        use                     generic-service
hostgroup_name  ex2003-servers
        service_description     Ex WMI
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l MSExchangeMGMT
        }
define service{
        use                     generic-service
hostgroup_name  ex2003-servers
        service_description     Ex MTA Stacks
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l MSExchangeMTA
        }
define service{
        use                     generic-service
hostgroup_name  ex2003-servers
        service_description     Ex POP3
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l POP3Svc
        }
define service{
        use                     generic-service
hostgroup_name  ex2003-servers
        service_description     Ex Routing Engine
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l RESvc
        }
define service{
        use                     generic-service
hostgroup_name  ex2003-servers
        service_description     Ex System Attendant
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l MSExchangeSA
        }
define service{
        use                     generic-service
hostgroup_name  ex2003-servers
        service_description     SMTP
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l SMTPSVC
        }

See Also

End to end email checking (Nagios)

IIS Server Monitoring

Check IIS services are running:

#web servers
define service{
        use                     service
        hostgroup_name  web-servers
        service_description     W3SVC
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
        }
define service{
        use                     service
        hostgroup_name  web-servers
        service_description     IIS Admin Service
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l IISADMIN
        }
define service{
        use                     service
        hostgroup_name  web-servers
        service_description     HTTP SSL
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l HTTPFilter
        }

SQL Server (MSSQL) Server Monitoring

See full page: Monitor SQL Server (MSSQL) using Nagios

Nagios can be configured to monitor named and non-named instances of MS SQL Server through use of escaping characters and being aware of the specific perfmon syntax. Details on how to monitor the following are explanied:

  • SQL Services (check_nt)
  • Ports open (check_tcp)
  • Load / health monitoring (check_nt and perfmon counters)
  • SQL Mirroring (check_nt and perfmon counters)

RBL Status

The check_bl plugin allows monitoring of RBL status for your outbound relay servers.

Plugin installation

  1. Download and extract http://bashton.com/downloads/nagios-check_bl-1.0.tar.gz
  2. Copy check_bl (perl script) to your Nagios plugins dir, the default is /usr/local/nagios/libexec
  3. Install the NET::DNS module for perl, as otherwise the script will be unable to perform the necessary DNS lookups. On Debian/Ubuntu the package is libnet-dns-perl . See Installing Perl Modules .
  4. Add the following config with your IP(S) to Nagios' config:
define  command {
        command_name    check_bl
        command_line    $USER1$/check_bl -H 1.1.1.1 -B zen.spamhaus.org bl.spamcop.net dnsbl.ahbl.org dnsbl.njabl.org dnsbl.sorbs.net virbl.dnsbl.bit.nl rbl.efnet.org phishing.rbl.msrbl.net 0spam.fusionzero.com list.dsbl.org multihop.dsbl.org unconfirmed.dsbl.org will-spam-for-food.eu.org blacklist.spambag.org blackholes.brainerd.net blackholes.uceb.org spamsources.dnsbl.info map.spam-rbl.com ns1.unsubscore.com psbl.surriel.com l2.spews.dnsbl.sorbs.net bl.csma.biz sbl.csma.biz dynablock.njabl.org no-more-funn.moensted.dk  ubl.unsubscore.com dnsbl-1.uceprotect.net dnsbl-2.uceprotect.net dnsbl-3.uceprotect.net spamguard.leadmon.net opm.blitzed.org bl.spamcannibal.org rbl.schulte.org dnsbl.ahbl.org virbl.dnsbl.bit.nl combined.rbl.msrbl.net
        }
define service{
        use                     generic-service
hostgroup_name  ex-cashub-servers
        service_description     Ex RBL Status
        check_command           check_bl
        }

Domain Expiry Monitoring

  1. Download the plugin and save to your Nagios plugins dir, the default is /usr/local/nagios/libexec
  2. Install the Date::Manip Perl module, on Debian/Ubuntu the package is libdate-manip-perl , on RHEL/CentOS the package can be perl-Date-Manip or perl-DateManip.noarch . See Installing Perl Modules
  3. Install whois if not present on your system.
  4. Append this command config to your /usr/local/nagios/etc/objects/commands.cfg:
define command{
        command_name    check_whois
        command_line    $USER1$/check_whois $ARG1$
}

It is best not to use $HOSTADDRESS$ as the argument for the check command as otherwise every domain will need to have its own host config and Nagios will try to ping it by default.

The command should then be referenced in a service:

define service{
        use     service
        host_name       Domains-Expiration
        service_description domain.com
        check_command check_whois!$SERVICEDESC$
}

#Dummy host to collate all the checks:
define host{
        use                     domain-expiry
        host_name               Domains-Expiration
        alias                   Domains Expiration
        address                 127.0.0.1
}

SSL Cert Expiry monitoring

The check_http command can natively monitor the SSL expiry of a cert with the -C parameter.

  • OpenSSL must be installed and the plugin must be compiled with opennssl with the --with-openssl parameter in your ./configure

Monitor the cert listening on the hosts ip address and alert if within 14 days of expiry:

define command{
command_name check_ssl_expiry
command_line /usr/lib/nagios/plugins/check_http --ssl -C 14 -H '$HOSTADDRESS$' -I '$HOSTADDRESS$'
}

A service directive can then be used as follows on each web server, presuming you have 1 listening SSL interface per server:

define service{
        use                     generic-service
        host_name  web_server
        service_description     SSL Cert Expiry
        check_command           check_ssl_expiry
}

End to end email checking

Nagios can monitor end-to-end email functonality when used with a perl script. The script sends emails via SMTP and expects them to arrive in a defined POP3 email account. Using an external mail forward this script enables you to assert functionality of sending & receiving emails.

Plugin installation

  1. Download the script: http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F1807.html;d=1
  1. Install the MAIL::POP3Client module for perl, as otherwise the script will be unable to perform the necessary POP3 connections. The package name varies from distro to distro. On Ubuntu it is libmail-pop3client-perl.
  2. Install Dovecot pop3 server: sudo apt-get install dovecot-common dovecot-pop3d It takes credentials from /etc/passwd .
  3. Install Postfix MTA: sudo apt-get install postfix. Configure through the /etc/postfix/main.cf file or use sudo dpkg-reconfigure postfix. See https://help.ubuntu.com/community/Postfix
  4. Setup relevant auto-forwards for your acc and allow-relay rules if required.
  5. Add the follwing Nagios config, adjusting for your setup as required:
define service{
        use                     generic-service
host_name  Email_server
        service_description     Email Send/Receieve Test
        check_command           check_email
        }
define command{
command_name check_email
command_line $USER1$/check_email.pl -poph=127.0.0.1 -popu=emailtest -pa=pop3password -smtph=FqdnOfRealyserver -from=emailtest@nagiosserver [email protected] -pendc=2 -lostc=0 -statfile=/stat/statfile
}

Notes:

  • The script requires access to write to a temporary 'stat' file. Nagios in my setup at least is very particular with permissions. It is best to give it its own root folder as seen above or place it in /tmp.
  • The script can also serve as a check_tcp for your relay server as if it cannot connect it returns critical to Nagios.
  • If using Exchange the auto forward rule will need to be set using AD (Exchange 2003) or the EMC (Exchange 2007).

LDAP Monitoring

This can be used for any LDAP service including Windows Domain Controllers and of course OpenLDAP. The plugin cannot check Windows Domain Controllers when using login credentials as Windows will only accept credentials over SSL.

  1. Download the plugin and save in your /usr/local/nagios/libexec dir.
  2. Install the NET::LDAP module perl, as otherwise the script cannot perform the LDAP lookups. On Ubuntu the package name is libnet-ldap-perl .
  3. Append this command config to your /usr/local/nagios/etc/objects/commands.cfg:
define command{
        command_name    check_ldap
        command_line    $USER1$/check_ldap -H $HOSTADDRESS$ $ARG1$
}

The command can then be referenced as a service, in this example it uses a hostgroup which contains all the Domain Controllers:

define hostgroup{
        hostgroup_name dcs
        alias Domain Controllers
        members DC1, DC2
}

define service{
        use                     generic-service
hostgroup_name  dcs
        service_description     NTDS LDAP Bind check
        check_command           check_ldap
}

Resources

Category:Nagios Category:Linux Category:Windows Category:Monitoring