root / plugins / sensors / freeipmi @ 5ee4d8cf
Historique | Voir | Annoter | Télécharger (5,17 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# -*- cperl -*- |
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
freeipmi - Multigraph-plugin to monitor sensors using FreeIPMI |
| 6 |
|
| 7 |
=head1 CONFIGURATION |
| 8 |
When used to monitor the local host, plugin config should define user root for direct ipmi access: |
| 9 |
[freeipmi] |
| 10 |
user root |
| 11 |
|
| 12 |
=head2 ENVIRONMENT VARIABLES |
| 13 |
|
| 14 |
When used to monitor a foreign host, this plugins use the variables |
| 15 |
IPMI_USERNAME and IPMI_PASSWORD to log in on the remote system. |
| 16 |
|
| 17 |
=head2 WILDCARD PLUGIN |
| 18 |
|
| 19 |
When used for the local host, the plugin should be linked as |
| 20 |
non-wildcard plugin, i.e., 'freeipmi', whereas when used to monitor a |
| 21 |
foreign host it should be, e.g., 'freeipmi_192.168.0.253'. |
| 22 |
|
| 23 |
=head1 DEPENDENCIES |
| 24 |
|
| 25 |
The plugin requires FreeIPMI 1.1.5 or later to fetch the information. |
| 26 |
Limits set on thresholds are available when using FreeIPMI 1.2.0 or |
| 27 |
later. |
| 28 |
|
| 29 |
=head1 AUTHOR |
| 30 |
|
| 31 |
Diego Elio Pettenò <flameeyes@flameeyes.eu>. |
| 32 |
|
| 33 |
With help and suggestions of: |
| 34 |
|
| 35 |
Bart ten Brinke <info@retrosync.com> |
| 36 |
|
| 37 |
=head1 LICENSE |
| 38 |
|
| 39 |
GPLv2 |
| 40 |
|
| 41 |
=head1 MAGIC MARKERS |
| 42 |
|
| 43 |
#%# family=auto |
| 44 |
#%# capabilities=autoconf |
| 45 |
|
| 46 |
=head1 LICENSE |
| 47 |
|
| 48 |
GPLv2 |
| 49 |
|
| 50 |
=head1 MAGIC MARKERS |
| 51 |
|
| 52 |
#%# family=auto |
| 53 |
#%# capabilities=autoconf |
| 54 |
|
| 55 |
=cut |
| 56 |
|
| 57 |
use strict; |
| 58 |
use Munin::Plugin; |
| 59 |
|
| 60 |
$ENV{'LANG'} = "C"; # Force parsable output from sensors.
|
| 61 |
$ENV{'LC_ALL'} = "C"; # Force parsable output from sensors.
|
| 62 |
my $IPMISENSORS = $ENV{'ipmisensors'} || 'ipmi-sensors';
|
| 63 |
|
| 64 |
$0 =~ /freeipmi(?:_(.+))$/; |
| 65 |
my $hostname = $1; |
| 66 |
|
| 67 |
my $help_output = `$IPMISENSORS --help`; |
| 68 |
|
| 69 |
$IPMISENSORS .= " --output-sensor-thresholds" if $help_output =~ /--output-sensor-thresholds/; |
| 70 |
$IPMISENSORS .= " --quiet-cache --comma-separated-output --no-header-output --ignore-not-available-sensors --sensor-types=Temperature,Fan,Current,Voltage"; |
| 71 |
$IPMISENSORS .= " --hostname=$hostname" if defined($hostname); |
| 72 |
$IPMISENSORS .= " --username=$ENV{IPMI_USERNAME}" if defined($ENV{IPMI_USERNAME});
|
| 73 |
$IPMISENSORS .= " --password=$ENV{IPMI_PASSWORD}" if defined($ENV{IPMI_PASSWORD});
|
| 74 |
|
| 75 |
my $output=`$IPMISENSORS 2>/dev/null`; |
| 76 |
my $retval=$?; |
| 77 |
|
| 78 |
if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
|
| 79 |
if ($retval >= 1) {
|
| 80 |
print "no (ipmi-sensors died)\n"; |
| 81 |
} elsif ($retval == -1) {
|
| 82 |
print "no (ipmi-sensors not found)\n"; |
| 83 |
} elsif ($output eq "\n") {
|
| 84 |
print "no (no compatible sensors)\n"; |
| 85 |
} else {
|
| 86 |
print "yes\n"; |
| 87 |
} |
| 88 |
|
| 89 |
exit 0; |
| 90 |
} |
| 91 |
|
| 92 |
my %sensors = ( |
| 93 |
temp => {
|
| 94 |
inputs => [], |
| 95 |
title => "Temperatures by IPMI", |
| 96 |
vlabel => "Degrees Celsius", |
| 97 |
graph_args => "--base 1000 -l 0", |
| 98 |
}, |
| 99 |
fan => {
|
| 100 |
inputs => [], |
| 101 |
title => "Fans speed by IPMI", |
| 102 |
vlabel => "RPM", |
| 103 |
graph_args => "--base 1000 -l 0", |
| 104 |
}, |
| 105 |
power => {
|
| 106 |
inputs => [], |
| 107 |
title => "Power by IPMI", |
| 108 |
vlabel => "W", |
| 109 |
graph_args => "--base 1000 -l 0", |
| 110 |
}, |
| 111 |
current => {
|
| 112 |
inputs => [], |
| 113 |
title => "Current by IPMI", |
| 114 |
vlabel => "A", |
| 115 |
graph_args => "--base 1000 -l 0", |
| 116 |
}, |
| 117 |
voltage => {
|
| 118 |
inputs => [], |
| 119 |
title => "Voltages by IPMI", |
| 120 |
vlabel => "Volt", |
| 121 |
graph_args => "--base 1000 --logarithmic", |
| 122 |
}, |
| 123 |
); |
| 124 |
|
| 125 |
my @data = split(/\n/, $output); |
| 126 |
foreach my $line (@data) {
|
| 127 |
my @dataline = split(/,/, $line); |
| 128 |
|
| 129 |
# skip values that are not useful |
| 130 |
next if $dataline[3] eq "N/A"; |
| 131 |
|
| 132 |
my %sensor = ( |
| 133 |
graphid => "ipmi" . $dataline[0], |
| 134 |
value => $dataline[3], |
| 135 |
label => $dataline[1] |
| 136 |
); |
| 137 |
$sensor{lwarn} = (defined($dataline[7]) and $dataline[7] ne "N/A") ? $dataline[7] : '';
|
| 138 |
$sensor{hwarn} = (defined($dataline[8]) and $dataline[8] ne "N/A") ? $dataline[8] : '';
|
| 139 |
|
| 140 |
$sensor{lcrit} = (defined($dataline[6]) and $dataline[6] ne "N/A") ? $dataline[6] : '';
|
| 141 |
$sensor{hcrit} = (defined($dataline[9]) and $dataline[9] ne "N/A") ? $dataline[9] : '';
|
| 142 |
|
| 143 |
my $type; |
| 144 |
if ( $dataline[2] eq "Temperature" ) {
|
| 145 |
$type = "temp"; |
| 146 |
} elsif ( $dataline[2] eq "Fan" ) {
|
| 147 |
$type = "fan" |
| 148 |
} elsif ( $dataline[2] eq "Current" and $dataline[4] eq "W" ) {
|
| 149 |
$type = "power"; |
| 150 |
} elsif ( $dataline[2] eq "Current" and $dataline[4] eq "A" ) {
|
| 151 |
$type = "current"; |
| 152 |
} elsif ( $dataline[2] eq "Voltage" ) {
|
| 153 |
$type = "voltage"; |
| 154 |
} |
| 155 |
|
| 156 |
push(@{$sensors{$type}->{inputs}}, \%sensor);
|
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
if ( defined $ARGV[0] and $ARGV[0] eq 'config' ) {
|
| 161 |
foreach my $type (keys %sensors) {
|
| 162 |
# don't print anything if no value is found |
| 163 |
next if scalar(@{$sensors{$type}->{inputs}}) == 0;
|
| 164 |
|
| 165 |
print "host_name $hostname" if defined($hostname); |
| 166 |
|
| 167 |
print <<END; |
| 168 |
|
| 169 |
multigraph freeipmi_$type |
| 170 |
graph_title $sensors{$type}->{title}
|
| 171 |
graph_vlabel $sensors{$type}->{vlabel}
|
| 172 |
graph_args $sensors{$type}->{graph_args}
|
| 173 |
graph_category sensors |
| 174 |
END |
| 175 |
|
| 176 |
foreach my $sensor (@{$sensors{$type}->{inputs}}) {
|
| 177 |
print "$sensor->{graphid}.label $sensor->{label}\n";
|
| 178 |
|
| 179 |
print "$sensor->{graphid}.warning $sensor->{lwarn}:$sensor->{hwarn}\n"
|
| 180 |
unless $sensor->{lwarn} eq '' and $sensor->{hwarn} eq '';
|
| 181 |
print "$sensor->{graphid}.critical $sensor->{lcrit}:$sensor->{hcrit}\n"
|
| 182 |
unless $sensor->{lcrit} eq '' and $sensor->{hcrit} eq '';
|
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
unless ( ($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1 ) {
|
| 187 |
exit 0; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
foreach my $type (keys %sensors) {
|
| 192 |
# don't print anything if no value is found |
| 193 |
next if scalar(@{$sensors{$type}->{inputs}}) == 0;
|
| 194 |
|
| 195 |
print "multigraph freeipmi_$type\n"; |
| 196 |
|
| 197 |
foreach my $sensor (@{$sensors{$type}->{inputs}}) {
|
| 198 |
print "$sensor->{graphid}.value $sensor->{value}\n";
|
| 199 |
} |
| 200 |
} |
