-
Notifications
You must be signed in to change notification settings - Fork 18
/
check_pf_emmc_status
126 lines (99 loc) · 2.74 KB
/
check_pf_emmc_status
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
#
# Joe Vivona 2022-08-02
# you must have mmc-utils pacakage installed first
EMMCCMD="/usr/local/sbin/mmc"
EMMCSTATUSCMD="$EMMCCMD extcsd read /dev/mmcsd0rpmb"
exitstatus=3
usage() {
echo "check_pf_emmc_status - Nagios Plugin for checking eMMC Life Time Estimates and Pre EOL Infomration"
echo ""
echo "see https://docs.netgate.com/pfsense/en/latest/troubleshooting/disk-lifetime.html for more information"
echo ""
echo "check_pf_emmc_status [-h] -C [LTEA | LTEB | EOL] -c <crit> -w <warn>"
echo ""
exit 3
}
ltea() {
$EMMCSTATUSCMD | grep EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A | awk -F: '{print $2}' | awk -Fx '{print $2}'
}
lteb() {
$EMMCSTATUSCMD | grep EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B | awk -F: '{print $2}' | awk -Fx '{print $2}'
}
eol() {
$EMMCSTATUSCMD | grep EXT_CSD_PRE_EOL_INFO | awk -F: '{print $2}' | awk -Fx '{print $2}'
}
parse_args() {
while test $# -gt 0; do
case $1 in
-h)
usage
shift
;;
-C)
checkname=$2
shift
;;
-w)
warn=$2
shift
;;
-c)
crit=$2
shift
;;
*)
echo "ERROR: unknown parameter \"$1\""
usage
shift
;;
esac
shift
done
}
# make sure MMC utils are installed
if [ ! -e $EMMCCMD ]; then
echo "MMC Utilities are not installed"
echo " run the following on the pfSense device via SSH: pkg install -y mmc-utils"
exit 3
fi
parse_args "$@"
if [ -z "$checkname" ] || [ -z "$warn" ] || [ -z "$crit" ]; then
usage
fi
# we've passed all the initial checks and parameters
# now go execute the correct check and return the results based upon WARN and CRIT levels
case $checkname in
"LTEA") RESULT=$(ltea) ;;
"LTEB") RESULT=$(lteb) ;;
"EOL") RESULT=$(eol) ;;
*) usage ;;
esac
if [ -z "$RESULT" ]; then
echo -n "Something has gone wrong with the eMMC check - review syntax "
exit 3
fi
RESULTDEC=`echo "ibase=16; $RESULT" | bc`
# invert the checks to make life easier
if [ $RESULTDEC -lt $warn ]; then
MESSAGE='eMMC lifespan is OK, current value: '$RESULT' '
exitstatus=0
fi
if [ $RESULTDEC -ge $warn ]; then
# this is WARNING status
MESSAGE='eMMC is in Warning State, value: '$RESULT' '
exitstatus=1
fi
if [ $RESULTDEC -ge $crit ]; then
# this is CRITICAL status
MESSAGE='eMMC is in Critical State, value: '$RESULT' '
exitstatus=2
fi
case $exitstatus in
0) exitmessage='OK' ;;
1) exitmessage='WARNING' ;;
2) exitmessage='CRITICAL' ;;
3) exitmessage='UNKNOWN' ;;
esac
echo "${exitmessage} - ${MESSAGE}"
exit $exitstatus