[Nagiosplug-help] Check_netstat

Marc Powell marc at ena.com
Tue Oct 20 23:33:53 CEST 2009


On Oct 20, 2009, at 3:53 PM, Brad Beckenhauer wrote:

> 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
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart  
> your
> developing skills, take BlackBerry mobile applications to market and  
> stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference_______________________________________________
> Nagiosplug-help mailing list
> Nagiosplug-help at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagiosplug-help
> ::: Please include plugins version (-v) and OS when reporting any  
> issue.
> ::: Messages without supporting info will risk being sent to /dev/null





More information about the Help mailing list