Nginx 1.6.3 status monitoring with Adagios on CentOS 7

Download check_nginx_status.pl:

cd /usr/lib64/nagios/plugins/
wget https://raw.githubusercontent.com/regilero/check_nginx_status/master/check_nginx_status.pl

Install prerequisites:

yum install perl-libwww-perl nagios-plugins-perl

Create a check command:

pynag add command command_name="2ks-check_nginx_status" command_line='$USER1$/check_nginx_status.pl -H $HOSTADDRESS$ -p $_SERVICE_PORT$ -s $_SERVICE_SERVER_NAME$ $_SERVICE_OPTIONAL_ARGUMENTS$'

Create an okconfig template:

cd /etc/nagios/okconfig
echo 'define service {
    service_description            Nginx status
    use                            generic-service
    host_name                      HOSTNAME
    check_command                  2ks-check_nginx_status
    __PORT                         80
    __SERVER_NAME                  HOSTNAME
}
define service {
    use                            okc-linux-check_proc
    __WARNING                      1:
    __NAME                         nginx
    host_name                      HOSTNAME
    service_description            Process nginx
    __CRITICAL                     :10
    check_command                 okc-check_nrpe!check_procs -a $_SERVICE_WARNING$ $_SERVICE_CRITICAL$ $_SERVICE_NAME$
}' > nginx.cfg-example

Add the template to a host:

okconfig addtemplate www-01.domain.com --template nginx

Reload nagios and run the service checks from the Adagios web interface, and they should be green:

Troubleshooting
Problem: Running the plugin in nagios causes this error:

NGINX UNKNOWN - unable to write temporary data in :/tmp/123.123.123._check_nginx_status...

Probable causes:

You ran the plugin as root, it saved the *check_nginx_status file in /tmp with root ownership, and nagios can’t overwrite it.
SELinux or other ACL’s are preventing nagios from write to /tmp.

Solutions:
Delete the file:

rm -f /tmp/*check_nginx_status

Or reset permissions on /tmp:

chmod 777 /tmp/
chown root:root /tmp/
restorecon -R /tmp/ #NOTE: SELinux should be in permissive mode when using Adagios, unless you can create rules for it.
Advertisements
Nginx 1.6.3 status monitoring with Adagios on CentOS 7

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s