Skip to content

Instantly share code, notes, and snippets.

@derhofbauer
Created May 29, 2020 08:02
Show Gist options
  • Save derhofbauer/a6fc07bce5e749eee296f1a76fc54d3e to your computer and use it in GitHub Desktop.
Save derhofbauer/a6fc07bce5e749eee296f1a76fc54d3e to your computer and use it in GitHub Desktop.
Script to monitor your monitoring tool.
#!/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