Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions plugins/check_nagios_latency
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash

# Path to nagiostats
NAGIOSTATS="/usr/sbin/nagios3stats"

PROGNAME=`basename $0`

#functions
Expand All @@ -24,23 +21,31 @@ function print_help() {
}

function test_integer() {
LABEL=$1
LABEL=$1
VALUE=$2

if ! echo $VALUE | grep -qE '^[0-9]+(\.[0-9]+)?$' ; then
OUTPUT="$LABEL has no integer value ($VALUE)! Please correct this parameter"
EXITCODE=3
fi

}

#defaults
EXITCODE=0
WARNING=120 # Warning at 2 minutes
CRITICAL=180 # Critical at 3 minutes

if [ ! -x $NAGIOSTATS ]; then
OUTPUT="Please correct path to nagiostats ($NAGIOSTATS)"
# Path to nagiosstats
NAGIOSSTATS3="/usr/sbin/nagios3stats"
NAGIOSSTATS4="/usr/sbin/nagios4stats"
NAGIOSSTATS=$NAGIOSSTATS3
if [ -x $NAGIOSSTATS4 ]; then
NAGIOSSTATS=$NAGIOSSTATS4
fi

if [ ! -x $NAGIOSSTATS ]; then
OUTPUT="Please correct path to nagiosstats ($NAGIOSSTATS)"
EXITCODE=3
fi

Expand All @@ -60,7 +65,7 @@ test_integer "-c" $CRITICAL
test_integer "-w" $WARNING

if [ $EXITCODE -eq 0 ]; then
LATENCY=`$NAGIOSTATS | awk '/Active Service Latency/ {print $8}' `
LATENCY=`$NAGIOSSTATS | awk '/Active Service Latency/ {print $8}' `
LATENCY_INT=`echo $LATENCY | cut -f1 -d"." `
if [ $LATENCY_INT -ge $CRITICAL ]; then
OUTPUT="CRITICAL: Latency at $LATENCY seconds! | latency=$LATENCY;$WARNING;$CRITICAL"
Expand All @@ -70,9 +75,8 @@ if [ $EXITCODE -eq 0 ]; then
EXITCODE=1
else
OUTPUT="OK: Latency at $LATENCY seconds. | latency=$LATENCY;$WARNING;$CRITICAL"
fi fi
fi fi
fi

echo $OUTPUT
exit $EXITCODE