| 1 | #!/bin/bash |
|---|
| 2 | # -*- sh -*- |
|---|
| 3 | |
|---|
| 4 | : << =cut |
|---|
| 5 | |
|---|
| 6 | =head1 NAME |
|---|
| 7 | |
|---|
| 8 | ipmi_ - Plugin to monitor temperature or fan speed using IPMI |
|---|
| 9 | |
|---|
| 10 | =head1 CONFIGURATION |
|---|
| 11 | Define IPMI lan user & password on /etc/munin/plugin-conf.d/munin as bash variable : |
|---|
| 12 | IPMI_USER=xxxx |
|---|
| 13 | IPMI_PASS=yyy |
|---|
| 14 | =head2 ENVIRONMENT VARIABLES |
|---|
| 15 | |
|---|
| 16 | This plugin does not use environment variables |
|---|
| 17 | |
|---|
| 18 | =head2 WILDCARD PLUGIN |
|---|
| 19 | |
|---|
| 20 | This plugin should be linked as ipmi_temp or ipmi_fans, and will show |
|---|
| 21 | either temperatures or fan speeds based on its link name. |
|---|
| 22 | |
|---|
| 23 | =head1 NOTE |
|---|
| 24 | |
|---|
| 25 | WARNING: Munin has a 10 second default timeout on plugins. On some |
|---|
| 26 | hosts ipmitool takes longer than that to probe all your hardware. In |
|---|
| 27 | this case this plugin us unusable. |
|---|
| 28 | |
|---|
| 29 | =head1 AUTHOR |
|---|
| 30 | |
|---|
| 31 | Nicolai Langfeldt <janl@linpro.no> |
|---|
| 32 | |
|---|
| 33 | =head1 LICENSE |
|---|
| 34 | |
|---|
| 35 | Based on ipmi_ munin plugin |
|---|
| 36 | Donated to the public domain by Nicolai Langfeldt (janl@linpro.no) |
|---|
| 37 | Adapted 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 |
|---|
| 47 | CONFIG_FILE=/etc/munin/plugin-conf.d/ipmi |
|---|
| 48 | IPMI_USER= |
|---|
| 49 | IPMI_PASS= |
|---|
| 50 | |
|---|
| 51 | if [ -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 }') |
|---|
| 54 | fi |
|---|
| 55 | |
|---|
| 56 | CONFIG=no |
|---|
| 57 | case $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;; |
|---|
| 68 | esac |
|---|
| 69 | |
|---|
| 70 | case $0 in |
|---|
| 71 | *_temp*) MEASURE=temp;; |
|---|
| 72 | *_fans*) MEASURE=fans;; |
|---|
| 73 | *) echo Please invoke as ipmi_temp or ipmi_fans >&2 |
|---|
| 74 | exit 1;; |
|---|
| 75 | esac |
|---|
| 76 | |
|---|
| 77 | HOST_ADR=$(echo $0|sed 's/^.*\(temp\|fans\)_//;s/_/\./g') |
|---|
| 78 | HOST_ADR_=$(echo $0|sed 's/^.*\(temp\|fans\)_//') |
|---|
| 79 | export CONFIG MEASURE |
|---|
| 80 | |
|---|
| 81 | #### Work is done in this awk script |
|---|
| 82 | if [ "config" = "$CONFIG" ];then |
|---|
| 83 | echo "host_name $HOST_ADR" |
|---|
| 84 | fi |
|---|
| 85 | ipmitool -l $IPMI_USER -H $HOST_ADR -I lan -P "$IPMI_PASS" sensor | gawk -F'|' ' |
|---|
| 86 | BEGIN { |
|---|
| 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 | |
|---|
| 151 | END { |
|---|
| 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 | ' |
|---|