1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 18:07:20 +00:00
Munin-Contrib/plugins/sensors/freeipmi
Diego Elio Pettenò 7ed16b61e5 freeipmi: replace wildcard plugin with a multigraph one.
This new plugin is written in Perl rather than sh+awk, executes
ipmi-sensors only once per call (config/fetch still require two calls
total), and with one call it produces all the available graphs
depending on the available sensors.

This still allows for monitoring a remote system, and that becomes
even more interesting since it only fetches data once.

The plugin will also now fail autoconf if there is no sensor output
that can be monitored.
2012-10-23 17:14:57 -07:00

170 lines
4.4 KiB
Perl
Executable file

#!/usr/bin/perl -w
# -*- cperl -*-
=head1 NAME
freeipmi - Multigraph-plugin to monitor sensors using FreeIPMI
=head1 CONFIGURATION
=head2 ENVIRONMENT VARIABLES
When used to monitor a foreign host, this plugins use the variables
IPMI_USERNAME and IPMI_PASSWORD to log in on the remote system.
=head2 WILDCARD PLUGIN
When used for the local host, the plugin should be linked as
non-wildcard plugin, i.e., 'freeipmi', whereas when used to monitor a
foreign host it should be, e.g., 'freeipmi_192.168.0.253'.
=head1 AUTHOR
Diego Elio Pettenò <flameeyes@flameeyes.eu>.
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
use strict;
use Munin::Plugin;
$ENV{'LANG'} = "C"; # Force parsable output from sensors.
$ENV{'LC_ALL'} = "C"; # Force parsable output from sensors.
my $IPMISENSORS = $ENV{'ipmisensors'} || 'ipmi-sensors';
$0 =~ /freeipmi(?:_(.+))$/;
my $hostname = $1;
$IPMISENSORS .= " --quiet-cache --comma-separated-output --no-header-output --ignore-not-available-sensors --sensor-types=Temperature,Fan,Current,Voltage --output-sensor-thresholds";
$IPMISENSORS .= " --hostname=$hostname" if defined($hostname);
$IPMISENSORS .= " --username=$ENV{IPMI_USERNAME}" if defined($ENV{IPMI_USERNAME});
$IPMISENSORS .= " --password=$ENV{IPMI_PASSWORD}" if defined($ENV{IPMI_PASSWORD});
my $output=`$IPMISENSORS --output-sensor-thresholds 2>/dev/null`;
my $retval=$?;
if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
if ($retval >= 1) {
print "no (ipmi-sensors died)\n";
} elsif ($retval == -1) {
print "no (ipmi-sensors not found)\n";
} elsif ($output eq "\n") {
print "no (no compatible sensors)\n";
} else {
print "yes\n";
}
exit 0;
}
my %sensors = (
temp => {
inputs => [],
title => "Temperatures by IPMI",
vlabel => "Degrees Celsius",
graph_args => "--base 1000 -l 0",
},
fan => {
inputs => [],
title => "Fans speed by IPMI",
vlabel => "RPM",
graph_args => "--base 1000 -l 0",
},
power => {
inputs => [],
title => "Power by IPMI",
vlabel => "W",
graph_args => "--base 1000 -l 0",
},
current => {
inputs => [],
title => "Current by IPMI",
vlabel => "A",
graph_args => "--base 1000 -l 0",
},
voltage => {
inputs => [],
title => "Voltages by IPMI",
vlabel => "Volt",
graph_args => "--base 1000 --logarithmic",
},
);
my @data = split(/\n/, $output);
foreach my $line (@data) {
my @dataline = split(/,/, $line);
my %sensor = (
graphid => "ipmi" . $dataline[0],
value => $dataline[3],
label => $dataline[1]
);
$sensor{lwarn} = $dataline[7] if $dataline[7] ne "N/A";
$sensor{hwarn} = $dataline[9] if $dataline[9] ne "N/A";
$sensor{lcrit} = $dataline[6] if $dataline[6] ne "N/A";
$sensor{hcrit} = $dataline[10] if $dataline[10] ne "N/A";
my $type;
if ( $dataline[2] eq "Temperature" ) {
$type = "temp";
} elsif ( $dataline[2] eq "Fan" ) {
$type = "fan"
} elsif ( $dataline[2] eq "Current" and $dataline[4] eq "W" ) {
$type = "power";
} elsif ( $dataline[2] eq "Current" and $dataline[4] eq "A" ) {
$type = "current";
} elsif ( $dataline[2] eq "Voltage" ) {
$type = "voltage";
}
push(@{$sensors{$type}->{inputs}}, \%sensor);
}
if ( defined $ARGV[0] and $ARGV[0] eq 'config' ) {
foreach my $type (keys %sensors) {
# don't print anything if no value is found
next if scalar(@{$sensors{$type}->{inputs}}) == 0;
print "host_name $hostname" if defined($hostname);
print <<END;
multigraph freeipmi_$type
graph_title $sensors{$type}->{title}
graph_vlabel $sensors{$type}->{vlabel}
graph_args $sensors{$type}->{graph_args}
graph_category sensors
END
foreach my $sensor (@{$sensors{$type}->{inputs}}) {
print "$sensor->{graphid}.label $sensor->{label}\n";
print "$sensor->{graphid}.warning $sensor->{lwarn}:$sensor->{hwarn}\n"
if defined($sensor->{lwarn}) or defined($sensor->{hwarn});
print "$sensor->{graphid}.critical $sensor->{lcrit}:$sensor->{hcrit}\n"
if defined($sensor->{lcrit}) or defined($sensor->{hcrit});
}
}
exit 0;
}
foreach my $type (keys %sensors) {
# don't print anything if no value is found
next if scalar(@{$sensors{$type}->{inputs}}) == 0;
print "multigraph sensors_$type\n";
foreach my $sensor (@{$sensors{$type}->{inputs}}) {
print "$sensor->{graphid}.value $sensor->{value}\n";
}
}