From 8ff988095afd17a94caf7db5328d606c02b5b110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1ll=20Gu=C3=B0j=C3=B3n=20Sigur=C3=B0sson?= Date: Mon, 22 Nov 2010 15:55:32 +0000 Subject: [PATCH] check_snmp_tcpconnection.sh added --- misc/check_snmp_tcpconnection.sh | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 misc/check_snmp_tcpconnection.sh diff --git a/misc/check_snmp_tcpconnection.sh b/misc/check_snmp_tcpconnection.sh new file mode 100755 index 0000000..8d371da --- /dev/null +++ b/misc/check_snmp_tcpconnection.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Copyright 2010, Pall Sigurdsson +# +# This script is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# About this script +# +# This script will check for established TCP connection via SNMP + + + + +LOCAL_HOST=$1 +LOCAL_PORT=$2 +COMMUNITY=$3 +REMOTE_HOST=$4 +REMOTE_PORT=$5 + +if [ -z $REMOTE_HOST ]; then + echo "Usage: $0 " + exit 3 +fi + +OUTPUT=`/usr/bin/snmpwalk -v 2c -c $COMMUNITY $LOCAL_HOST TCP-MIB::tcpConnState.$LOCAL_HOST.$LOCAL_PORT.$REMOTE_HOST | grep -q established` +RESULT=$? + +if [ $RESULT -gt 0 ]; then + echo "TCP Connection from $REMOTE_HOST to $LOCAL_HOST:$LOCAL_PORT found" + echo "command:" + echo "/usr/bin/snmpwalk -v 2c -c $COMMUNITY $LOCAL_HOST TCP-MIB::tcpConnState.$LOCAL_HOST.$LOCAL_PORT.$REMOTE_HOST" + echo "OUTPUT: " + echo "$OUTPUT" + exit 1 +fi + +echo "TCP Connection from $REMOTE_HOST to $LOCAL_HOST:$LOCAL_PORT found" +exit 0