AW: Simple regular expressions & http_check

Helmut Januschka h.januschka at krone.at
Thu Apr 15 10:07:14 CEST 2004


here you go with perl regexes! 
requires wget, perl


use -N to invert -> if string is not found

#!/bin/bash

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.1 $' | sed -e 's/[^0-9.]//g'`

. $PROGPATH/utils.sh

print_usage() {
        echo -e "Check WebSite Plugin $REVISION\nWritten by Helmut Januschka(klewan at chello.at)"
        echo -e "* Checks if Given String is found in Webpage (Threw http 1.1 request)";
        echo -e "* If  -N 1 Checks if given string is not found in webpage";
        echo "---------------------Usage-----------------------------------------------"
        echo "-S String To Find Def=<html>"
        echo "-U Url (where to find the string) Def:/"
        echo "-H Host Def:localhost"
        echo "-T Trigger Command to execute if -S not found in -U (if no given not used)"
        echo "-P Port Def:80"
        echo "-N Negate Search 0/1 alert if -S IS found in -U Def:0";
        echo "-h  Show This Help"
        echo "-------------------------------------------------------------------------"
        print_revision
}

#Defs:
STRING="<html>";
URL="/";
HOST="localhost";
TRIGGER="";
PORT=80
NEGATE=0;

while getopts N:S:P:U:H:T:h o
do
        case $o in
        S) STRING=$OPTARG;;
        U) URL=$OPTARG;;
        T) TRIGGER=$OPTARG;;
        H) HOST=$OPTARG;;
        P) PORT=$OPTARG;;
        N) NEGATE=$OPTARG;;
        h) print_usage; exit $STATE_UNKOWN;;

        esac

done


#####
#do da check
c=0;
if [ $NEGATE -eq 0 ]; then

        wget -q -O /dev/stdout "http://$HOST:$PORT/$URL"|perl -ne "if (/$STRING/i) { exit 1;}"
        c=$?;

        if [ $c -eq 0 ]; then
                echo "Check Site2 ($URL / $HOST:$PORT, $STRING not found) [critical `date`]";
                exit $STATE_CRITICAL;

        fi;
        echo "Check Site2 ($URL / $HOST:$PORT, $STRING found) [ok `date`]";
        exit $STATE_OK;

else
        wget -q -O /dev/stdout "http://$HOST:$PORT/$URL"|perl -ne "if (/$STRING/i) { exit 1;}"
        c=$?;

        if [ $c -eq 1 ]; then
                echo "Check Site2(NEGATIVE)C ($URL / $HOST:$PORT, $STRING found) [critical `date`]";
                exit $STATE_CRITICAL;

        fi;

        echo "Check Site2(NEGATE)OK ($URL / $HOST:$PORT, $STRING not found) [ok `date`]";
        exit $STATE_OK;

fi;
-----Ursprüngliche Nachricht-----
Von: Michael T. Halligan [mailto:michael at halligan.org] 
Gesendet: Donnerstag, 15. April 2004 03:07
An: nagios-users at lists.sourceforge.net
Betreff: [Nagios-users] Simple regular expressions & http_check


I'm trying to use a check_http to monitor a url on a webserver. If the appserver behind the webserver is working, it will always include a specific string :

<form name="PdcSurvey" action="http://test.domain/pss/pss6" onsubmit="return PdcProcessPage();" method="post">

My service check entry is this : 

/usr/lib/nagios/plugins/check_http -t  60 -H test.domain -u http://test.domain/pss/survey/2gnsJ/app_test_survey.htm?U2=test -r '<form name=\"PdcSurvey\" action=\"http://test.domain/pss/pss6\" onsubmit=\"return PdcProcessPage\(\);\" method=\"post\">'

And this works  just fine if I do it from the command line.

However, if I run this from nagios, it always fails claiming "No Output"

What am I doing wrong with this? Does nagios end up quoting things funny?

-------------------
Michael T. Halligan
Chief Geek
Halligan Infrastructure Designs.
http://www.halligan.org/
2250 Jerrold Ave #11
San Francisco, CA 94124-1012
(415) 724.7998 - Mobile



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list