IpmiConfig: ipmi_

File ipmi_, 3.5 kB (added by maxence, 2 years ago)

IPMI Plugin for munin

Line 
1#!/bin/bash
2# -*- sh -*-
3
4: << =cut
5
6=head1 NAME
7
8ipmi_ - Plugin to monitor temperature or fan speed using IPMI
9
10=head1 CONFIGURATION
11Define IPMI lan user & password on /etc/munin/plugin-conf.d/munin as bash variable :
12IPMI_USER=xxxx
13IPMI_PASS=yyy
14=head2 ENVIRONMENT VARIABLES
15
16This plugin does not use environment variables
17
18=head2 WILDCARD PLUGIN
19
20This plugin should be linked as ipmi_temp or ipmi_fans, and will show
21either temperatures or fan speeds based on its link name.
22
23=head1 NOTE
24
25WARNING: Munin has a 10 second default timeout on plugins.  On some
26hosts ipmitool takes longer than that to probe all your hardware.  In
27this case this plugin us unusable.
28
29=head1 AUTHOR
30
31Nicolai Langfeldt <janl@linpro.no>
32
33=head1 LICENSE
34
35Based on ipmi_ munin plugin
36Donated to the public domain by Nicolai Langfeldt (janl@linpro.no)
37Adapted by Maxence Dunnewind <maxence@dunnewind.net>
38
39=head1 MAGIC MARKERS
40
41 #%# family=auto
42 #%# capabilities=autoconf suggest
43
44=cut
45
46#### Parse commandline to determine what the job is
47CONFIG_FILE=/etc/munin/plugin-conf.d/ipmi
48IPMI_USER=
49IPMI_PASS=
50
51if [ -f /etc/munin/plugin-conf.d/ipmi ];then
52    IPMI_USER=$(grep ipmi_user /etc/munin/plugin-conf.d/ipmi|awk '{ print $2 }')
53    IPMI_PASS=$(grep ipmi_pass /etc/munin/plugin-conf.d/ipmi|awk '{ print $2 }')
54fi
55
56CONFIG=no
57case $1 in
58    autoconf)
59        ! test -x /usr/bin/ipmitool &&
60          echo 'no (no /usr/bin/ipmitool)' && exit 0
61        echo yes
62        exit 0
63        ;;
64    suggest) echo fans
65             echo temp
66             exit 0;;
67    config)  CONFIG=config;;
68esac
69
70case $0 in
71    *_temp*) MEASURE=temp;;
72    *_fans*) MEASURE=fans;;
73    *) echo Please invoke as ipmi_temp or ipmi_fans >&2
74       exit 1;;
75esac
76
77HOST_ADR=$(echo $0|sed 's/^.*\(temp\|fans\)_//;s/_/\./g')
78HOST_ADR_=$(echo $0|sed 's/^.*\(temp\|fans\)_//')
79export CONFIG MEASURE
80
81#### Work is done in this awk script
82if [ "config" = "$CONFIG" ];then
83echo "host_name $HOST_ADR"
84fi
85ipmitool -l $IPMI_USER -H $HOST_ADR -I lan  -P "$IPMI_PASS" sensor | gawk -F'|' '
86BEGIN {
87    FANS = "";
88    TEMPS = "";
89    CFANS = "graph_title '$HOST_ADR' fan speeds \ngraph_vlabel RPM\ngraph_category Sensors\n";
90    CTEMPS = "graph_title '$HOST_ADR' temperature\ngraph_vlabel Degrees celcius\ngraph_category Sensors\n";
91}
92
93# Remove extraneous spaces to make output prettyer
94{ gsub(/\t/," "); gsub(/ +/," "); gsub(/ +\|/,"|"); gsub(/\| +/,"|") }
95
96# Skip lines with 0x0 in first column
97/^[^|]+\|0x0\|/ { next; };
98
99# Skip lines with na in first column
100/^[^|]+\|na\|/ { next; };
101
102# Parse temperatures
103/degrees C/ {
104        NAME=THING=$1;
105        gsub(/[^A-Za-z0-9]/,"",NAME);
106        TEMP=$2;
107
108        # Find unique name
109        while (NAMES[NAME] >= 1) {
110            NAME=sprintf("%si",NAME);
111        }
112        NAMES[NAME]=1;
113
114        WARN=$8;
115        CRIT=$9;
116
117        TEMPS = sprintf("%s%s.value %s\n",TEMPS,NAME,TEMP);
118        CTEMPS = sprintf("%s%s.label %s\n",CTEMPS,NAME,THING);
119
120        if (CRIT !~ /na/) {
121                CTEMPS = sprintf("%s%s.critical 0:%s\n",CTEMPS,NAME,CRIT);
122        }
123
124        if (WARN !~ /na/) {
125                CTEMPS = sprintf("%s%s.warning 0:%s\n",CTEMPS,NAME,WARN);
126        }
127}
128
129/RPM/ {
130        NAME=THING=$1;
131        gsub(/[^A-Za-z0-9]/,"",NAME);
132        SPEED=$2;
133
134        # Find unique name
135        while (NAMES[NAME] >= 1) {
136            NAME=sprintf("%si",NAME);
137        }
138        NAMES[NAME]=1;
139
140        FANS = sprintf("%s%s.value %s\n",FANS,NAME,SPEED);
141        CFANS = sprintf("%s%s.label %s\n",CFANS,NAME,THING);
142
143        OK=$4;
144
145        MIN=$6;
146        if (MIN !~ /na/) {
147                CFANS = sprintf("%s%s.warning %s:\n",CFANS,NAME,MIN);
148        }
149}
150
151END {
152    if (ENVIRON["MEASURE"] == "temp") {
153        VALUE=TEMPS;
154        CONFIG=CTEMPS;
155    } else {
156        VALUE=FANS;
157        CONFIG=CFANS;
158    }
159    if (ENVIRON["CONFIG"] == "config")
160        printf "%s",CONFIG;
161    else
162        printf "%s",VALUE;
163}
164'