@@ -4,56 +4,70 @@ nut_ups=
44nut_update_every=2
55
66nut_check () {
7- if [ -z " ${nut_ups} " ]
7+ local x all
8+
9+ require_cmd upsc || return 1
10+ require_cmd awk || return 1
11+
12+ all=" $nut_ups "
13+ [ -z " $all " ] && all=" $( upsc -l) "
14+
15+ nut_ups=
16+ for x in $all
17+ do
18+ upsc " $x " > /dev/null
19+ [ $? -eq 0 ] && nut_ups=" $nut_ups $x " && continue
20+ echo >&2 " nut: ERROR: Cannot get information for NUT UPS '$x '."
21+ done
22+
23+ if [ -z " $nut_ups " ]
824 then
925 echo >&2 " nut: Please set nut_ups='ups_name' in $confd /nut.conf"
1026 return 1
1127 fi
1228
13- upsc " ${nut_ups} " > /dev/null
14- if [ ! $? -eq 0 ]
15- then
16- echo >&2 " nut: failed to fetch info for ups '$nut_ups '. Please set nut_ups='ups_name' in $confd /nut.conf"
17- return 1
18- fi
19-
2029 return 0
2130}
2231
2332nut_create () {
2433 # create the charts
25- cat << EOF
26- CHART nut.charge '' "UPS Charge" "percentage" nut '' area 21001 $nut_update_every
34+ local x
35+
36+ for x in $nut_ups
37+ do
38+ cat << EOF
39+ CHART nut_$x .charge '' "UPS Charge" "percentage" $x nut area 21001 $nut_update_every
2740DIMENSION battery_charge charge absolute 1 100
2841
29- CHART nut .battery_voltage '' "UPS Battery Voltage" "Volts" nut '' line 21002 $nut_update_every
42+ CHART nut_ $x .battery_voltage '' "UPS Battery Voltage" "Volts" $x nut line 21002 $nut_update_every
3043DIMENSION battery_voltage voltage absolute 1 100
3144DIMENSION battery_voltage_high high absolute 1 100
3245DIMENSION battery_voltage_low low absolute 1 100
3346DIMENSION battery_voltage_nominal nominal absolute 1 100
3447
35- CHART nut .input_voltage '' "UPS Input Voltage" "Volts" nut '' line 21003 $nut_update_every
48+ CHART nut_ $x .input_voltage '' "UPS Input Voltage" "Volts" $x nut line 21003 $nut_update_every
3649DIMENSION input_voltage voltage absolute 1 100
3750DIMENSION input_voltage_fault fault absolute 1 100
3851DIMENSION input_voltage_nominal nominal absolute 1 100
3952
40- CHART nut .input_current '' "UPS Input Current" "Ampere" nut '' line 21004 $nut_update_every
53+ CHART nut_ $x .input_current '' "UPS Input Current" "Ampere" $x nut line 21004 $nut_update_every
4154DIMENSION input_current_nominal nominal absolute 1 100
4255
43- CHART nut .input_frequency '' "UPS Input Frequency" "Hz" nut '' line 21005 $nut_update_every
56+ CHART nut_ $x .input_frequency '' "UPS Input Frequency" "Hz" $x nut line 21005 $nut_update_every
4457DIMENSION input_frequency frequency absolute 1 100
4558DIMENSION input_frequency_nominal nominal absolute 1 100
4659
47- CHART nut .output_voltage '' "UPS Output Voltage" "Volts" nut '' line 21006 $nut_update_every
60+ CHART nut_ $x .output_voltage '' "UPS Output Voltage" "Volts" $x nut line 21006 $nut_update_every
4861DIMENSION output_voltage voltage absolute 1 100
4962
50- CHART nut .load '' "UPS Load" "percentage" nut '' area 21000 $nut_update_every
63+ CHART nut_ $x .load '' "UPS Load" "percentage" $x nut area 21000 $nut_update_every
5164DIMENSION load load absolute 1 100
5265
53- CHART nut .temp '' "UPS Temperature" "temperature" nut '' line 21007 $nut_update_every
66+ CHART nut_ $x .temp '' "UPS Temperature" "temperature" $x nut line 21007 $nut_update_every
5467DIMENSION temp temp absolute 1 100
5568EOF
56-
69+ done
70+
5771 return 0
5872}
5973
@@ -66,7 +80,11 @@ nut_update() {
6680 # for each dimension
6781 # remember: KEEP IT SIMPLE AND SHORT
6882
69- upsc " ${nut_ups} " | awk "
83+ local x
84+
85+ for x in $nut_ups
86+ do
87+ upsc " $x " | awk "
7088BEGIN {
7189 battery_charge = 0;
7290 battery_voltage = 0;
@@ -98,45 +116,47 @@ BEGIN {
98116/^ups.load: .*/ { load = \$ 2 * 100 };
99117/^ups.temperature: .*/ { temp = \$ 2 * 100 };
100118END {
101- print \" BEGIN nut .charge $1 \" ;
119+ print \" BEGIN nut_ $x .charge $1 \" ;
102120 print \" SET battery_charge = \" battery_charge;
103121 print \" END\"
104122
105- print \" BEGIN nut .battery_voltage $1 \" ;
123+ print \" BEGIN nut_ $x .battery_voltage $1 \" ;
106124 print \" SET battery_voltage = \" battery_voltage;
107125 print \" SET battery_voltage_high = \" battery_voltage_high;
108126 print \" SET battery_voltage_low = \" battery_voltage_low;
109127 print \" SET battery_voltage_nominal = \" battery_voltage_nominal;
110128 print \" END\"
111129
112- print \" BEGIN nut .input_voltage $1 \" ;
130+ print \" BEGIN nut_ $x .input_voltage $1 \" ;
113131 print \" SET input_voltage = \" input_voltage;
114132 print \" SET input_voltage_fault = \" input_voltage_fault;
115133 print \" SET input_voltage_nominal = \" input_voltage_nominal;
116134 print \" END\"
117135
118- print \" BEGIN nut .input_current $1 \" ;
136+ print \" BEGIN nut_ $x .input_current $1 \" ;
119137 print \" SET input_current_nominal = \" input_current_nominal;
120138 print \" END\"
121139
122- print \" BEGIN nut .input_frequency $1 \" ;
140+ print \" BEGIN nut_ $x .input_frequency $1 \" ;
123141 print \" SET input_frequency = \" input_frequency;
124142 print \" SET input_frequency_nominal = \" input_frequency_nominal;
125143 print \" END\"
126144
127- print \" BEGIN nut .output_voltage $1 \" ;
145+ print \" BEGIN nut_ $x .output_voltage $1 \" ;
128146 print \" SET output_voltage = \" output_voltage;
129147 print \" END\"
130148
131- print \" BEGIN nut .load $1 \" ;
149+ print \" BEGIN nut_ $x .load $1 \" ;
132150 print \" SET load = \" load;
133151 print \" END\"
134152
135- print \" BEGIN nut .temp $1 \" ;
153+ print \" BEGIN nut_ $x .temp $1 \" ;
136154 print \" SET temp = \" temp;
137155 print \" END\"
138156}
139157"
158+ done
159+
140160 return 0
141161}
142162
0 commit comments