Page 1 of 2
check_tcp via string with warnings
Posted: Wed Dec 16, 2015 6:30 pm
by deelight
Hi Guys,
i've got a problem with the check_tcp plugin and counld not find any plugin who works like i need.
I'm sending a string to a port via check_tcp and get a number back, in this case 2580. On this number i need to define warning and crital values.
Example:
Code: Select all
/usr/lib/nagios/plugins# ./check_tcp -H XXXXXXXXXX -p 51031 -E -s "status\r\n" -d 1 -t 30 -e "SOMEThING"
TCP WARNING - Unexpected response from host/socket: [b]2580[/b]|time=0,000358s;;;0,000000;30,000000
I need somthing like
Code: Select all
/usr/lib/nagios/plugins# ./check_tcp -H XXXXXXXXXX -p 51031 -E -s "status\r\n" -d 1 -t 30 -w 2500 -c 3000
Is there anyway to do this or any plugin i've not found yet?
Re: check_tcp via string with warnings
Posted: Thu Dec 17, 2015 12:58 pm
by rkennedy
The check_tcp command is generating warning / critical based on the response time from the TCP port.
To help you find a plugin that will work for you, what kind of application is this?
Re: check_tcp via string with warnings
Posted: Thu Dec 17, 2015 5:16 pm
by deelight
It's a custom tool that looks into a folder at another location and show how many file are waiting. i have no other way to monitor this.
I need, like in check_smtp to define a warning/critical on the value i get beack when i ask the port for his status.
Re: check_tcp via string with warnings
Posted: Thu Dec 17, 2015 5:23 pm
by hsmith
You could write a wrapper script that executes the plugin, and exit 0/1/2 depending on what it finds using some if statements.
Do you follow?
Re: check_tcp via string with warnings
Posted: Thu Dec 17, 2015 5:26 pm
by deelight
yes, i just had hoped that there would be an easyier way ...

Re: check_tcp via string with warnings
Posted: Fri Dec 18, 2015 10:41 am
by rkennedy
As @hsmith, I think a bash script would be an easy enough way to parse the data for you.
For an example on how to write one, see
http://www.yourownlinux.com/2014/06/how ... cript.html
Let us know if you need any further assistance!
Re: check_tcp via string with warnings
Posted: Fri Dec 18, 2015 5:42 pm
by deelight
I build a small bash script that is working basicly... i'm just struggling with the difference between when it is a warning and a critical.
Code: Select all
if [ $RESPONSE -lt $WARN ]
then
echo "OK- $RESPONSE $MSG"
exit 0
elif [ $RESPONSE -ge $WARN -lt $CRIT ]
then
echo "WARNING- $RESPONSE $MSG"
exit 1
elif [ $RESPONSE -ge $CRIT ]
then
echo "CRITICAL- $RESPONSE $MSG"
exit 2
else
echo "UNKNOWN- $output"
exit 3
fi
Re: check_tcp via string with warnings
Posted: Mon Dec 21, 2015 10:21 am
by hsmith
deelight wrote:i'm just struggling with the difference between when it is a warning and a critical.
Can you elaborate on this a bit?
Re: check_tcp via string with warnings
Posted: Mon Dec 21, 2015 6:29 pm
by deelight
got it... just switched the order. The problem was, that when it was a critical value it was also a warning value so it exits already with 1. Now i have it like this:
Code: Select all
if [ $RESPONSE -lt $WARN ]
then
echo "OK- $RESPONSE $MSG"
exit 0
elif [ $RESPONSE -ge $CRIT ]
then
echo "CRITICAL- $RESPONSE $MSG"
exit 2
elif [ $RESPONSE -ge $WARN ]
then
echo "WARNING- $RESPONSE $MSG"
exit 1
else
echo "UNKNOWN- $RESPONSE"
exit 3
fi
Re: check_tcp via string with warnings
Posted: Mon Dec 21, 2015 6:43 pm
by deelight
My current solution looks like this:
Code: Select all
#!/bin/bash
#
[code]# Check TCP Response fuer NAGIOS
#
# by Kjell Krenz
#
#
# Version 0.1
#
#
while [ $# -gt 0 ]
do
case $1 in
-h)
HOST=$2
shift 2
;;
-p)
PORT=$2
shift 2
;;
-s)
STRING=$2
shift 2
;;
-w)
WARN=$2
shift 2
;;
-c)
CRIT=$2
shift 2
;;
-m)
MSG=$2
shift 2
;;
*)
echo "Usage:"
echo "-h: Host (IP)"
echo "-p: TCP Port"
echo "-s: STRING"
echo "-w: WARNING VALUE"
echo "-c: CRITICAL VALUE"
echo "-m: Custom Message Label"
shift 1
;;
esac
done
exec 3<>/dev/tcp/$HOST/$PORT
echo -en "$STRING\n" >&3
RESPONSE="`cat <&3`"
if [ $RESPONSE -lt $WARN ]
then
echo "OK- $RESPONSE $MSG"
exit 0
elif [ $RESPONSE -ge $CRIT ]
then
echo "CRITICAL- $RESPONSE $MSG"
exit 2
elif [ $RESPONSE -ge $WARN ]
then
echo "WARNING- $RESPONSE $MSG"
exit 1
else
echo "UNKNOWN- $RESPONSE"
exit 3
fi
esac
echo $RESPONSE
exit $EXIT