Last active
March 29, 2019 13:56
-
-
Save Buzut/c72fb2ad17a374860733382581bcb84b to your computer and use it in GitHub Desktop.
Various simple Sensu checks
This file contains 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 | |
# check if given host returns HTTP status 200 | |
# usage: httpd.sh [host:port] | |
# ex: httpd localhost:3000 | |
# if no arguments, default to localhost:80 | |
if [ -z "$1" ] | |
then | |
httpd=`curl -s -D - localhost -o /dev/null | sed -n '/HTTP/p'` | |
else | |
httpd=`curl -s -D - $1 -o /dev/null | sed -n '/HTTP/p'` | |
fi | |
if [[ "$httpd" == *200* ]] | |
then | |
echo "httpd up" | |
exit 0 | |
else | |
echo "httpd down" | |
exit 2 | |
fi |
This file contains 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 | |
#template from https://www.thomas-krenn.com/en/wiki/Mdadm_checkarray | |
# monitor mismatch_cnt (/sys/block/md*/md/mismatch_cnt) | |
# usage: raid.sh [warning critical] | |
# if no arguments, defaults to 1 10 | |
if [ -z "$1" ] | |
then | |
WARN_LIMIT=1 | |
else | |
WARN_LIMIT=$1 | |
fi | |
if [ -z "$2" ] | |
then | |
CRIT_LIMIT=10 | |
else | |
CRIT_LIMIT=$2 | |
fi | |
if [ -z $WARN_LIMIT ] || [ -z $CRIT_LIMIT ] | |
then | |
echo "Usage: raid.sh WARNLIMIT CRITLIMIT" | |
exit 3; | |
else | |
DATA=-1 | |
for file in /sys/block/md*/md/mismatch_cnt | |
do | |
DATA=`cat $file` | |
MD_NAME=`echo $file | awk 'BEGIN { FS = "/" } ; { print $4 }'` | |
PERF_DATA+="$MD_NAME=`cat $file` " | |
done | |
if [ $DATA -eq -1 ] | |
then | |
echo "UNKNOWN - software raid mismatch_cnts not found | $PERF_DATA" | |
exit 3; | |
fi | |
if [ $DATA -lt $WARN_LIMIT ] | |
then | |
echo "OK - all software raid mismatch_cnts are smaller than $WARN_LIMIT | $PERF_DATA" | |
exit 0; | |
fi | |
if [ $DATA -ge $WARN_LIMIT ] && [ $DATA -lt $CRIT_LIMIT ] | |
then | |
echo "WARNING - software raid mismatch_cnts are greater or equal than $WARN_LIMIT | $PERF_DATA" | |
exit 1; | |
fi | |
if [ $DATA -ge $CRIT_LIMIT ] | |
then | |
echo "CRITICAL - software raid mismatch_cnts are greater or equal than $CRIT_LIMIT | $PERF_DATA" | |
exit 2; | |
fi | |
if [ $DATA -eq -1 ] | |
then | |
echo "UNKNOWN - software raid mismatch_cnts not found | $PERF_DATA" | |
exit 3; | |
fi | |
fi |
This file contains 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 | |
# check if server needs to be restarted | |
if [ -f /var/run/reboot-required ] | |
then | |
echo "A reboot is needed" | |
exit 1 | |
else | |
echo "All good!" | |
exit 0 | |
fi |
This file contains 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 | |
# check if a given service is running | |
# usage: service.sh serviceName | |
service=$1 | |
if [ -z $service ] | |
then | |
echo "Usage: service.sh serviceName" | |
exit 3 | |
fi | |
# search for line with "active (running)" | |
return=`service $service status | grep "active (running)"` | |
# if nothing is found, var is empty | |
if [ -z "return" ] | |
then | |
echo "Ooops, $service has stopped" | |
exit 2 | |
else | |
echo "All good!" | |
exit 0 | |
fi |
This file contains 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 | |
# check if disks pass SMART test | |
for disk in `lsblk | grep disk | cut -d ' ' -f 1` | |
do | |
status=`smartctl --health /dev/$disk | grep PASSED` | |
if [[ -z "$status" ]] | |
then | |
echo "Disk $disk has a problem" | |
diskFailure=true | |
fi | |
done | |
if [[ $diskFailure = "true" ]] | |
then | |
exit 2 | |
else | |
echo All disks ok | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment