check_http and warning / critical on string match?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
nko321
Posts: 2
Joined: Thu Apr 21, 2016 6:09 pm

check_http and warning / critical on string match?

Post 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?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_http and warning / critical on string match?

Post 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
Former Nagios Employee
nko321
Posts: 2
Joined: Thu Apr 21, 2016 6:09 pm

Re: check_http and warning / critical on string match?

Post by nko321 »

Thanks! It looks so simple once the solution is staring back at you!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_http and warning / critical on string match?

Post by rkennedy »

No problem! Are we good to mark this thread as resolved?
Former Nagios Employee
Locked