Page 1 of 1

check_http and warning / critical on string match?

Posted: Thu Apr 21, 2016 6:12 pm
by nko321
I have a web page I'd like to check. It's a dashboard that displays a list of things and whether those things are "OK", "WARN", or "CRIT".

I'd like to create a check that looks at this page and goes into Warning if it sees "WARN" anywhere on the page and Critical if it sees "CRIT" anywhere on the page. I've found the --invert-regex parameter, but it looks like this only allows my checks to go Critical. I don't see a way to specify a match for both Warning and Critical. Can it be done?

Re: check_http and warning / critical on string match?

Posted: Fri Apr 22, 2016 9:46 am
by rkennedy
I wrote a simple wrapper script for you. The logic on this is very basic, and it expects only one of these words to be found. You'll need to modify this to your needs -

Code: Select all

#!/bin/bash
#make sure to change the check commands as needed. the logic on this is very basic.

#define vars
ok=$(/usr/local/nagios/libexec/check_http -H google.com -s 'ok' | grep 'OK' | wc -l)
warn=$(/usr/local/nagios/libexec/check_http -H google.com -s 'warn' | grep 'WARNING' | wc -l)
crit=$(/usr/local/nagios/libexec/check_http -H google.com -s 'critical' | grep 'CRITICAL' | wc -l)

#check values
if [ $ok -eq 1 ]
then
        state="OK"
                statecode="0"
elif [ $warn -eq 1 ]
then
        state="WARNING"
                statecode="1"
elif [ $crit -eq 1 ]
then
        state="CRITICAL"
                statecode="2"
else
        state="UNKNOWN"
                statecode="3"
fi
echo "$state: $state|state=$statecode"
exit $statecode

Re: check_http and warning / critical on string match?

Posted: Sun Apr 24, 2016 10:43 am
by nko321
Thanks! It looks so simple once the solution is staring back at you!

Re: check_http and warning / critical on string match?

Posted: Mon Apr 25, 2016 9:56 am
by rkennedy
No problem! Are we good to mark this thread as resolved?