4

I've got a problem with the check_tcp plugin from Nagios and could not find any plugin that 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:

/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: 2580|time=0,000358s;;;0,000000;30,000000

I need somthing like:

/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?

2 Answers 2

3

Create your own wrapper, ie. in Perl, to execute the check_tcp internally, then analyse the response and return exit code according to the response.

With so simple check, you might even implement the whole thing in Perl without wrapping the other command. Sample code is here: http://xmodulo.com/how-to-write-simple-tcp-server-and-client-in-perl.html

1
  • Or just use Perl to connect to a TCP socket.
    – lazyfrosch
    Dec 18, 2015 at 16:25
0

Finally i wrote a small bash script that basicly works fine... Just still got some bugs inside, so if there are any ideas for improvement:

#!/bin/bash
#
# 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .