Last active
December 29, 2015 13:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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