commit ba70f3b737fcd175b2d646316f55e9c6a838fcf5 Author: Jonny007-MKD Date: Thu Feb 6 20:50:46 2020 +0000 Fork from https://exchange.icinga.com/jasem/check_md_raid updated diff --git a/check_mdstat.sh b/check_mdstat.sh new file mode 100755 index 0000000..52488df --- /dev/null +++ b/check_mdstat.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# Created by Sebastian Grewe, Jammicron Technology +# Changes By Jasem Elayeb on 02.03.2016 +# JE: add Physical Disks Name RAID_DISKS +# JE: add Physical Disks Status DISKS_STATUS +# JE: add Array Names RAID_ARRAY + +# Get count of raid arrays +RAID_DEVICES=`grep ^md -c /proc/mdstat` + +# Get count of degraded arrays +RAID_STATUS=`grep "\[.*_.*\]" /proc/mdstat -c` + +# Is an array currently recovering, get percentage of recovery +RAID_RECOVER=`grep recovery /proc/mdstat | awk '{print $4}'` + +# Is an array currently resyncing, get percentage of resync + +RAID_RESYNC=`grep resync /proc/mdstat | awk '{print $4}'` + +RAID_ARRAY=`awk '/md[1-9]/{for (i=1;i<=NF;++i) if ($i~/md[1-2]/)print $i}' /proc/mdstat |xargs` +RAID_DISKS=`awk '/sd[a-z]/{for (i=1;i<=NF;++i) if ($i~/sd[a-z]/)print $i}' /proc/mdstat |xargs` +DISKS_STATUS=`grep algorithm /proc/mdstat|awk '{print $12}'` + +# Check raid status +# RAID recovers --> Warning +if [[ $RAID_RECOVER ]]; then + STATUS="WARNING - Checked $RAID_DEVICES arrays $RAID_ARRAY, recovering : $RAID_RECOVER" + EXIT=1 +# RAID resync --> Warning +elif [[ $RAID_RESYNC ]]; then + STATUS="WARNING - Checked $RAID_DEVICES arrays $RAID_ARRAY., resyncing : $RAID_RESYNC" + EXIT=1 +# RAID ok +elif [[ $RAID_STATUS == "0" ]]; then + STATUS="OK - Checked $RAID_DEVICES arrays $RAID_ARRAY." + EXIT=0 +# All else critical, better save than sorry +else + STATUS="CRITICAL - Checked $RAID_DEVICES arrays $RAID_ARRAY, $RAID_STATUS have FAILED" + EXIT=2 +fi + +# Status and quit +echo -e "$STATUS \n Physical Disks: $RAID_DISKS Disks Status: $DISKS_STATUS " +exit $EXIT