Skip to content

Instantly share code, notes, and snippets.

@stefanhoth
Last active December 29, 2015 13:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanhoth/7677580 to your computer and use it in GitHub Desktop.
Save stefanhoth/7677580 to your computer and use it in GitHub Desktop.
nagios check for parsing the body of the http response for a detailed message
#!/bin/bash
#check input parameters
if [ -z $1 ]; then
echo "Usage: $0 <url>"
exit 3
fi
#url to check
checkurl=$1
#get web content
response=$(wget -qO - $checkurl)
if [ $? -ne 0 ]; then
echo "UNKNOWN - error while running wget $checkurl"
exit 3
fi
#get text within body tag
response=$(echo $response|sed 's/.*<body[^>]*>\(.*\)<\/body>.*/\1/')
#print response as it is
echo $response
#use exit codes depending on response
if [[ "$response" = *WARNING* ]]; then exit 1; fi
if [[ "$response" = *CRITICAL* ]]; then exit 2; fi
if [[ "$response" = *OK* ]]; then exit 0; fi
#anything else will treated as UNKNOWN
exit 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment