Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / sensors / freeipmi @ 548a2b62

Historique | Voir | Annoter | Télécharger (4,94 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

    
9
=head2 ENVIRONMENT VARIABLES
10

    
11
When used to monitor a foreign host, this plugins use the variables
12
IPMI_USERNAME and IPMI_PASSWORD to log in on the remote system.
13

    
14
=head2 WILDCARD PLUGIN
15

    
16
When used for the local host, the plugin should be linked as
17
non-wildcard plugin, i.e., 'freeipmi', whereas when used to monitor a
18
foreign host it should be, e.g., 'freeipmi_192.168.0.253'.
19

    
20
=head1 DEPENDENCIES
21

    
22
The plugin requires FreeIPMI 1.1.5 or later to fetch the information.
23
Limits set on thresholds are available when using FreeIPMI 1.2.0 or
24
later.
25

    
26
=head1 AUTHOR
27

    
28
Diego Elio Pettenò <flameeyes@flameeyes.eu>.
29

    
30
With help and suggestions of:
31

    
32
Bart ten Brinke <info@retrosync.com>
33

    
34
=head1 LICENSE
35

    
36
GPLv2
37

    
38
=head1 MAGIC MARKERS
39

    
40
 #%# family=auto
41
 #%# capabilities=autoconf
42

    
43
=head1 LICENSE
44

    
45
GPLv2
46

    
47
=head1 MAGIC MARKERS
48

    
49
 #%# family=auto
50
 #%# capabilities=autoconf
51

    
52
=cut
53

    
54
use strict;
55
use Munin::Plugin;
56

    
57
$ENV{'LANG'} = "C"; # Force parsable output from sensors.
58
$ENV{'LC_ALL'} = "C"; # Force parsable output from sensors.
59
my $IPMISENSORS = $ENV{'ipmisensors'} || 'ipmi-sensors';
60

    
61
$0 =~ /freeipmi(?:_(.+))$/;
62
my $hostname = $1;
63

    
64
my $help_output = `$IPMISENSORS --help`;
65

    
66
$IPMISENSORS .= " --output-sensor-thresholds" if $help_output =~ /--output-sensor-thresholds/;
67
$IPMISENSORS .= " --quiet-cache --comma-separated-output --no-header-output --ignore-not-available-sensors --sensor-types=Temperature,Fan,Current,Voltage";
68
$IPMISENSORS .= " --hostname=$hostname" if defined($hostname);
69
$IPMISENSORS .= " --username=$ENV{IPMI_USERNAME}" if defined($ENV{IPMI_USERNAME});
70
$IPMISENSORS .= " --password=$ENV{IPMI_PASSWORD}" if defined($ENV{IPMI_PASSWORD});
71

    
72
my $output=`$IPMISENSORS 2>/dev/null`;
73
my $retval=$?;
74

    
75
if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
76
  if ($retval >= 1) {
77
    print "no (ipmi-sensors died)\n";
78
  } elsif ($retval == -1) {
79
    print "no (ipmi-sensors not found)\n";
80
  } elsif ($output eq "\n") {
81
    print "no (no compatible sensors)\n";
82
  } else {
83
    print "yes\n";
84
  }
85

    
86
  exit 0;
87
}
88

    
89
my %sensors = (
90
	       temp => {
91
			inputs => [],
92
			title => "Temperatures by IPMI",
93
			vlabel => "Degrees Celsius",
94
			graph_args => "--base 1000 -l 0",
95
		       },
96
	       fan => {
97
		       inputs => [],
98
		       title => "Fans speed by IPMI",
99
		       vlabel => "RPM",
100
		       graph_args => "--base 1000 -l 0",
101
		      },
102
	       power => {
103
			 inputs => [],
104
			 title => "Power by IPMI",
105
			 vlabel => "W",
106
			 graph_args => "--base 1000 -l 0",
107
			},
108
	       current => {
109
			 inputs => [],
110
			 title => "Current by IPMI",
111
			 vlabel => "A",
112
			 graph_args => "--base 1000 -l 0",
113
			},
114
	       voltage => {
115
			   inputs => [],
116
			   title => "Voltages by IPMI",
117
			   vlabel => "Volt",
118
			   graph_args => "--base 1000 --logarithmic",
119
			  },
120
	      );
121

    
122
my @data = split(/\n/, $output);
123
foreach my $line (@data) {
124
  my @dataline = split(/,/, $line);
125

    
126
  # skip values that are not useful
127
  next if $dataline[3] eq "N/A";
128

    
129
  my %sensor = (
130
		graphid => "ipmi" . $dataline[0],
131
		value => $dataline[3],
132
		label => $dataline[1]
133
	       );
134
  $sensor{lwarn} = $dataline[7] ne "N/A" ? $dataline[7] : '';
135
  $sensor{hwarn} = $dataline[8] ne "N/A" ? $dataline[8] : '';
136

    
137
  $sensor{lcrit} = $dataline[6] ne "N/A" ? $dataline[6] : '';
138
  $sensor{hcrit} = $dataline[9] ne "N/A" ? $dataline[9] : '';
139

    
140
  my $type;
141
  if ( $dataline[2] eq "Temperature" ) {
142
    $type = "temp";
143
  } elsif ( $dataline[2] eq "Fan" ) {
144
    $type = "fan"
145
  } elsif ( $dataline[2] eq "Current" and $dataline[4] eq "W" ) {
146
    $type = "power";
147
  } elsif ( $dataline[2] eq "Current" and $dataline[4] eq "A" ) {
148
    $type = "current";
149
  } elsif ( $dataline[2] eq "Voltage" ) {
150
    $type = "voltage";
151
  }
152

    
153
  push(@{$sensors{$type}->{inputs}}, \%sensor);
154
}
155

    
156

    
157
if ( defined $ARGV[0] and $ARGV[0] eq 'config' ) {
158
  foreach my $type (keys %sensors) {
159
    # don't print anything if no value is found
160
    next if scalar(@{$sensors{$type}->{inputs}}) == 0;
161

    
162
    print "host_name $hostname" if defined($hostname);
163

    
164
    print <<END;
165

    
166
multigraph freeipmi_$type
167
graph_title $sensors{$type}->{title}
168
graph_vlabel $sensors{$type}->{vlabel}
169
graph_args $sensors{$type}->{graph_args}
170
graph_category sensors
171
END
172

    
173
    foreach my $sensor (@{$sensors{$type}->{inputs}}) {
174
      print "$sensor->{graphid}.label $sensor->{label}\n";
175

    
176
      print "$sensor->{graphid}.warning $sensor->{lwarn}:$sensor->{hwarn}\n"
177
	unless $sensor->{lwarn} eq '' and $sensor->{hwarn} eq '';
178
      print "$sensor->{graphid}.critical $sensor->{lcrit}:$sensor->{hcrit}\n"
179
	unless $sensor->{lcrit} eq '' and $sensor->{hcrit} eq '';
180
    }
181
  }
182

    
183
  unless ( ($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1 ) {
184
    exit 0;
185
  }
186
}
187

    
188
foreach my $type (keys %sensors) {
189
  # don't print anything if no value is found
190
  next if scalar(@{$sensors{$type}->{inputs}}) == 0;
191

    
192
  print "multigraph freeipmi_$type\n";
193

    
194
  foreach my $sensor (@{$sensors{$type}->{inputs}}) {
195
    print "$sensor->{graphid}.value $sensor->{value}\n";
196
  }
197
}