[Nagiosplug-help] Check_netstat

Brad Beckenhauer bbecken at aafp.org
Tue Oct 20 22:53:18 CEST 2009


I need to query a remote system for a specific inbound IP:Port combination (ESTABLISHED)
 
example:  check_netstat 10.10.10.10:8100
and return OK if there is an ESTABLISHED connection.
 
The check_netstat will run on a remote host running nrpe.
Nrpe and the nagios-plugins are installed on the remote host and nagios is running the default checks against the nrpe host.
 
Below is the script I'm using, and it works on the nrpe host but not from the Nagios Server.
 
from the Nagios server:
check_nrpe -H 10.10.10.2 -c check_netstat -a 10.10.10.10:8100
NRPE: Unable to read output
 
I have debugging turned on for the remote host and found this in the log:
 
Oct 20 15:42:57 bugs nrpe[5964]: Host is asking for command 'check_netstat' to be run...
Oct 20 15:42:57 bugs nrpe[5964]: Running command: /etc/nagios/bb/check_netstat 10.10.10.10:8100
Oct 20 15:42:57 bugs nrpe[5964]: Command completed with return code 3 and output:
Oct 20 15:42:57 bugs nrpe[5964]: Return Code: 3, Output: NRPE: Unable to read output
What am I missing to make this script work?
 
thank you
 
 
#!/bin/bash
#
# check_netstat
#
# Check for an ESTABLISH /inbound connection to a particular port
#
# You may have to change the LIBEXEC, depending on where the
# nagios plugins are installed.
LIBEXEC="/usr/lib/nagios/plugins"
PATH="/usr/bin:/usr/sbin:/bin:/sbin"
 
# set Nagios environment variables $STATE_OK and $STATE_CRITICAL that
# are required in order to make this script report the proper status
# back to the Nagios server by including the Nagios utils.sh script.
. $LIBEXEC/utils.sh
 
if [[ $# -lt 1 ]]
then
    echo "Error: you must supply an argument like 10.10.10.1:8196"
else
        CONNECTION=$1
fi
 
function check_netstat() {
        # use netstat to query for a specific IP:PORT ESTABLISHED connection
        STATUS=`netstat -n | grep ESTABLISHED | grep $CONNECTION`
        if [ "$STATUS" != "" ]
        then
                # OK Port was found, return code 0 - OK
                echo "Connection OK. $exitstatus"
                exitstatus=$STATE_OK
                exit $exitstatus
        else
                # Error: Port was not found, return code 2 - critical
                echo "Connection not ESTABLISHED. $exitstatus "
                exitstatus=$STATE_CRITICAL
                exit $exitstatus
        fi
}
 
check_netstat
#
# eof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/help/attachments/20091020/de1bc552/attachment.html>


More information about the Help mailing list