Skip to content

Instantly share code, notes, and snippets.

@ericbarch
Last active February 5, 2024 20:08
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericbarch/2d1953c0af2459c89ab87a3064fdb2a0 to your computer and use it in GitHub Desktop.
Save ericbarch/2d1953c0af2459c89ab87a3064fdb2a0 to your computer and use it in GitHub Desktop.
Dead simple alerts when your mdadm array degrades without setting up a full blown MTA
#!/bin/bash
# dead simple mdadm alerts via webhook
# by eric barch [v1.0 -- 2018.11.26]
# 1. place this file in ~/chkraid.sh
# chmod +x ~/chkraid.sh
# 2. drop this in your crontab:
# 0 * * * * /home/<your_username>/chkraid.sh
# 3. get free account at http://healthchecks.io (no affiliation)
# then create a new healh check (period: one hour) and paste the URL below
SUCCESS_URL_HEALTHCHECK="https://hc-ping.com/YOUR_CHECK_URL"
# 4. fill in the substring that represents your healthy array
# helpful info on the output of /proc/mdstat here:
# https://raid.wiki.kernel.org/index.php/Mdstat#md_config.2Fstatus_line
# example: a dual RAID array (U represents a drive that is up)
RAID_HEALTHY_SUBSTRING="[UU]"
# 5. make sure you have curl installed
echo "Checking status of RAID array..."
raid_status=$(cat /proc/mdstat)
if [[ $raid_status == *"$RAID_HEALTHY_SUBSTRING"* ]]; then
echo "It's good!"
/usr/bin/curl $SUCCESS_URL_HEALTHCHECK
else
echo "Ahhhhh!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment