blob: 1d2a5bdd87a24d758e1d056b9a0194725ffa415d (
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
|
#!/usr/bin/perl
# Nagios plugin for IPMI sensors status checking.
#
# Especially useful on Dell Poweredge servers, and others that
# implement the Intelligent Platform Management Interface (IPMI)
# interface.
#
# (C) Chris Wilson <check_ipmi@qwirx.com>, 2005-06-04
# Released under the GNU General Public License (GPL)
use warnings;
use strict;
open IPMI, "ipmitool sdr |" or die "ipmitool: $!";
my %found;
my %bad;
sub trim ($) {
my ($v) = @_;
$v =~ s/^ +//;
$v =~ s/ +$//;
return $v;
}
while (my $line = <IPMI>)
{
chomp $line;
unless ($line =~ m'^(.*) \| (.*) \| (\w+)$')
{
die "Bad format in ipmitool output: $line";
}
my $name = trim $1;
my $value = trim $2;
my $state = trim $3;
$name =~ tr| |_|;
my $counter = 1;
my $uname = "$name";
while ($found{$uname}) {
$uname = $name . $counter++;
}
next if $state eq "ns";
if ($state ne "ok") {
$bad{$uname} = $state;
}
$found{$uname} = $value;
}
if (keys %bad) {
print "IPMI critical: ";
my @bad;
foreach my $name (sort keys %bad) {
push @bad, "$name is $bad{$name}";
}
print join(", ", @bad) . " ";
} else {
print "IPMI ok ";
}
my @out;
foreach my $name (sort keys %found) {
next unless $name =~ m|Fan| or $name =~ m|Temp|;
push @out, "$name = $found{$name}";
}
print "(" . join(", ", @out) . ")\n";
if (%bad) { exit 2 } else { exit 0 }
|