#!/bin/bash
# Script to use open source wget utility to check web sites
#   on nodes that are in NetView's database
# Target website host is passed as 1st parameter by servmon
# URL is passed as second parameter - this field must also
#   include :<portnumber> as a prepend,if required
#   URL should include preceding and trailing slashes
# wget will bring URL page back to /home/servmon/wget with
#     a filename of <host>_wget.out
# If wget fails then the output file will be zero-length
# NOTE that this is not threadsafe if there is more than one wget
#  servmon monitor running to any given webserver
#
# If the file exists and is greater than zero-length, then 
# exit 2 (normal status to servmon), otherwise exit 4 (critical)
#
set -x

HOST="$1"
URL="$2"
DIR="/home/servmon/wget/"
FILE="$DIR$HOST"_wget.out

wget -nv -O "$FILE" "$HOST$URL"

if [ -s "$FILE" ]
then
  exit 2
else
  exit 4
fi

