-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_salt_minions.sh
44 lines (38 loc) · 1.16 KB
/
check_salt_minions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
# Written by Jan Scheufler in late 2014
# Feel free to share, modify and improve
OK=0
UNKNOWN=0
WARNING=0
CRITICAL=0
# get all unresponsive minions
OUTPUT=`/usr/bin/sudo /usr/bin/salt-run manage.down`
# store return code
EC1=$?
# replace all new lines in the output with commas
OUTPUT="${OUTPUT//$'\n'/, }"
# OK - if return code 0 AND output empty
if [ $EC1 -eq 0 ] && [ -z "$OUTPUT" ]; then
echo "OK - all known salt minions report for duty"
((OK++))
# CRITICAL - if return code 0 AND output not empty
elif [ $EC1 -eq 0 ] && [ ! -z "$OUTPUT" ]; then
echo "CRITICAL - the following minion(s) do(es) not report for duty: $OUTPUT"
((CRITICAL++))
# CRITICAL - if return code not 0
elif [ $EC1 -ne 0 ]; then
echo "CRITICAL - the command used to check for unresponsive minions failed"
((CRITICAL++))
# UNKOWN - if none ob the above match, something is wrong
else
echo "UNKOWN - I don't even want to know how you got here; something is REALLY wrong"
((UNKNOWN++))
fi
# set exit code of the script
if [ $CRITICAL -gt 0 ]; then
exit 2
elif [ $UNKNOWN -gt 0 ]; then
exit 3
else
exit 0
fi