$E_UNKNOWN $FW_LOCK $USAGE $HELP $LICENSE
$snmp_session $snmp_error $omreport $globalstatus $global
$linebreak $omopt_chassis $omopt_system $blade
- $exit_code $snmp $original_sigwarn
- %check %opt %perfdata %reverse_exitcode %status2nagios
+ $exit_code $snmp
+ %check %opt %reverse_exitcode %status2nagios
%snmp_status %snmp_probestatus %probestatus2nagios %sysinfo
%blacklist %nagios_alert_count %count
- @perl_warnings @controllers @enclosures
+ @perl_warnings @controllers @enclosures @perfdata
@report_storage @report_chassis @report_other
);
# Initialization and global variables
#---------------------------------------------------------------------
-# Small subroutine to collect any perl warnings during execution
-sub collect_perl_warning {
- push @perl_warnings, [@_];
-}
-
-# Set the WARN signal to use our collect subroutine above
-$original_sigwarn = $SIG{__WARN__};
-$SIG{__WARN__} = \&collect_perl_warning;
+# Collect perl warnings in an array
+$SIG{__WARN__} = sub { push @perl_warnings, [@_]; };
# Version and similar info
$NAME = 'check_openmanage';
-$VERSION = '3.5.7-beta15';
+$VERSION = '3.5.8-beta2';
$AUTHOR = 'Trond H. Amundsen';
$CONTACT = 't.h.amundsen@usit.uio.no';
SNMP OPTIONS:
- -H, --hostname Hostname or IP of the server (needed for SNMP)
+ -H, --hostname Hostname or IP (required for SNMP)
-C, --community SNMP community string
-P, --protocol SNMP protocol version
--port SNMP port number
);
# Performance data
-%perfdata = ();
+@perfdata = ();
# Global health status
$global = 1; # default is to check global status
# Collect performance data
if (defined $opt{perfdata}) {
$name =~ s{\A Temperature\sProbe\s(\d+) \z}{temp_$1}gxms;
- my $pkey = "enclosure_${encl_id}_${name}";
- my $pval = join q{;}, "${reading}C", $max_warn, $max_crit;
- $perfdata{$pkey} = $pval;
+ my $label = "enclosure_${encl_id}_${name}";
+ my $mini = $label;
+ $mini =~ s{enclosure_(.+?)_temp_(.+?)}{e$1t$2}xms;
+ push @perfdata, {
+ label => $label,
+ mini => $mini,
+ value => $reading,
+ warn => $max_warn,
+ crit => $max_crit,
+ };
}
}
return;
my $pname = lc $location;
$pname =~ s{\s}{_}gxms;
$pname =~ s{proc_}{cpu#}xms;
- my $pkey = join q{_}, 'fan', $index, $pname;
- my $pval = join q{;}, "${reading}RPM", $max_warn, $max_crit;
- $perfdata{$pkey} = $pval;
+ push @perfdata, {
+ label => "fan_${index}_${pname}",
+ mini => "f$index",
+ value => $reading,
+ warn => $max_warn,
+ crit => $max_crit,
+ };
}
}
return;
if ($snmp) {
$index = $out->{temperatureProbeIndex} - 1;
$status = $snmp_probestatus{$out->{temperatureProbeStatus}};
- $reading = $out->{temperatureProbeReading} / 10;
$location = $out->{temperatureProbeLocationName};
- $max_crit = $out->{temperatureProbeUpperCriticalThreshold} / 10;
- $max_warn = $out->{temperatureProbeUpperNonCriticalThreshold} / 10;
+ $reading = exists $out->{temperatureProbeReading}
+ ? $out->{temperatureProbeReading} / 10 : '[N/A]';
+ $max_crit = exists $out->{temperatureProbeUpperCriticalThreshold}
+ ? $out->{temperatureProbeUpperCriticalThreshold} / 10 : '[N/A]';
+ $max_warn = exists $out->{temperatureProbeUpperNonCriticalThreshold}
+ ? $out->{temperatureProbeUpperNonCriticalThreshold} / 10 : '[N/A]';
$min_crit = exists $out->{temperatureProbeLowerCriticalThreshold}
? $out->{temperatureProbeLowerCriticalThreshold} / 10 : '[N/A]';
$min_warn = exists $out->{temperatureProbeLowerNonCriticalThreshold}
? $out->{temperatureProbeLowerNonCriticalThreshold} / 10 : '[N/A]';
$type = get_hashval($out->{temperatureProbeType}, \%probe_type);
$discrete = exists $out->{temperatureProbeDiscreteReading}
- ? $out->{temperatureProbeDiscreteReading} : undef;
+ ? $out->{temperatureProbeDiscreteReading} : '[N/A]';
+ # workaround for bad temp probes
+ if ($type eq 'AmbientESM' and $reading !~ m{\A \d+(\.\d+)? \z}xms) {
+ $type = 'Discrete';
+ }
}
else {
$index = $out->{'Index'};
$count{temp}++;
if ($type eq 'Discrete') {
- my $msg = sprintf 'Temperature probe %d (%s): is %s',
+ my $msg = sprintf 'Temperature probe %d [%s] is %s',
$index, $location, $discrete;
my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
report('chassis', $msg, $err, $index);
$pname =~ s{\s}{_}gxms;
$pname =~ s{_temp\z}{}xms;
$pname =~ s{proc_}{cpu#}xms;
- my $pkey = join q{_}, 'temp', $index, $pname;
- my $pval = join q{;}, "${reading}C", $max_warn, $max_crit;
- $perfdata{$pkey} = $pval;
+ push @perfdata, {
+ label => "temp_${index}_${pname}",
+ mini => "t$index",
+ value => $reading,
+ warn => $max_warn,
+ crit => $max_crit,
+ };
}
}
}
# Collect performance data
if (defined $opt{perfdata}) {
next AMP if $reading !~ m{\A \d+(\.\d+)? \z}xms; # discrete reading (not number)
- my $pname = lc $location;
- $pname =~ s{\s}{_}gxms;
- my $pkey = join q{_}, 'pwr_mon', $index, $pname;
- my $pval = join q{;}, "$reading$unit", $max_warn, $max_crit;
- $perfdata{$pkey} = $pval;
+ my $label = join q{_}, 'pwr_mon', $index, lc $location;
+ $label =~ s{\s}{_}gxms;
+ push @perfdata, {
+ label => $label,
+ mini => "p${index}" . lc $unit,
+ value => $reading,
+ warn => $max_warn,
+ crit => $max_crit,
+ };
}
}
my %used = ();
# find used indexes
- foreach (keys %perfdata) {
- if (m/\A pwr_mon_(\d+)/xms) {
+ foreach (@perfdata) {
+ if ($_->{label} =~ m/\A pwr_mon_(\d+)/xms) {
$used{$1} = 1;
}
}
$found = 0;
next AMP2;
}
- if ($found and $line =~ m/\A ([^;]+?) ; (\d*\.\d+) \s ([AW]) \z/xms) {
+ if ($found and $line =~ m/\A ([^;]+?) ; (\d*\.\d+) \s [AW] \z/xms) {
my $aname = lc $1;
my $aval = $2;
- my $aunit = $3;
$aname =~ s{\s}{_}gxms;
# don't use an existing index
while (exists $used{$index}) { ++$index; }
- $perfdata{"pwr_mon_${index}_${aname}"} = "$aval$aunit;0;0";
+ push @perfdata, {
+ label => "pwr_mon_${index}_${aname}",
+ mini => "p${index}a",
+ value => $aval,
+ warn => 0,
+ crit => 0,
+ };
++$index;
}
}
# Fetch OMSA version via SNMP, put in sysinfo hash
#
sub get_snmp_about {
- my %omsa_oid
- = (
- '1.3.6.1.4.1.674.10892.1.100.10.0' => 'systemManagementSoftwareGlobalVersionName',
- );
- my $systemManagementSoftwareGroup = '1.3.6.1.4.1.674.10892.1.100';
- my $result = $snmp_session->get_table(-baseoid => $systemManagementSoftwareGroup);
+ # systemManagementSoftwareGlobalVersionName
+ my $oid = '1.3.6.1.4.1.674.10892.1.100.10.0';
+ my $result = $snmp_session->get_request(-varbindlist => [$oid]);
+
if (defined $result) {
- foreach my $oid (keys %{ $result }) {
- if (exists $omsa_oid{$oid} and $omsa_oid{$oid} eq 'systemManagementSoftwareGlobalVersionName') {
- $sysinfo{om} = ($result->{$oid});
- }
- }
+ $sysinfo{om} = exists $result->{$oid} && $result->{$oid} ne q{}
+ ? $result->{$oid} : 'unknown';
}
else {
- my $msg = sprintf 'SNMP ERROR getting OMSA info: %s',
- $snmp_session->error;
+ my $msg = sprintf 'SNMP ERROR: Getting OMSA version failed: %s', $snmp_session->error;
report('other', $msg, $E_UNKNOWN);
}
return;
}
}
+# Reset the WARN signal
+$SIG{__WARN__} = 'DEFAULT';
+
# Print any perl warnings that have occured
if (@perl_warnings) {
foreach (@perl_warnings) {
$exit_code = $E_UNKNOWN;
}
-# Reset the WARN signal
-$SIG{__WARN__} = $original_sigwarn;
-
# Print performance data
-if (defined $opt{perfdata} && !$opt{debug} && %perfdata) {
+if (defined $opt{perfdata} && !$opt{debug} && @perfdata) {
my $lb = $opt{perfdata} eq 'multiline' ? "\n" : q{ }; # line break for perfdata
print q{|};
- sub perfdata {
- my %order
- = (
- fan => 0,
- pwr => 1,
- temp => 2,
- enclosure => 3,
- );
- return ($order{(split /_/, $a, 2)[0]} cmp $order{(split /_/, $b, 2)[0]}) || $a cmp $b;
+ # Sort routine for performance data
+ sub perfsort {
+ my %order = ( fan => 0, pwr => 1, tem => 2, enc => 3, );
+ return ($order{(substr $a->{label}, 0, 3)} cmp $order{(substr $b->{label}, 0, 3)}) ||
+ $a->{label} cmp $b->{label};
}
- print join $lb, map { "'$_'=$perfdata{$_}" } sort perfdata keys %perfdata;
+ # Print performance data sorted
+ my $type = $opt{perfdata} eq 'minimal' ? 'mini' : 'label';
+ print join $lb, map { "$_->{$type}=$_->{value};$_->{warn};$_->{crit}" } sort perfsort @perfdata;
}
# Print a linebreak at the end