hi i wanted to monitor tcp connections on specific ports so i created one ssh script which i kept in /var/prtg/scripts
scripts contents as follows
- !/bin/bash netstat -anp |egrep '(8081|8082|8083|8885)' |grep ESTABLISHED | awk '{print $1,$4,$5}'
which gives me error Response not wellformed: IP :PORT IP:PORT (code: PE132) i believe value:message is some setting is missing, i downt know to put where exactly or how can i get output in PRTG so that i can keep monitoring for the TCP Connections. Thanks in advance
Article Comments
Hi sanjaygurav2003
I think you expect a variable return in the sensor with multiple entries. But I don't think its possible what you want. You could measure "how many" established connections there are or if there is in fact one or not. But you cannot get variable data like all established connections. It would be possible as XML but then the amount of "lines" you get back is then fixed when you create the sensor.
You could count all the established connections and if there are too many, then the sensor will go red. Or even use the unusal detection. just add "| wc -l" at the end, then you should get how many established connections you have.
Have you already read through this?
regards Thomas
Mar, 2016 - Permalink
Hi Thomos
Ya true , i was expecting a variable return, instead of count in the sensor with the output with ip's & port. i can get now what i wanted from the link given by you. Thanks for your help
script used ( which shows 8885 port Established connection status)
#!/bin/bash port="8885" service="FIX-8885" NETSTAT=`which netstat` ID=`which id` die(){ exit 999 } is_root(){ local id=$($ID -u) if [ $id -ne 0 ] then echo "4:500:You have to be root to run $0." # returncode 4 = put sensor in DOWN status die fi } preparation(){ if [ ! -x $NETSTAT ] then echo "2:500:netstat not found." die fi if [ ! -x $ID ] then echo "2:500:id not found." # returncode = 2 = put sensor in DOWN status die fi is_root } check_service(){ serviceIsRunning=false openPorts=$($NETSTAT -n | grep '8885'| awk '{ print $4}' | awk -F: '{print $NF}' | sed '/^$/d' | sort -u) for openPort in $openPorts do if [ "$port" == "$openPort" ] then serviceIsRunning=true echo "0:200:$service is running." # returncode 0 = put sensor in OK status break fi done if [ $serviceIsRunning == false ] then echo "1:404:$service is not running." # returncode 1 = put sensor in WARNING status fi } main(){ preparation check_service } main
EDIT BY MOD: Formatting!
Mar, 2016 - Permalink
The output from scripts used by the SSH sensor need to be in the following format:
Example:
Make sure it matches. Since you're having multiple key value pairs, you might want to look into the SSH Script Advanced sensor which can take XML as a result. The format needs to be like this:
Mar, 2016 - Permalink