Home Directory Plugins * Remote Check Tunneling check_by_snmp / check_snmp_extend / check_snmp_exec

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_by_snmp / check_snmp_extend / check_snmp_exec

Current Version
0.3
Last Release Date
2012-03-27
Compatible With
  • Nagios 1.x
  • Nagios 2.x
  • Nagios 3.x
  • Nagios XI
  • Nagios Fusion
Owner
License
GPL
Hits
86861
Files:
FileDescription
check_by_snmpcheck_by_snmp.pl - version 0.22 (Jan 2012)
check_by_snmp.plcheck_by_snmp.pl - version 0.3 (Mar 2012)
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
This plugin lets you use extended functionality of SNMP to execute plugins remotely in a way similar to NRPE. In its second mode of operation it allows to use results from some command or a remote data file with actual processing of the data done by a plugin on a Nagios server. This plugin supports both SNMP exec and SNMP extend mechanisms.
To find all available options do:
./check_by_snmp --help

All SNMP Versions (1,2,3) and authentication options are supported and similar to my other check_snmp plugins. These are easy to understand when you do --help

The plugin has two primary modes of operations:

(I) Remote Execution of Plugin

You execute plugin on a remote system and return its output and exit code back to nagios. This is most similar to NRPE and default behavior if you don't specify any other options or specify option -S by itself.

The command you want to execute would be added to snmpd.conf with either exec or extend, for example this is added to /etc/snmp/snmpd.conf on a system I recently setup.
extend thriftcheck /home/nagios/plugins/check_thrift_server

Nagios command definition for above is:

define command {
command_name remote_exec-check_thrift_server
command_line $USER1$/check_by_snmp.pl -E thriftcheck -H $HOSTADDRESS$ -L sha,aes -l $_HOSTSNMP_V3_USER$ -x $_HOSTSNMP_V3_AUTH$ -X $_HOSTSNMP_V3_PRIV$
}

The option "-E" is used to designate plugin you want to execute as specified in snmpd.conf. If you have version of SNMPd that supports exec rather than extend than instead of above you would have added something like:
exec .1.3.6.1.4.1.2021.301 thriftcheck /home/nagios/plugins/check_thrift_server
to snmpd.conf and specified OID instead of name for check_by_snmp:
command_line $USER1$/check_by_snmp.pl -O 1.3.6.1.4.1.2021.301 -H $HOSTADDRESS$ -L sha,aes -l $_HOSTSNMP_V3_USER$ -x $_HOSTSNMP_V3_AUTH$ -X $_HOSTSNMP_V3_PRIV$

(II) Data From Remote System Used by Local Nagios Plugin

In this way you do not execute entire plugin remotely, rather you just provide data that plugin would normally want and interpreting the data is done by plugin on a Nagios server. The most common (at least for my plugin) is to get data from /proc filesystem but you can also get results from execution of one or more commands, etc.

For example if your plugin wants /proc/stat data you could add the following:
extend cpustat /bin/cat /proc/stat

The plugin supports several ways of how the results would actually be communicated to another plugin.

1) -T option

With this the data from remote system is saved in a temporary file. It is expected that a nagios plugin that wants tis data would have a parameter where you specify file name. In place of actual file you specify this as %FILE1% and check_by_snmp would replace that with a name of the temporary file it wrote results to, execute the plugin (if its perl, this would even be done within embedded perl as if it was called from nagios), wait for it to finish and get its exit code, remove temporary file and then exit with same exit code it got. An example of command definition that does this is:

define command {
command_name check_snmp_linuxcpustat
command_line $USER1$/check_by_snmp.pl -E cpustat -H $HOSTADDRESS$ -L sha,aes -l $_HOSTSNMP_V3_USER$ -x $_HOSTSNMP_V3_AUTH$ -X $_HOSTSNMP_V3_PRIV$ -T --exec $USER1$/check_linux_procstat.pl -P %FILE1% -f -w $ARG1$ -c $ARG2$
}

Most important to get from above is that everything after --exec is a plugin to be executed.

2) -S option

Ths would be a default behavior if you don't specify any option and is used when nagios plugin can accept results in STDIN. Then check_by_snmp executes remote command with PIPE to redirect its standard output to plugin's standard input. The plugin to be excuted would get forked and always gets executed in a separate process outside of nagios. An example of how to use this is:

define command {
command_name check_snmp_linuxcpustat
command_line $USER1$/check_by_snmp.pl -E cpustat -H $HOSTADDRESS$ -L sha,aes -l $_HOSTSNMP_V3_USER$ -x $_HOSTSNMP_V3_AUTH$ -X $_HOSTSNMP_V3_PRIV$ -S --exec $USER1$/check_linux_procstat.pl -P - -f -w $ARG1$ -c $ARG2$
}
3) -F option

Instead of saving to temporary file(s) the results are saved to file(s) specified with -F. The file name can be something semi-temporary and unique with HOSTNAME as its component. The file is not deleted by check_by_snmp plugin and unlike above two cases the execution is done with exec so basically check_by_snmp replaces itself with a command specified after --exec. Example of this type of configuration is:

define command {
command_name check_snmp_linuxcpustat
command_line $USER1$/check_by_snmp.pl -E cpustat -H $HOSTADDRESS$ -L sha,aes -l $_HOSTSNMP_V3_USER$ -x $_HOSTSNMP_V3_AUTH$ -X $_HOSTSNMP_V3_PRIV$ -F /tmp/nagios_$HOSTNAME$_procstat --exec $USER1$/check_linux_procstat.pl -P /tmp/nagios_$HOSTNAME$_procstat -f -w $ARG1$ -c $ARG2$
}

-F can also be used for debugging in conjunction with other options. Basically you can specify some log file to write data to even if data is passed to another plugin in STDIN with -S option.


Note that plugin supports getting data from more than one file. In such a case you specify multiple OIDs with -O separated by ',' or multiple extend names with -E similarly separated by ','. The -F option can then contain multiple file names separated by ',' as well. -T option would save to multiple temporary file with %FILE1% being a macro to be replaced for first file name, %FILE2% for second and so on.


That's it. If you like this plugin have a comment or a suggestion, feel free to write me - my email address is above. Support is also provided by email.
Reviews (1)
byrafaeldriutti, August 5, 2013
Very usefull thanks!!

The download link needs to be updated, points to the 0.22 version, which lacks the -E option. To get the 0.3 version go to http://william.leibzon.org/nagios/plugins/check_by_snmp.pl