Last active
December 23, 2018 00:54
-
-
Save phunehehe/5564090 to your computer and use it in GitHub Desktop.
Script to check multiple URLs in Nagios, see http://phunehehe.net/check-multiple-urls-nagios/
This file contains hidden or 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 | |
# Split URLs by comma | |
urls=${1//,/ } | |
for url in $urls | |
do | |
hostname="${url%%/*}" | |
if [[ "$url" = */* ]] | |
then | |
# Domain plus path, like example.com/path | |
path="/${url#*/}" | |
else | |
# Just domain, like example.com | |
path=/ | |
fi | |
result="$(/usr/lib/nagios/plugins/check_http --hostname "$hostname" --url "$path")" | |
status="$?" | |
if [[ "$status" -ne 0 ]] | |
then | |
# First warning is the final result | |
echo "$url: $result" | |
exit "$status" | |
fi | |
done | |
echo "All URLs OK: $urls" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't either get this to work. I have a bunch of URL's. It shows All Urls OK even when given a wrong URL in the $urls !!!