File check_ipmi_sensors of Package nagios-plugins-ipmi
1
#!/bin/bash
2
3
#
4
# check_ipmi: Only checks temperatures and fan speeds. No voltages to
5
# speak of in the computers I have.
6
#
7
# WARNING: Nagios has a 10 second timeout on plugins. On some hosts
8
# ipmitool takes longer than that to probe all your hardware. In this
9
# case this plugin us unusable.
10
#
11
# Donated to the public domain by Nicolai Langfeldt (janl@linpro.no)
12
#
13
14
ipmitool sensor | gawk -F'|' '
15
BEGIN {
16
EXIT=0;
17
MSG[0]="OK: ";
18
MSG[1]="WARNING: ";
19
MSG[2]="CRITICAL: ";
20
}
21
22
# Remove extraneous spaces to make output prettyer
23
{ gsub(/\t/," "); gsub(/ +/," "); gsub(/ +\|/,"|"); gsub(/\| +/,"|") }
24
25
# Skip lines with 0x0 in first column
26
/^[^|]+\|0x0\|/ { next; };
27
28
# Skip lines with na in first column
29
/^[^|]+\|na\|/ { next; };
30
31
# Parse temperatures
32
/degrees C/ {
33
THING=$1;
34
TEMP=$2;
35
OK=$4;
36
if (OK ~ /ok/) {
37
MSG[0] = sprintf("%s %s is %dC, ",MSG[0] , THING,TEMP);
38
next;
39
}
40
WARN=$8;
41
CRIT=$9;
42
if (CRIT !~ /na/ && TEMP>=CRIT) {
43
MSG[2] = sprintf("%s %s is %dC (max %d) ",
44
MSG[2], THING, TEMP, CRIT);
45
EXIT=2;
46
next;
47
}
48
49
if (WARN !~ /na/ && TEMP>=WARN) {
50
MSG[1] = sprintf("%s %s is %dC (max %dC, critical at %dC) ",
51
MSG[1], THING, TEMP, CRIT);
52
if (EXIT=0) EXIT=1;
53
next;
54
}
55
# Fall through, all we know is that temp is not OK.
56
57
MSG[2] = sprintf("%s %s is %d (%s) ", MSG[2], THING, TEMP, OK);
58
if (EXIT=0) EXIT=1;
59
}
60
61
/RPM/ {
62
THING=$1;
63
SPEED=$2;
64
OK=$4;
65
66
if (OK ~ /ok/) {
67
MSG[0] = sprintf("%s %s is at %d RPM, ",MSG[0], THING, SPEED);
68
next;
69
}
70
MIN=$6;
71
72
if (MIN !~ /na/ && SPEED<MIN) {
73
MSG[2] = sprintf("%s %s is %dC (min %d) ",
74
MSG[2], THING, SPEED, MIN);
75
EXIT=2;
76
next;
77
}
78
79
# Fall through, all we know is that speed is not OK.
80
81
MSG[2] = sprintf("%s %s is %d (%s) ", MSG[2], THING, SPEED, OK);
82
if (EXIT=0) EXIT=1;
83
}
84
85
END {
86
gsub(/, *$/,"",MSG[EXIT]);
87
print MSG[EXIT];
88
exit EXIT;
89
}
90
'
91