How To Test Nagios Remote NRPE Commands

Published Date Author: , Posted September 27th, 2018 at 10:46:20am

There are many things to configure in Nagios, especially when using custom check commands. Recently I needed to configure all of the Continuent Clustering Nagios checks. Once setup on the database side, I wanted to confirm that everything was working.

Basics: Run a Remote NRPE Check

To test a remote NRPE client command from a nagios server via the command line, use the check_nrpe command:

1
shell> /opt/local/libexec/nagios/check_nrpe -H db1 -c check_tungsten_latency
shell> /opt/local/libexec/nagios/check_nrpe -H db1 -c check_tungsten_latency

The above command calls the NRPE daemon running on host db1 and executes the NRPE command “check_tungsten_latency” as defined in the db1:/etc/nagios/nrpe.cfg file.

Here is the line used in nrpe.cfg to define the check_tungsten_latency remote NRPE call:

1
command[check_tungsten_latency]=/usr/bin/sudo -u tungsten /opt/continuent/tungsten/cluster-home/bin/check_tungsten_latency -w 2.5 -c 4.0
command[check_tungsten_latency]=/usr/bin/sudo -u tungsten /opt/continuent/tungsten/cluster-home/bin/check_tungsten_latency -w 2.5 -c 4.0

Note that sudo is in use to give the nrpe user access as the tungsten user to the tungsten-owned check scripts using the sudo wildcard configuration.

Here is the service check definition in the /opt/local/etc/nagios/objects/services.cfg file:

1
2
3
4
5
6
7
8
9
# Service definition
define service{
    service_description         check_tungsten_latency - Continuent Clustering
    servicegroups               myclusters
    host_name                   db1,db2,db3,db4,db5,db6,db7,db8,db9
    check_command               check_nrpe!check_tungsten_latency
    contact_groups              admin
    use                         generic-service
    }
# Service definition
define service{
    service_description         check_tungsten_latency - Continuent Clustering
    servicegroups               myclusters
    host_name                   db1,db2,db3,db4,db5,db6,db7,db8,db9
    check_command               check_nrpe!check_tungsten_latency
    contact_groups              admin
    use                         generic-service
    }

Security: Sudo Configuration

To enable sudo for the nrpe user, create or edit the file /etc/sudoers.d/20_nagios like so:

sudo vim /etc/sudoers.d/20_nagios

1
2
3
Defaults:nrpe !requiretty
Defaults:nrpe !visiblepw
nrpe          ALL=(tungsten)  NOPASSWD: /opt/continuent/tungsten/cluster-home/bin/check*
Defaults:nrpe !requiretty
Defaults:nrpe !visiblepw
nrpe          ALL=(tungsten)  NOPASSWD: /opt/continuent/tungsten/cluster-home/bin/check*

Additional Command Examples

/etc/nagios/nrpe.cfg

1
2
command[check_tungsten_online]=/usr/bin/sudo -u tungsten /opt/continuent/tungsten/cluster-home/bin/check_tungsten_online
command[check_tungsten_progress]=/usr/bin/sudo -u tungsten /opt/continuent/tungsten/cluster-home/bin/check_tungsten_progress -t 5</code>
command[check_tungsten_online]=/usr/bin/sudo -u tungsten /opt/continuent/tungsten/cluster-home/bin/check_tungsten_online
command[check_tungsten_progress]=/usr/bin/sudo -u tungsten /opt/continuent/tungsten/cluster-home/bin/check_tungsten_progress -t 5</code>

/opt/local/etc/nagios/objects/services.cfg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Service definition
define service{
    service_description         check_tungsten_online - Continuent Clustering
    servicegroups               myclusters
    host_name                   db1,db2,db3,db4,db5,db6,db7,db8,db9
    check_command               check_nrpe!check_tungsten_online
    contact_groups              admin
    use                         generic-service
    }
 
# Service definition
define service{
    service_description         check_tungsten_progress - Continuent Clustering
    servicegroups               myclusters
    host_name                   db1,db2,db3,db4,db5,db6,db7,db8,db9
    check_command               check_nrpe!check_tungsten_progress
    contact_groups              admin
    use                         generic-service
    }    
# Service definition
define service{
    service_description         check_tungsten_online - Continuent Clustering
    servicegroups               myclusters
    host_name                   db1,db2,db3,db4,db5,db6,db7,db8,db9
    check_command               check_nrpe!check_tungsten_online
    contact_groups              admin
    use                         generic-service
    }

# Service definition
define service{
    service_description         check_tungsten_progress - Continuent Clustering
    servicegroups               myclusters
    host_name                   db1,db2,db3,db4,db5,db6,db7,db8,db9
    check_command               check_nrpe!check_tungsten_progress
    contact_groups              admin
    use                         generic-service
    }    

For more information about monitoring Continuent clusters, please visit https://docs.continuent.com/tungsten-clustering-6.0/ecosystem-nagios.html.

To learn about Continuent solutions in general, check out https://www.continuent.com/solutions

No comments as yet.

Leave Your Comment  Leave a comment

All fields marked with "*" are required.