Created
May 27, 2014 11:49
-
-
Save nv1t/bfa3d70570dc96d2637c to your computer and use it in GitHub Desktop.
Check IPMI with ignore list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) | |
# | |
# 27.05.2014 ignorelist Patch by Jan Hoersch <jan.hoersch@tmt.de> | |
# | |
use warnings; | |
use strict; | |
use Getopt::Long; | |
my $ignore=""; | |
my $result = GetOptions ("ignore=s" => \$ignore); | |
my %ignorelist = map {$_ => 1 } split(/,/,$ignore); | |
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" and !exists($ignorelist{$uname})) { | |
$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 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ignorelist can be set with: check_ipmi --ignore=Temp2,Temp3