Page 1 of 2

Check_connections

Posted: Wed Mar 30, 2016 12:01 pm
by ednaldojta
Friends,
They've helped me a lot in the Post concerning check_by_ssh, however now I need a way to monitor the number of connections per port on servers.

And I need it with some plugin because the SSH is a bit complicated for commercial reasons. The servers to be monitored are from another company, and so I can not create an account to access via SSH, for security reasons.

For this need, through a plugin to bring number of connections per port.

I saw check_connections.sh the Nagios Exchange, but did not know how to set up the syntax in commands.cfg file Nagios.
What can help me thank you.

Re: Check_connections

Posted: Wed Mar 30, 2016 12:19 pm
by rkennedy
Your previous thread about the check_netstat_conn (https://support.nagios.com/forum/viewto ... 67#p177367) should work fine for this, if you don't want to use the SSH route, you can always take a look at executing the script through NRPE.

Re: Check_connections

Posted: Wed Mar 30, 2016 12:35 pm
by ednaldojta
configuring check_netstat_conn
because you need a syntax in commmands.cfg file.

Re: Check_connections

Posted: Wed Mar 30, 2016 12:37 pm
by rkennedy
Can you please clarify what you're saying?

Re: Check_connections

Posted: Wed Mar 30, 2016 1:34 pm
by ednaldojta
So I can install a plugin, I must first configure commands.cfg, correct file?

Yeah, I installed the plugin, however when I run the plugin appears that critique.

Re: Check_connections

Posted: Wed Mar 30, 2016 2:08 pm
by lmiltchev
I haven't used this plugin, but it seems to me that it could be only used locally, for example:

Code: Select all

/usr/local/nagios/libexec/check_netstat_conn -p <port>
I don't believe you will be able to check a remote server, unless you run it locally (on the remote server), and call it from XI via check_nrpe.

Re: Check_connections

Posted: Wed Mar 30, 2016 2:12 pm
by ednaldojta
there was a critical implementation.

Re: Check_connections

Posted: Wed Mar 30, 2016 3:53 pm
by rkennedy
Can you post the full script you're running?

Re: Check_connections

Posted: Thu Mar 31, 2016 8:38 am
by ednaldojta
is the Nagios Plugin itself that is on the Nagios Exchange page.

Code: Select all

#!/bin/sh
# 
# check_netstat_conn - Check listening ports using netstat utility
#
# Author:	Aaron Eidt ([email protected])
#

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

PROGRAM="check_netstat_conn"

usage () {
	printf "\n%s - Check port using netstat utility\n" $0
	printf "$Id: $PROGRAM 1 2013-07-08 $"
	printf "\nUsage: %s: -p\n\n" $0
}


port=

while getopts p: o
do
	case $o in
		p)
			port="$OPTARG"
			;;
		?)
			usage
			exit ${STATE_UNKNOWN}
			;;
	esac
done

if [ x$port = x ]; then
	usage
	exit ${STATE_UNKNOWN}
fi

$ENV{PATH}=$ENV{PATH}:/usr/local/nagios/libexec/
NETSTAT=`which netstat`

if [ ! -e $NETSTAT ]; then
	echo "CANNOT FIND NETSTAT!"
	exit ${STATE_UNKNOWN}
fi

result=`$NETSTAT -an | grep :$port`
num_conn=`echo $result | wc -l`

if [ `echo $result | egrep -c 'LISTEN|ESTABLISHED'` -gt 1 ]; then
	echo "OK: There are $num_conn established or listening connections on port $port"
	exit ${STATE_OK}
fi

echo "CRITICAL: There are NO established or listening connections on port $port"
exit ${STATE_CRITICAL}

Re: Check_connections

Posted: Thu Mar 31, 2016 1:33 pm
by tmcdonald
Try changing line 43 from

$ENV{PATH}=$ENV{PATH}:/usr/local/nagios/libexec/

to

PATH=$PATH:/usr/local/nagios/libexec/

then re-run it.