#!/bin/bash
# Script to use open source wget utility to check web sites
# 1st parameter by servmon is the hostname of a SmartSet member
#   - this shouldbe run against a SmartSet that only contains
#     the NetView server
# URL is passed as second parameter - this field should
#   include the whole URL,including <hostname>:<port>/<url>/
# 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_url.out

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

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

