-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnutups_.sh
227 lines (215 loc) · 5.92 KB
/
nutups_.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
# -*- sh -*-
#
# Plugin to monitor various statistics exported by a UPS.
#
# Written by Andras Korn in 2005. Licensed under the GPL.
#
# usage: ups_upsid_function
#
# env.upsc <command> (default: "/bin/upsc")
# env.upsconf <filename> (default: "/etc/nut/ups.conf")
#
#%# family=contrib
#%# capabilities=autoconf suggest
UPS=$(basename $0 | cut -d_ -f2)
FUNCTION=$(basename $0 | cut -d_ -f3)
UPSC=${upsc:-/usr/local/bin/upsc}
UPSCONF=${upsconf:-/usr/local/etc/nut/ups.conf}
if [ "$1" = "autoconf" ]; then
[ -x $UPSC ] && [ -r $UPSCONF ] && echo yes && exit 0
echo "no ($UPSC or $UPSCONF not found)"
exit 0
fi
if [ "$1" = "suggest" ]; then
grep '^\[[^]]*\]$' $UPSCONF \
| tr -d '][' \
| while read ups; do
for i in voltages freq charge current; do
echo ${ups}_${i}
done
done
fi
info() {
$UPSC $UPS | sed -n '/device.mfr/{s/.*: //;p;}
/device.model/{s/.*: / /;p;}
' | tr -d '\n'
}
voltages() {
if [ "$1" = "config" ]; then
echo -n "graph_title "
info
echo " voltages"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel Volt"
echo "input.label Input"
echo "input.type GAUGE"
echo "input.max 260"
echo "input.min 210"
echo "output.label Output"
echo "output.type GAUGE"
echo "output.max 260"
echo "output.min 210"
echo "nominal.label Nominal"
echo "nominal.type GAUGE"
echo "nominal.max 260"
echo "nominal.min 210"
else
$UPSC $UPS | sed -n '/output.voltage.nominal/{s/.*:/nominal.value/;p;}
/output.voltage:/{s/.*:/output.value/;p;}
/input.voltage:/{s/.*:/input.value/;p;}
'
fi
}
battery() {
if [ "$1" = "config" ]; then
echo -n "graph_title "
info
echo " battery"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel %"
echo "charge.label Charge"
echo "charge.type GAUGE"
echo "charge.max 100"
echo "charge.min 0"
echo "voltage.label Voltage"
echo "voltage.type GAUGE"
echo "voltage.max 100"
echo "voltage.min 0"
echo "nominal.label Nominal"
echo "nominal.type GAUGE"
echo "nominal.max 100"
echo "nominal.min 0"
else
$UPSC $UPS | sed -n '/battery.voltage.nominal/{s/.*:/nominal.value/;p;}
/battery.voltage:/{s/.*:/voltage.value/;p;}
/battery.charge:/{s/.*:/charge.value/;p;}
'
fi
}
frequency() {
if [ "$1" = "config" ]; then
echo -n "graph_title "
info
echo " frequency"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel frequency 1/s"
echo "freq.label AC frequency"
echo "freq.type GAUGE"
echo "freq.max 60"
echo "freq.min 40"
else
$UPSC $UPS | sed -n '/input.frequency:/{s/.*:/freq.value/;p;}
'
fi
}
current() {
if [ "$1" = "config" ]; then
echo -n "graph_title "
info
echo " current"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel Amper"
echo "input.label Input current"
echo "input.type GAUGE"
echo "input.max 16"
echo "input.min 0"
echo "output.label Output current"
echo "output.type GAUGE"
echo "output.max 16"
echo "output.min 0"
echo "pf.label Power Factor"
echo "pf.type GAUGE"
echo "pf.max 1"
echo "pf.min 0"
else
$UPSC $UPS | sed -n '/input.current/{s/.*:/input.value/;p;}
/output.current/{s/.*:/output.value/;p;}
/output.powerfactor/{s/.*:/pf.value/;p;}
'
fi
}
time() {
if [ "$1" = "config" ]; then
echo -n "graph_title "
info
echo " runtime"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel seconds"
echo "runtime.label IN"
echo "runtime.type GAUGE"
echo "runtime.max 10800"
echo "runtime.min 0"
else
$UPSC $UPS | sed -n '/battery.runtime/{s/.*:/runtime.value/;p;}
'
fi
}
power() {
if [ "$1" = "config" ]; then
echo -n "graph_title "
info
echo " power usage"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel Watt / VoltAmpere"
echo "power.label Power VA"
echo "power.type GAUGE"
echo -n "power.max "
$UPSC $UPS | sed -n '/ups.power.nominal/{s/.*: //;p;}'
echo "power.min 0"
echo "realpower.label Power W"
echo "realpower.type GAUGE"
echo -n "realpower.max "
$UPSC $UPS | sed -n '/ups.realpower.nominal/{s/.*: //;p;}'
echo "realpower.min 0"
else
$UPSC $UPS | sed -n '/ups.power:/{s/.*:/power.value/;p;}
/ups.realpower:/{s/.*:/realpower.value/;p;}
'
fi
}
load() {
if [ "$1" = "config" ]; then
echo -n "graph_title "
info
echo " load"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel %"
echo "load.label Load"
echo "load.type GAUGE"
echo "load.max 100"
echo "load.min 0"
echo "efficiency.label Efficiency"
echo "efficiency.type GAUGE"
echo "efficiency.max 100"
echo "efficiency.min 0"
else
$UPSC $UPS | sed -n '/ups.load:/{s/.*:/load.value/;p;}
/ups.efficiency/{s/.*:/efficiency.value/;p;}
'
fi
}
[ "$1" = "config" ] && echo "graph_category sensors"
case "$FUNCTION" in
voltages)
voltages $1
;;
battery)
battery $1
;;
freq)
frequency $1
;;
current)
current $1
;;
power)
power $1
;;
time)
time $1
;;
load)
load $1
;;
esac