Created
May 29, 2020 08:02
-
-
Save derhofbauer/a6fc07bce5e749eee296f1a76fc54d3e to your computer and use it in GitHub Desktop.
Script to monitor your monitoring tool.
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/sh | |
# PING test targets | |
ping_targets="example.org" | |
# HTTP STATUS test targets | |
status_targets="http://example.org:5000" | |
# Notification recipients | |
mail_to="[email protected]" | |
# Hosts, that failed at least one check | |
failed_hosts="" | |
# Ping Tests | |
for host in $ping_targets | |
do | |
ping -c 1 $host > /dev/null | |
if [ $? -ne 0 ]; then | |
if [ "$failed_hosts" == "" ]; then | |
failed_hosts="$host" | |
else | |
failed_hosts="$failed_hosts, $host" | |
fi | |
fi | |
done | |
# HTTP Status Tests | |
for host in $status_targets | |
do | |
http_status=`curl -LI "$host" -o /dev/null -w '%{http_code}' -s` | |
if [ "$http_status" != "200" ]; then | |
if [ "$failed_hosts" == "" ]; then | |
failed_hosts="$host" | |
else | |
failed_hosts="$failed_hosts, $host" | |
fi | |
fi | |
done | |
# Send Emails to defined addresses | |
if [ "$failed_hosts" != "" ]; then | |
for to in $mail_to | |
do | |
echo "Ping failed for: $failed_hosts" | mailx -s "Failed ping targets" $mail_to | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment