aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_ipmi
blob: b1223eec7ea31d19f71f5c3f18ca57a34c32587e (plain)
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
#!/bin/bash

#-I lanplus -U <User> -P <PW> -L User -H <Host>

2>&2 > /dev/null which ipmitool || exit 3

# also replaces na with ""
function strip_string() {
	local RETURN=""
	[ "$1" = "na" ] || RETURN="$@"
	echo "$RETURN"
}

function float_compare() {
	[ $# -ne 2 ] && return 1

	(( $(echo "$1 > $2" | bc -l ) )) && return 0
	return 1
}

WARN=()
CRIT=()

PERFDATA=()

DATA="$(ipmitool $@ sensor list; exit $?)"
RET=$?

if [ $RET -ne 0 ]; then
	echo UNKOWN: IPMI error
	echo "$DATA"
	exit 3
fi

# Lower Non-Recoverable : na
# Lower Critical        : 5.000
# Lower Non-Critical    : 10.000
# Upper Non-Critical    : 61.000
# Upper Critical        : 66.000
# Upper Non-Recoverable : na
while IFS='|' read sensor value unit state lnr lc lw uw uc unr ; do
	val="$( strip_string $value )"
	[ -z $val ] && continue

	unt="$( strip_string $unit )"
	[ -z "$unt" -o "$unt" = "discrete" ] && continue

	snsr="$( strip_string $sensor )"

	low_warn="$( strip_string $lw )"
	low_crit="$( strip_string $lc )"
	hi_warn="$(  strip_string $uw )"
	hi_crit="$(  strip_string $uc )"

	if float_compare $val $hi_crit || float_compare $low_crit $val; then
		CRIT+=("$snsr")
	elif float_compare $val $hi_warn || float_compare $low_warn $val; then
		WARN+=("$snsr")
	fi

	PERFDATA+=("$snsr=$val;$low_warn${hi_warn:+:$hi_warn};$low_crit${hi_crit:+:$hi_crit}")
done <<< "$DATA"

if [ ${#WARN[@]} -gt 0 ]; then
	echo -n "IPMI WARNING: ${WARN[@]}"
	RET=1
elif [ ${#CRIT[@]} -gt 0 ]; then
	echo -n "IPMI CRITICAL: ${CRIT[@]}"
	RET=2
else
	echo -n "IPMI OK"
	RET=0
fi

echo "|${PERFDATA[@]}"