check_tcp via string with warnings

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
deelight
Posts: 6
Joined: Wed Dec 16, 2015 6:23 pm

check_tcp via string with warnings

Post 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?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_tcp via string with warnings

Post 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?
Former Nagios Employee
deelight
Posts: 6
Joined: Wed Dec 16, 2015 6:23 pm

Re: check_tcp via string with warnings

Post 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.
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: check_tcp via string with warnings

Post 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?
Former Nagios Employee.
me.
deelight
Posts: 6
Joined: Wed Dec 16, 2015 6:23 pm

Re: check_tcp via string with warnings

Post by deelight »

yes, i just had hoped that there would be an easyier way ... ;)
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_tcp via string with warnings

Post 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!
Former Nagios Employee
deelight
Posts: 6
Joined: Wed Dec 16, 2015 6:23 pm

Re: check_tcp via string with warnings

Post 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
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: check_tcp via string with warnings

Post 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?
Former Nagios Employee.
me.
deelight
Posts: 6
Joined: Wed Dec 16, 2015 6:23 pm

Re: check_tcp via string with warnings

Post 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
deelight
Posts: 6
Joined: Wed Dec 16, 2015 6:23 pm

Re: check_tcp via string with warnings

Post 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
Locked