3 # a space separated list of UPS names
4 # if empty, the list returned by 'upsc -l' will be used
7 # how frequently to collect UPS data
12 # the priority of nut related to other charts
18 timeout $nut_timeout upsc -l
22 timeout $nut_timeout upsc "$1"
28 # - 0 to enable the chart
29 # - 1 to disable the chart
33 require_cmd upsc || return 1
35 [ -z "$nut_ups" ] && nut_ups="$( nut_get_all )"
39 nut_get "$x" >/dev/null
42 nut_ids[$x]="$( fixid "$x" )"
45 echo >&2 "nut: ERROR: Cannot get information for NUT UPS '$x'."
48 if [ ${#nut_ids[@]} -eq 0 ]
50 echo >&2 "nut: Please set nut_ups='ups_name' in $confd/nut.conf"
61 for x in "${nut_ids[@]}"
64 CHART nut_$x.charge '' "UPS Charge" "percentage" ups nut.charge area $((nut_priority + 1)) $nut_update_every
65 DIMENSION battery_charge charge absolute 1 100
67 CHART nut_$x.battery_voltage '' "UPS Battery Voltage" "Volts" ups nut.battery.voltage line $((nut_priority + 2)) $nut_update_every
68 DIMENSION battery_voltage voltage absolute 1 100
69 DIMENSION battery_voltage_high high absolute 1 100
70 DIMENSION battery_voltage_low low absolute 1 100
71 DIMENSION battery_voltage_nominal nominal absolute 1 100
73 CHART nut_$x.input_voltage '' "UPS Input Voltage" "Volts" input nut.input.voltage line $((nut_priority + 3)) $nut_update_every
74 DIMENSION input_voltage voltage absolute 1 100
75 DIMENSION input_voltage_fault fault absolute 1 100
76 DIMENSION input_voltage_nominal nominal absolute 1 100
78 CHART nut_$x.input_current '' "UPS Input Current" "Ampere" input nut.input.current line $((nut_priority + 4)) $nut_update_every
79 DIMENSION input_current_nominal nominal absolute 1 100
81 CHART nut_$x.input_frequency '' "UPS Input Frequency" "Hz" input nut.input.frequency line $((nut_priority + 5)) $nut_update_every
82 DIMENSION input_frequency frequency absolute 1 100
83 DIMENSION input_frequency_nominal nominal absolute 1 100
85 CHART nut_$x.output_voltage '' "UPS Output Voltage" "Volts" output nut.output.voltage line $((nut_priority + 6)) $nut_update_every
86 DIMENSION output_voltage voltage absolute 1 100
88 CHART nut_$x.load '' "UPS Load" "percentage" ups nut.load area $((nut_priority)) $nut_update_every
89 DIMENSION load load absolute 1 100
91 CHART nut_$x.temp '' "UPS Temperature" "temperature" ups nut.temperature line $((nut_priority + 7)) $nut_update_every
92 DIMENSION temp temp absolute 1 100
101 # the first argument to this function is the microseconds since last update
102 # pass this parameter to the BEGIN statement (see bellow).
104 # do all the work to collect / calculate the values
106 # remember: KEEP IT SIMPLE AND SHORT
109 for i in "${!nut_ids[@]}"
116 battery_voltage_high = 0;
117 battery_voltage_low = 0;
118 battery_voltage_nominal = 0;
120 input_voltage_fault = 0;
121 input_voltage_nominal = 0;
122 input_current_nominal = 0;
124 input_frequency_nominal = 0;
129 /^battery.charge: .*/ { battery_charge = \$2 * 100 };
130 /^battery.voltage: .*/ { battery_voltage = \$2 * 100 };
131 /^battery.voltage.high: .*/ { battery_voltage_high = \$2 * 100 };
132 /^battery.voltage.low: .*/ { battery_voltage_low = \$2 * 100 };
133 /^battery.voltage.nominal: .*/ { battery_voltage_nominal = \$2 * 100 };
134 /^input.voltage: .*/ { input_voltage = \$2 * 100 };
135 /^input.voltage.fault: .*/ { input_voltage_fault = \$2 * 100 };
136 /^input.voltage.nominal: .*/ { input_voltage_nominal = \$2 * 100 };
137 /^input.current.nominal: .*/ { input_current_nominal = \$2 * 100 };
138 /^input.frequency: .*/ { input_frequency = \$2 * 100 };
139 /^input.frequency.nominal: .*/ { input_frequency_nominal = \$2 * 100 };
140 /^output.voltage: .*/ { output_voltage = \$2 * 100 };
141 /^ups.load: .*/ { load = \$2 * 100 };
142 /^ups.temperature: .*/ { temp = \$2 * 100 };
144 print \"BEGIN nut_$x.charge $1\";
145 print \"SET battery_charge = \" battery_charge;
148 print \"BEGIN nut_$x.battery_voltage $1\";
149 print \"SET battery_voltage = \" battery_voltage;
150 print \"SET battery_voltage_high = \" battery_voltage_high;
151 print \"SET battery_voltage_low = \" battery_voltage_low;
152 print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
155 print \"BEGIN nut_$x.input_voltage $1\";
156 print \"SET input_voltage = \" input_voltage;
157 print \"SET input_voltage_fault = \" input_voltage_fault;
158 print \"SET input_voltage_nominal = \" input_voltage_nominal;
161 print \"BEGIN nut_$x.input_current $1\";
162 print \"SET input_current_nominal = \" input_current_nominal;
165 print \"BEGIN nut_$x.input_frequency $1\";
166 print \"SET input_frequency = \" input_frequency;
167 print \"SET input_frequency_nominal = \" input_frequency_nominal;
170 print \"BEGIN nut_$x.output_voltage $1\";
171 print \"SET output_voltage = \" output_voltage;
174 print \"BEGIN nut_$x.load $1\";
175 print \"SET load = \" load;
178 print \"BEGIN nut_$x.temp $1\";
179 print \"SET temp = \" temp;
182 [ $? -ne 0 ] && unset nut_ids[$i] && echo >&2 "nut: failed to get values for '$i', disabling it."
185 [ ${#nut_ids[@]} -eq 0 ] && echo >&2 "nut: no UPSes left active." && return 1