Shashikant shah

Saturday, 23 August 2014

Nagios Plugin for check ESTABLISHED connection "Web-Server" on Linux

#!/bin/bash

# Check for missing parameters
if [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]]; then
        echo "Missing parameters! Syntax: ./check_netstat.sh HOSTNAME WARNING_THRESHOLD CRITICAL_THRESHOLD"
        exit 2
fi

host=$1
port=$2
Warning=$3
Critical=$4

Time=`netstat -an | grep :$port | grep -c TIME_WAIT`;
Est=`netstat -an | grep :$port | grep -c ESTABLISHED`;
Close=`netstat -an | grep :$port | grep -c CLOSE_WAIT`;

# Connection is Establish---OK;

if [[ "$Est" -lt "$Warning" ]]; then
        echo "OK - ESTABLISHED $Est, TIME_WAIT $Time, CLOSE_WAIT $Close"
        exit 0
fi

# Connection is WARNING---WARNING;

if [[ "$Est" -gt "$Warning" ]] && [[ "$Est" -lt "$Critical" ]]; then
        echo "WARNING - ESTABLISHED $Est, TIME_WAIT $Time, CLOSE_WAIT $Close"       
        exit 1
fi

# Connection is CRITICAL---CRITICAL;

if [[ "$Est" -gt "$Critical" ]]; then
       echo "CRITICAL - ESTABLISHED $Est, TIME_WAIT $Time, CLOSE_WAIT $Close"       
        exit 2
fi

No comments:

Post a Comment