Xymon Mailing List Archive search

Any way to do http tests with HEAD request?

list Jeremy Laidman
Tue, 14 Apr 2015 15:06:49 +1000
Message-Id: <user-911566419189@xymon.invalid>

On 14 April 2015 at 06:45, Andrew Rakowski <user-00c59fc5f1d5@xymon.invalid> wrote:
Thanks for the reply Jeremy.  I thought about making a "httphead" test in
the protocols.cfg file, and using the "curl" utility to do what BigBrother
used to do,

You would do one or the other.

but I don't see how to pass the URL to the test.
To use protocols.cfg, you would have to specify it in the protocols.cfg
file.  For example:

[httphead]
  port 80
  send "HEAD
/xyz/portal/user/anon/js_peid/123456790/panel/Main/template/content\r\nHost:
xyz.somewhere.com\r\n\r\n"
  expect "HTTP/1.1 200 OK"

Actually, my protocols.cfg (and probably the installed version) already had
a similar definition as [cuspd] which queries a CUPS protocol print server,
which is essentially a web service running on port 631.

Is there some implicit passing of test URL to these protocols.cfg defined
tests (like the string from the hosts.cfg file is stuck at the end of the
invoked command taken from protocols.cfg?)

No.  But you can do this with a script.  For example:

0.0.0.0 xyz-web2 # noconn HTTPHEAD:TIMEOUT=15,URL=
https://xyz.somewhere.com/xyz/portal/user/anon/js_peid/123456789/panel/Main/template/content

Then:

#!/bin/sh

[ "$XYMONHOME" ] || exit 1
TEST=httphead
CURL=/usr/bin/curl

$XYMONHOME/bin/xymongrep "HTTPHEAD:*" | sed 's/ *# */ /;s/ dialup//;s/
testip//'|
        while read IP HOST STRING; do
                PART=`IFS=":"; set - $STRING; shift; echo "$*"`
                (
                        IFS=,
                        set - $PART
                        TIMEOUT=15
                        URL=""
                        while [ "$1" ]; do
                                VAR=`IFS="="; set - $1; echo $1`
                                VAL=`IFS="="; set - $1; shift; echo "$*"`
                                case "$VAR" in
                                        TIMEOUT) TIMEOUT="$VAL";;
                                        URL) URL="$VAL";;
                                esac
                                shift
                        done
                        RESULT=`$CURL -g -s -S -m 45 -I -k
--connect-timeout $TIMEOUT "$URL" 2>&1`
                        [ $? -eq 0 ] && COL=green || COL=red
                        #printf "status $HOST.$TEST $COL `date` HEAD status
$COL\n\n$RESULT\n" | $XYMON $XYMSRV "@"
                        printf "status $HOST.$TEST $COL `date` HEAD status
$COL\n\n$RESULT\n"
                )
        done