Projet

Général

Profil

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

root / plugins / ipmi / freeipmi_ @ 4e3ef5b9

Historique | Voir | Annoter | Télécharger (4,11 ko)

1
#!/bin/sh
2
# -*- sh -*-
3

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
freeipmi_ - Plugin to monitor temperature or fan speed using FreeIPMI
9

    
10
=head1 CONFIGURATION
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
You can monitor either the current system (via /dev/ipmi0 and the
20
like) or a remote system (via the LAN protocols), and for each of the
21
two options you can select your sensors:
22

    
23
 - fans;
24
 - temp;
25
 - power;
26
 - current;
27
 - voltage.
28

    
29
When used for the local host, the plugin should be linked as, e.g.,
30
'ipmi_temp', whereas when used to monitor a foreign host it should be,
31
e.g., 'ipmi_192.168.0.253_temp'.
32

    
33
=head1 NOTE
34

    
35
=head1 AUTHOR
36

    
37
Rewritten by Diego Elio Pettenò <flameeyes@flameeyes.eu>.
38
Based on the work of Nicolai Langfeldt <janl@linpro.no>, Logilab and
39
Peter Palfrader.
40

    
41
=head1 LICENSE
42

    
43
GPLv2
44

    
45
=head1 MAGIC MARKERS
46

    
47
 #%# family=auto
48
 #%# capabilities=autoconf suggest
49

    
50
=cut
51

    
52
#### Parse commandline to determine what the job is
53

    
54
_ipmisensors() {
55
    params="--quiet-cache --comma-separated-output --no-header-output --ignore-not-available-sensors"
56
    if [ "x${hostname}" != "x" ]; then
57
	params="${params} --hostname=${hostname}"
58
	[ "x${IPMI_USERNAME}" != "x" ] && params="${params} --username=${IPMI_USERNAME}"
59
	[ "x${IPMI_PASSWORD}" != "x" ] && params="${params} --password=${IPMI_PASSWORD}"
60
    fi
61

    
62
    if ! ipmi-sensors ${params} --output-sensor-thresholds "$@"; then
63
	ipmi-sensors ${params} "$@"
64
    fi
65
}
66

    
67
# extract and eventual hostname out of the called name; we
68
# have to check whether it's set to "u" as that's what happens
69
# when the compatibility with ipmi_sensor_ is used.
70
hostname1=${0#*_}
71
hostname=${hostname1%%_*}
72
if [ "x${hostname}" = "xu" -o "x${hostname}" = "x${hostname1}" ]; then
73
    hostname=""
74
fi
75

    
76
case $0 in
77
    *_temp|*_u_degrees_c)
78
	title="Temperatures"
79
	vlabel="degrees Celsius"
80
	type=Temperature
81
	unit=C
82
	;;
83
    *_fans|*_u_rpm)
84
	title="Fan speeds"
85
	vlabel="Rotations per Minute (RPM)"
86
	type=Fan
87
	unit=RPM
88
	;;
89
    *_power|*_u_watts)
90
	title="Power consumption"
91
	vlabel="Watts"
92
	type=Current
93
	unit=W
94
	;;
95
    *_current|*_u_amps)
96
	title="Current drain"
97
	vlabel="Amperes"
98
	type=Current
99
	unit=A
100
	;;
101
    *_voltage|*_u_volts)
102
	title="Voltages"
103
	vlabel="Volts"
104
	type=Voltage
105
	unit=V
106
	;;
107
    *)
108
	if [ x"$1" != x"autoconf" -a x"$1" != x"suggest" ]; then
109
	    echo "Please invoke as one of the supported sensors types:" >&2
110
	    echo freeipmi_{temp,fans,power,current} >&2
111
	    exit 1
112
	fi
113
esac
114

    
115
case $1 in
116
    autoconf)
117
	if ! command -v ipmi-sensors >/dev/null 2>&1 ; then
118
	    echo 'no (missing ipmi-sensors command)'
119
	    exit 0
120
	fi
121

    
122
	if ! _ipmisensors -t OS_Boot >/dev/null 2>&1 ; then
123
	    echo 'no (unable to access IPMI device)'
124
	    exit 0
125
	fi
126

    
127
	echo yes
128
	exit 0
129
	;;
130
    suggest)
131
	_ipmisensors | awk -F, '
132
$3 == "Temperature" { print "temp"; }
133
$3 == "Fan" { print "fans"; }
134
$3 == "Current" && $5 == "W" { print "power"; }
135
$3 == "Current" && $5 == "A" { print "current"; }
136
$3 == "Voltage" { print "voltage"; }
137
'
138
	exit 0;;
139
    config)
140
	cat - <<EOF
141
graph_title ${title} based on IPMI sensors
142
graph_vlabel ${vlabel}
143
graph_category Sensors
144
EOF
145

    
146
	if [ "x${hostname}" != "x" ]; then
147
	    echo "host_name ${hostname}"
148
	fi
149
	;;
150
esac
151

    
152
_ipmisensors -t ${type} | awk -F, -v CONFIG=$1 -v UNIT=$unit '
153
$5 == UNIT {
154
    if ( CONFIG != "config" ) {
155
      printf("ipmi%s.value %s\n", $1, $4);
156
    } else {
157
      printf("ipmi%s.label %s\n", $1, $2);
158

    
159
      # This can only happen if FreeIPMI is new enough
160
      if ( NF == 12 ) {
161
        if ( $8 != "N/A" && $10 != "N/A" )
162
          printf("ipmi%s.warning %s:%s\n", $1, $8, $10);
163
        else if ( $8 == "N/A" && $10 != "N/A" )
164
          printf("ipmi%s.warning :%s\n", $1, $10);
165
        else if ( $8 != "N/A" && $10 == "N/A" )
166
          printf("ipmi%s.warning %s:\n", $1, $8);
167

    
168
        if ( $7 != "N/A" && $11 != "N/A" )
169
          printf("ipmi%s.critical %s:%s\n", $1, $7, $11);
170
        else if ( $7 == "N/A" && $11 != "N/A" )
171
          printf("ipmi%s.critical :%s\n", $1, $11);
172
        else if ( $7 != "N/A" && $11 == "N/A" )
173
          printf("ipmi%s.critical %s:\n", $1, $7);
174
      }
175
  }
176
}
177
'
178

    
179
# vim: syntax=sh ts=4 et