Monday 20 January 2014

Nagios nrpe with argument passing



Quick HOW TO STEPS:

On monitored Host:
1. On /etc/nagios/nrpe.cfg file check the value from "0" to "1" at dont_blame_nrpe=0
2. Define the command at [ nrpe.cfg ], such that it will except the arg values.
3. Restart the nrpe server services, after you do some change.

From Nagios Server:
1. Do a recheck with check_nrpe command and check all are working fine.
[ e.g ] check_nrpe -H MonitoredHost -c check_users1 -a 1 2
2. Define the service: [ having the ARG values ]

define service{
        hostgroup_name                  all
        service_description             Current Users
        check_command                   check_nrpe!check_users_with_ARG -a 10 15
        use                             generic-service ; Name of service template to use
        notification_interval           0 ; set > 0 if you want to be renotified
}
3. Restart the nagios server service.



### With Few more details:


########### Following is a check where we have not used npre or nsca ##########

# Define a service to check the load on the local machine.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       amitAsus
        service_description             Current Load
        check_command                   check_load!5.0!4.0!3.0!10.0!6.0!4.0
        }



######### Following is a check where we have use nrpe ############

# Define a service to check the remote mysql partation information on the remote machine.
define service{
        host_name                       mysqlDB1,mysqlDB2
        service_description             check_mysql_partition
        check_command                   check_nrpe_1arg!check_mysql_partition
        use                             generic-service-15 ; Name of service template to use
        notification_interval           0 ; set > 0 if you want to be renotified
}





################################################
######## What is this check_nrpe_1arg ##########

# Default path where the defination is there:
/etc/nagios-plugins/config

$ cat check_nrpe.cfg
# this command runs a program $ARG1$ with arguments $ARG2$
define command {
    command_name    check_nrpe
    command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
}

# this command runs a program $ARG1$ with no arguments
define command {
    command_name    check_nrpe_1arg
    command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}


# NOTE: Original command stay: most of the time at the following location:

/usr/lib/nagios/plugins/check_nrpe


## check_nrpe -help

$ check_nrpe --help

NRPE Plugin for Nagios
Copyright (c) 1999-2008 Ethan Galstad (nagios@nagios.org)
Version: 2.12
Last Modified: 03-10-2008
License: GPL v2 with exemptions (-l for more info)
SSL/TLS Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher required

Usage: check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]

Options:
 -n         = Do no use SSL
 -u         = Make socket timeouts return an UNKNOWN state instead of CRITICAL
 <host>     = The address of the host running the NRPE daemon
 [port]     = The port on which the daemon is running (default=5666)
 [timeout]  = Number of seconds before connection times out (default=10)
 [command]  = The name of the command that the remote daemon should run
 [arglist]  = Optional arguments that should be passed to the command.  Multiple
              arguments should be separated by a space.  If provided, this must be
              the last option supplied on the command line.
 -h,--help    Print this short help.
 -l,--license Print licensing information.
 -n,--no-ssl  Do not initial an ssl handshake with the server, talk in plaintext.

Note:
This plugin requires that you have the NRPE daemon running on the remote host.
You must also have configured the daemon to associate a specific plugin command
with the [command] option you are specifying here.  Upon receipt of the
[command] argument, the NRPE daemon will run the appropriate plugin command and
send the plugin output and return code back to *this* plugin.  This allows you
to execute plugins on remote hosts and 'fake' the results to make Nagios think
the plugin is being run locally.




### Following is an example of nrpe.cfg under /etc/nagios folder:

# Common Standard checks
command[check_ssh]=/usr/lib/nagios/plugins/check_ssh -H localhost -p 1717
command[check_users]=/usr/lib/nagios/plugins/check_users -w 10 -c 15
command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10%


### Passing arguments user check_nrpe

# Following is the error you will get if you have not enable the argument passing at the monitored Host:

NagiosServer:/etc/nagios-plugins/config$ check_nrpe -H MonitoredHost -c check_disk -a 60 80 /dev/xvda1
CHECK_NRPE: Received 0 bytes from daemon.  Check the remote server logs for error messages.


# from /var/log/syslog:

Jan 20 12:17:21  MonitoredHost nrpe[8527]: Error: Request contained command arguments, but argument option is not enabled!
Jan 20 12:17:21  MonitoredHost nrpe[8527]: Client request was invalid, bailing out...


### So, you have to enable the following at the Monitored Host:
### File: /etc/nagios/nrpe.cfg   [ e.g. Example on ubuntu system, and following with line number example ]

So, at line number [94] you have to change dont_blame_nrpe, from "0" to "1" .



NOTE: Don't forget to restart your nrpe server services after changing the value and the command should been defined at the monitored host.


 82 # COMMAND ARGUMENT PROCESSING
 83 # This option determines whether or not the NRPE daemon will allow clients
 84 # to specify arguments to commands that are executed.  This option only works
 85 # if the daemon was configured with the --enable-command-args configure script
 86 # option. 
 87 #
 88 # *** ENABLING THIS OPTION IS A SECURITY RISK! ***
 89 # Read the SECURITY file for information on some of the security implications
 90 # of enabling this variable.
 91 #
 92 # Values: 0=do not allow arguments, 1=allow command arguments
 93
 94 dont_blame_nrpe=0 

NOTE: The above line should be configured as " dont_blame_nrpe=1 " to have arg enabled.


NOTE: The command at the monitored host's nrpe.cfg file should also configured to receive the arguments:

Following is an example that need to be there at the nrpe.cfg file at the monitored host:
command[check_users1]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
command[check_total_procs1]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$

And from Nagios server: you can run the following command. [ Note: only 1 (-a) and then ARG1 ARG2 and so on.. , no need to have another -a before ARG2, if you put more then 1 -a then you will get error. ]

user@nagiosServer:/etc/nagios-plugins/config$ check_nrpe -H MonitoredHost -c check_users1 -a 1 2
USERS OK - 1 users currently logged in |users=1;1;2;0

user@nagiosSever:/etc/nagios-plugins/config$ check_nrpe -H MonitoredHost -c check_total_procs1 -a 80 100
PROCS CRITICAL: 112 processes

user@nagiosSever:/etc/nagios-plugins/config$ check_nrpe -H MonitoredHost -c check_total_procs1 -a 200 300
PROCS OK: 110 processes
 

 
# The following examples use hardcoded command arguments...

# The following examples allow user-supplied arguments and can
# only be used if the NRPE daemon was compiled with support for
# command arguments *AND* the dont_blame_nrpe directive in this
# config file is set to '1'.  This poses a potential security risk, so
# make sure you read the SECURITY file before doing this.

#command[check_users]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
#command[check_load]=/usr/lib/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
#command[check_disk]=/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
#command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$


Hope, you liked the example over here, on how to enable $ARGn$ option at the Monitored Host's nrpe.cfg file and how to use the same on the check_npre command.

NOTE:
Following is one of the example, from your nagios server, where you can define your service along with ARG value, for the command that is defined on the monitored host.


define service{
        hostgroup_name                  all
        service_description             Current Users
        check_command                   check_nrpe!check_users_with_ARG -a 10 15
        use                             generic-service ; Name of service template to use
        notification_interval           0 ; set > 0 if you want to be renotified
}

In the monitored host you have the same command define as per the define server where the command also defined and that is tacking the arg values.

command[check_users_with_ARG]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$






No comments:

Post a Comment