summaryrefslogtreecommitdiffstats
path: root/plugins/check_ups.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ups.c')
-rw-r--r--plugins/check_ups.c1023
1 files changed, 552 insertions, 471 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 68737c4..380ff3b 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -1,665 +1,746 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_ups plugin 3 * Monitoring check_ups plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 2000 Tom Shields 6 * Copyright (c) 2000 Tom Shields
7* 2004 Alain Richard <alain.richard@equation.fr> 7 * 2004 Alain Richard <alain.richard@equation.fr>
8* 2004 Arnaud Quette <arnaud.quette@mgeups.com> 8 * 2004 Arnaud Quette <arnaud.quette@mgeups.com>
9* Copyright (c) 2002-2007 Monitoring Plugins Development Team 9 * Copyright (c) 2002-2023 Monitoring Plugins Development Team
10* 10 *
11* Description: 11 * Description:
12* 12 *
13* This file contains Network UPS Tools plugin for Monitoring 13 * This file contains Network UPS Tools plugin for Monitoring
14* 14 *
15* This plugin tests the UPS service on the specified host. Network UPS Tools 15 * This plugin tests the UPS service on the specified host. Network UPS Tools
16* from www.networkupstools.org must be running for this plugin to work. 16 * from www.networkupstools.org must be running for this plugin to work.
17* 17 *
18* 18 *
19* This program is free software: you can redistribute it and/or modify 19 * This program is free software: you can redistribute it and/or modify
20* it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
21* the Free Software Foundation, either version 3 of the License, or 21 * the Free Software Foundation, either version 3 of the License, or
22* (at your option) any later version. 22 * (at your option) any later version.
23* 23 *
24* This program is distributed in the hope that it will be useful, 24 * This program is distributed in the hope that it will be useful,
25* but WITHOUT ANY WARRANTY; without even the implied warranty of 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27* GNU General Public License for more details. 27 * GNU General Public License for more details.
28* 28 *
29* You should have received a copy of the GNU General Public License 29 * You should have received a copy of the GNU General Public License
30* along with this program. If not, see <http://www.gnu.org/licenses/>. 30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31* 31 *
32* 32 *
33*****************************************************************************/ 33 *****************************************************************************/
34 34
35const char *progname = "check_ups"; 35const char *progname = "check_ups";
36const char *copyright = "2000-2007"; 36const char *copyright = "2000-2023";
37const char *email = "devel@monitoring-plugins.org"; 37const char *email = "devel@monitoring-plugins.org";
38 38
39#include "common.h" 39#include "common.h"
40#include "netutils.h" 40#include "netutils.h"
41#include "utils.h" 41#include "utils.h"
42 42
43enum { 43enum { PORT = 3493 };
44 PORT = 3493 44
45}; 45#define UPS_NONE 0 /* no supported options */
46 46#define UPS_UTILITY 1 /* supports utility line */
47#define CHECK_NONE 0 47#define UPS_BATTPCT 2 /* supports percent battery remaining */
48 48#define UPS_STATUS 4 /* supports UPS status */
49#define UPS_NONE 0 /* no supported options */ 49#define UPS_TEMP 8 /* supports UPS temperature */
50#define UPS_UTILITY 1 /* supports utility line voltage */ 50#define UPS_LOADPCT 16 /* supports load percent */
51#define UPS_BATTPCT 2 /* supports percent battery remaining */ 51#define UPS_REALPOWER 32 /* supports real power */
52#define UPS_STATUS 4 /* supports UPS status */ 52
53#define UPS_TEMP 8 /* supports UPS temperature */ 53#define UPSSTATUS_NONE 0
54#define UPS_LOADPCT 16 /* supports load percent */ 54#define UPSSTATUS_OFF 1
55 55#define UPSSTATUS_OL 2
56#define UPSSTATUS_NONE 0 56#define UPSSTATUS_OB 4
57#define UPSSTATUS_OFF 1 57#define UPSSTATUS_LB 8
58#define UPSSTATUS_OL 2 58#define UPSSTATUS_CAL 16
59#define UPSSTATUS_OB 4 59#define UPSSTATUS_RB 32 /*Replace Battery */
60#define UPSSTATUS_LB 8 60#define UPSSTATUS_BYPASS 64
61#define UPSSTATUS_CAL 16 61#define UPSSTATUS_OVER 128
62#define UPSSTATUS_RB 32 /*Replace Battery */ 62#define UPSSTATUS_TRIM 256
63#define UPSSTATUS_BYPASS 64 63#define UPSSTATUS_BOOST 512
64#define UPSSTATUS_OVER 128
65#define UPSSTATUS_TRIM 256
66#define UPSSTATUS_BOOST 512
67#define UPSSTATUS_CHRG 1024 64#define UPSSTATUS_CHRG 1024
68#define UPSSTATUS_DISCHRG 2048 65#define UPSSTATUS_DISCHRG 2048
69#define UPSSTATUS_UNKNOWN 4096 66#define UPSSTATUS_UNKNOWN 4096
70 67#define UPSSTATUS_ALARM 8192
71enum { NOSUCHVAR = ERROR-1 }; 68
72 69enum { NOSUCHVAR = ERROR - 1 };
73int server_port = PORT; 70
74char *server_address; 71typedef struct ups_config {
75char *ups_name = NULL; 72 unsigned int server_port;
76double warning_value = 0.0; 73 char *server_address;
77double critical_value = 0.0; 74 char *ups_name;
78int check_warn = FALSE; 75 double warning_value;
79int check_crit = FALSE; 76 double critical_value;
80int check_variable = UPS_NONE; 77 bool check_warn;
81int supported_options = UPS_NONE; 78 bool check_crit;
82int status = UPSSTATUS_NONE; 79 int check_variable;
83 80 int status;
84double ups_utility_voltage = 0.0; 81 bool temp_output_c;
85double ups_battery_percent = 0.0; 82} ups_config;
86double ups_load_percent = 0.0; 83
87double ups_temperature = 0.0; 84ups_config ups_config_init(void) {
88char *ups_status; 85 ups_config tmp = {0};
89int temp_output_c = 0; 86 tmp.server_port = PORT;
90 87 tmp.server_address = NULL;
91int determine_status (void); 88 tmp.ups_name = NULL;
92int get_ups_variable (const char *, char *); 89 tmp.check_variable = UPS_NONE;
93 90 tmp.status = UPSSTATUS_NONE;
94int process_arguments (int, char **); 91
95int validate_arguments (void); 92 return tmp;
96void print_help (void); 93}
97void print_usage (void); 94
98 95// Forward declarations
99int 96int determine_status(ups_config *, int *supported_options);
100main (int argc, char **argv) 97int get_ups_variable(const char *, char *, const ups_config config);
101{ 98
102 int result = STATE_UNKNOWN; 99int process_arguments(int, char **, ups_config *);
103 char *message; 100int validate_arguments(ups_config);
101void print_help(void);
102void print_usage(void);
103
104int main(int argc, char **argv) {
105 setlocale(LC_ALL, "");
106 bindtextdomain(PACKAGE, LOCALEDIR);
107 textdomain(PACKAGE);
108
109 char *ups_status;
110 ups_status = strdup("N/A");
111
104 char *data; 112 char *data;
105 char *tunits; 113 data = strdup("");
106 char temp_buffer[MAX_INPUT_BUFFER];
107 double ups_utility_deviation = 0.0;
108 int res;
109 114
110 setlocale (LC_ALL, ""); 115 char *message;
111 bindtextdomain (PACKAGE, LOCALEDIR); 116 message = strdup("");
112 textdomain (PACKAGE);
113 117
114 ups_status = strdup ("N/A"); 118 // Exit result
115 data = strdup (""); 119 int result = STATE_UNKNOWN;
116 message = strdup ("");
117 120
118 /* Parse extra opts if any */ 121 /* Parse extra opts if any */
119 argv=np_extra_opts (&argc, argv, progname); 122 argv = np_extra_opts(&argc, argv, progname);
120 123
121 if (process_arguments (argc, argv) == ERROR) 124 // Config from commandline
122 usage4 (_("Could not parse arguments")); 125 ups_config config = ups_config_init();
126
127 if (process_arguments(argc, argv, &config) == ERROR) {
128 usage4(_("Could not parse arguments"));
129 }
123 130
124 /* initialize alarm signal handling */ 131 /* initialize alarm signal handling */
125 signal (SIGALRM, socket_timeout_alarm_handler); 132 signal(SIGALRM, socket_timeout_alarm_handler);
126 133
127 /* set socket timeout */ 134 /* set socket timeout */
128 alarm (socket_timeout); 135 alarm(socket_timeout);
136
137 int supported_options = UPS_NONE;
129 138
130 /* get the ups status if possible */ 139 /* get the ups status if possible */
131 if (determine_status () != OK) 140 if (determine_status(&config, &supported_options) != OK) {
132 return STATE_CRITICAL; 141 return STATE_CRITICAL;
142 }
143
144
133 if (supported_options & UPS_STATUS) { 145 if (supported_options & UPS_STATUS) {
134 146
135 ups_status = strdup (""); 147 ups_status = strdup("");
148
136 result = STATE_OK; 149 result = STATE_OK;
137 150
138 if (status & UPSSTATUS_OFF) { 151 if (config.status & UPSSTATUS_OFF) {
139 xasprintf (&ups_status, "Off"); 152 xasprintf(&ups_status, "Off");
140 result = STATE_CRITICAL; 153 result = STATE_CRITICAL;
141 } 154 } else if ((config.status & (UPSSTATUS_OB | UPSSTATUS_LB)) ==
142 else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) == 155 (UPSSTATUS_OB | UPSSTATUS_LB)) {
143 (UPSSTATUS_OB | UPSSTATUS_LB)) { 156 xasprintf(&ups_status, _("On Battery, Low Battery"));
144 xasprintf (&ups_status, _("On Battery, Low Battery"));
145 result = STATE_CRITICAL; 157 result = STATE_CRITICAL;
146 } 158 } else {
147 else { 159 if (config.status & UPSSTATUS_OL) {
148 if (status & UPSSTATUS_OL) { 160 xasprintf(&ups_status, "%s%s", ups_status, _("Online"));
149 xasprintf (&ups_status, "%s%s", ups_status, _("Online"));
150 } 161 }
151 if (status & UPSSTATUS_OB) { 162 if (config.status & UPSSTATUS_OB) {
152 xasprintf (&ups_status, "%s%s", ups_status, _("On Battery")); 163 xasprintf(&ups_status, "%s%s", ups_status, _("On Battery"));
153 result = STATE_WARNING; 164 result = max_state(result, STATE_WARNING);
154 } 165 }
155 if (status & UPSSTATUS_LB) { 166 if (config.status & UPSSTATUS_LB) {
156 xasprintf (&ups_status, "%s%s", ups_status, _(", Low Battery")); 167 xasprintf(&ups_status, "%s%s", ups_status, _(", Low Battery"));
157 result = STATE_WARNING; 168 result = max_state(result, STATE_WARNING);
158 } 169 }
159 if (status & UPSSTATUS_CAL) { 170 if (config.status & UPSSTATUS_CAL) {
160 xasprintf (&ups_status, "%s%s", ups_status, _(", Calibrating")); 171 xasprintf(&ups_status, "%s%s", ups_status, _(", Calibrating"));
161 } 172 }
162 if (status & UPSSTATUS_RB) { 173 if (config.status & UPSSTATUS_RB) {
163 xasprintf (&ups_status, "%s%s", ups_status, _(", Replace Battery")); 174 xasprintf(&ups_status, "%s%s", ups_status,
164 result = STATE_WARNING; 175 _(", Replace Battery"));
176 result = max_state(result, STATE_WARNING);
165 } 177 }
166 if (status & UPSSTATUS_BYPASS) { 178 if (config.status & UPSSTATUS_BYPASS) {
167 xasprintf (&ups_status, "%s%s", ups_status, _(", On Bypass")); 179 xasprintf(&ups_status, "%s%s", ups_status, _(", On Bypass"));
180 // Bypassing the battery is likely a bad thing
181 result = STATE_CRITICAL;
182 }
183 if (config.status & UPSSTATUS_OVER) {
184 xasprintf(&ups_status, "%s%s", ups_status, _(", Overload"));
185 result = max_state(result, STATE_WARNING);
168 } 186 }
169 if (status & UPSSTATUS_OVER) { 187 if (config.status & UPSSTATUS_TRIM) {
170 xasprintf (&ups_status, "%s%s", ups_status, _(", Overload")); 188 xasprintf(&ups_status, "%s%s", ups_status, _(", Trimming"));
171 } 189 }
172 if (status & UPSSTATUS_TRIM) { 190 if (config.status & UPSSTATUS_BOOST) {
173 xasprintf (&ups_status, "%s%s", ups_status, _(", Trimming")); 191 xasprintf(&ups_status, "%s%s", ups_status, _(", Boosting"));
174 } 192 }
175 if (status & UPSSTATUS_BOOST) { 193 if (config.status & UPSSTATUS_CHRG) {
176 xasprintf (&ups_status, "%s%s", ups_status, _(", Boosting")); 194 xasprintf(&ups_status, "%s%s", ups_status, _(", Charging"));
177 } 195 }
178 if (status & UPSSTATUS_CHRG) { 196 if (config.status & UPSSTATUS_DISCHRG) {
179 xasprintf (&ups_status, "%s%s", ups_status, _(", Charging")); 197 xasprintf(&ups_status, "%s%s", ups_status, _(", Discharging"));
198 result = max_state(result, STATE_WARNING);
180 } 199 }
181 if (status & UPSSTATUS_DISCHRG) { 200 if (config.status & UPSSTATUS_ALARM) {
182 xasprintf (&ups_status, "%s%s", ups_status, _(", Discharging")); 201 xasprintf(&ups_status, "%s%s", ups_status, _(", ALARM"));
202 result = STATE_CRITICAL;
183 } 203 }
184 if (status & UPSSTATUS_UNKNOWN) { 204 if (config.status & UPSSTATUS_UNKNOWN) {
185 xasprintf (&ups_status, "%s%s", ups_status, _(", Unknown")); 205 xasprintf(&ups_status, "%s%s", ups_status, _(", Unknown"));
186 } 206 }
187 } 207 }
188 xasprintf (&message, "%sStatus=%s ", message, ups_status); 208 xasprintf(&message, "%sStatus=%s ", message, ups_status);
189 } 209 }
190 210
211 int res;
212 char temp_buffer[MAX_INPUT_BUFFER];
213
191 /* get the ups utility voltage if possible */ 214 /* get the ups utility voltage if possible */
192 res=get_ups_variable ("input.voltage", temp_buffer); 215 res = get_ups_variable("input.voltage", temp_buffer, config);
193 if (res == NOSUCHVAR) supported_options &= ~UPS_UTILITY; 216 if (res == NOSUCHVAR) {
194 else if (res != OK) 217 supported_options &= ~UPS_UTILITY;
218 } else if (res != OK) {
195 return STATE_CRITICAL; 219 return STATE_CRITICAL;
196 else { 220 } else {
197 supported_options |= UPS_UTILITY; 221 supported_options |= UPS_UTILITY;
198 222
199 ups_utility_voltage = atof (temp_buffer); 223 double ups_utility_voltage = 0.0;
200 xasprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); 224 ups_utility_voltage = atof(temp_buffer);
225 xasprintf(&message, "%sUtility=%3.1fV ", message, ups_utility_voltage);
226
227 double ups_utility_deviation = 0.0;
201 228
202 if (ups_utility_voltage > 120.0) 229 if (ups_utility_voltage > 120.0) {
203 ups_utility_deviation = 120.0 - ups_utility_voltage; 230 ups_utility_deviation = 120.0 - ups_utility_voltage;
204 else 231 } else {
205 ups_utility_deviation = ups_utility_voltage - 120.0; 232 ups_utility_deviation = ups_utility_voltage - 120.0;
233 }
206 234
207 if (check_variable == UPS_UTILITY) { 235 if (config.check_variable == UPS_UTILITY) {
208 if (check_crit==TRUE && ups_utility_deviation>=critical_value) { 236 if (config.check_crit &&
237 ups_utility_deviation >= config.critical_value) {
209 result = STATE_CRITICAL; 238 result = STATE_CRITICAL;
239 } else if (config.check_warn &&
240 ups_utility_deviation >= config.warning_value) {
241 result = max_state(result, STATE_WARNING);
210 } 242 }
211 else if (check_warn==TRUE && ups_utility_deviation>=warning_value) { 243 xasprintf(&data, "%s",
212 result = max_state (result, STATE_WARNING); 244 perfdata("voltage", (long)(1000 * ups_utility_voltage),
213 } 245 "mV", config.check_warn,
214 xasprintf (&data, "%s", 246 (long)(1000 * config.warning_value),
215 perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", 247 config.check_crit,
216 check_warn, (long)(1000*warning_value), 248 (long)(1000 * config.critical_value), true, 0,
217 check_crit, (long)(1000*critical_value), 249 false, 0));
218 TRUE, 0, FALSE, 0));
219 } else { 250 } else {
220 xasprintf (&data, "%s", 251 xasprintf(&data, "%s",
221 perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", 252 perfdata("voltage", (long)(1000 * ups_utility_voltage),
222 FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); 253 "mV", false, 0, false, 0, true, 0, false, 0));
223 } 254 }
224 } 255 }
225 256
226 /* get the ups battery percent if possible */ 257 /* get the ups battery percent if possible */
227 res=get_ups_variable ("battery.charge", temp_buffer); 258 res = get_ups_variable("battery.charge", temp_buffer, config);
228 if (res == NOSUCHVAR) supported_options &= ~UPS_BATTPCT; 259 if (res == NOSUCHVAR) {
229 else if ( res != OK) 260 supported_options &= ~UPS_BATTPCT;
261 } else if (res != OK) {
230 return STATE_CRITICAL; 262 return STATE_CRITICAL;
231 else { 263 } else {
232 supported_options |= UPS_BATTPCT; 264 supported_options |= UPS_BATTPCT;
233 ups_battery_percent = atof (temp_buffer);
234 xasprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent);
235 265
236 if (check_variable == UPS_BATTPCT) { 266 double ups_battery_percent = 0.0;
237 if (check_crit==TRUE && ups_battery_percent <= critical_value) { 267 ups_battery_percent = atof(temp_buffer);
268 xasprintf(&message, "%sBatt=%3.1f%% ", message, ups_battery_percent);
269
270 if (config.check_variable == UPS_BATTPCT) {
271 if (config.check_crit &&
272 ups_battery_percent <= config.critical_value) {
238 result = STATE_CRITICAL; 273 result = STATE_CRITICAL;
274 } else if (config.check_warn &&
275 ups_battery_percent <= config.warning_value) {
276 result = max_state(result, STATE_WARNING);
239 } 277 }
240 else if (check_warn==TRUE && ups_battery_percent<=warning_value) { 278 xasprintf(&data, "%s %s", data,
241 result = max_state (result, STATE_WARNING); 279 perfdata("battery", (long)ups_battery_percent, "%",
242 } 280 config.check_warn, (long)(config.warning_value),
243 xasprintf (&data, "%s %s", data, 281 config.check_crit, (long)(config.critical_value),
244 perfdata ("battery", (long)ups_battery_percent, "%", 282 true, 0, true, 100));
245 check_warn, (long)(warning_value),
246 check_crit, (long)(critical_value),
247 TRUE, 0, TRUE, 100));
248 } else { 283 } else {
249 xasprintf (&data, "%s %s", data, 284 xasprintf(&data, "%s %s", data,
250 perfdata ("battery", (long)ups_battery_percent, "%", 285 perfdata("battery", (long)ups_battery_percent, "%", false,
251 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); 286 0, false, 0, true, 0, true, 100));
252 } 287 }
253 } 288 }
254 289
255 /* get the ups load percent if possible */ 290 /* get the ups load percent if possible */
256 res=get_ups_variable ("ups.load", temp_buffer); 291 res = get_ups_variable("ups.load", temp_buffer, config);
257 if ( res == NOSUCHVAR ) supported_options &= ~UPS_LOADPCT; 292 if (res == NOSUCHVAR) {
258 else if ( res != OK) 293 supported_options &= ~UPS_LOADPCT;
294 } else if (res != OK) {
259 return STATE_CRITICAL; 295 return STATE_CRITICAL;
260 else { 296 } else {
261 supported_options |= UPS_LOADPCT; 297 supported_options |= UPS_LOADPCT;
262 ups_load_percent = atof (temp_buffer);
263 xasprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent);
264 298
265 if (check_variable == UPS_LOADPCT) { 299 double ups_load_percent = 0.0;
266 if (check_crit==TRUE && ups_load_percent>=critical_value) { 300 ups_load_percent = atof(temp_buffer);
301 xasprintf(&message, "%sLoad=%3.1f%% ", message, ups_load_percent);
302
303 if (config.check_variable == UPS_LOADPCT) {
304 if (config.check_crit &&
305 ups_load_percent >= config.critical_value) {
267 result = STATE_CRITICAL; 306 result = STATE_CRITICAL;
307 } else if (config.check_warn &&
308 ups_load_percent >= config.warning_value) {
309 result = max_state(result, STATE_WARNING);
268 } 310 }
269 else if (check_warn==TRUE && ups_load_percent>=warning_value) { 311 xasprintf(&data, "%s %s", data,
270 result = max_state (result, STATE_WARNING); 312 perfdata("load", (long)ups_load_percent, "%",
271 } 313 config.check_warn, (long)(config.warning_value),
272 xasprintf (&data, "%s %s", data, 314 config.check_crit, (long)(config.critical_value),
273 perfdata ("load", (long)ups_load_percent, "%", 315 true, 0, true, 100));
274 check_warn, (long)(warning_value),
275 check_crit, (long)(critical_value),
276 TRUE, 0, TRUE, 100));
277 } else { 316 } else {
278 xasprintf (&data, "%s %s", data, 317 xasprintf(&data, "%s %s", data,
279 perfdata ("load", (long)ups_load_percent, "%", 318 perfdata("load", (long)ups_load_percent, "%", false, 0,
280 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); 319 false, 0, true, 0, true, 100));
281 } 320 }
282 } 321 }
283 322
284 /* get the ups temperature if possible */ 323 /* get the ups temperature if possible */
285 res=get_ups_variable ("ups.temperature", temp_buffer); 324 res = get_ups_variable("ups.temperature", temp_buffer, config);
286 if ( res == NOSUCHVAR ) supported_options &= ~UPS_TEMP; 325 if (res == NOSUCHVAR) {
287 else if ( res != OK) 326 supported_options &= ~UPS_TEMP;
327 } else if (res != OK) {
288 return STATE_CRITICAL; 328 return STATE_CRITICAL;
289 else { 329 } else {
290 supported_options |= UPS_TEMP; 330 supported_options |= UPS_TEMP;
291 if (temp_output_c) { 331
292 tunits="degC"; 332 double ups_temperature = 0.0;
293 ups_temperature = atof (temp_buffer); 333 char *tunits;
294 xasprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); 334
295 } 335 if (config.temp_output_c) {
296 else { 336 tunits = "degC";
297 tunits="degF"; 337 ups_temperature = atof(temp_buffer);
298 ups_temperature = (atof (temp_buffer) * 1.8) + 32; 338 xasprintf(&message, "%sTemp=%3.1fC", message, ups_temperature);
299 xasprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); 339 } else {
340 tunits = "degF";
341 ups_temperature = (atof(temp_buffer) * 1.8) + 32;
342 xasprintf(&message, "%sTemp=%3.1fF", message, ups_temperature);
300 } 343 }
301 344
302 if (check_variable == UPS_TEMP) { 345 if (config.check_variable == UPS_TEMP) {
303 if (check_crit==TRUE && ups_temperature>=critical_value) { 346 if (config.check_crit && ups_temperature >= config.critical_value) {
304 result = STATE_CRITICAL; 347 result = STATE_CRITICAL;
348 } else if (config.check_warn &&
349 ups_temperature >= config.warning_value) {
350 result = max_state(result, STATE_WARNING);
305 } 351 }
306 else if (check_warn == TRUE && ups_temperature>=warning_value) { 352 xasprintf(&data, "%s %s", data,
307 result = max_state (result, STATE_WARNING); 353 perfdata("temp", (long)ups_temperature, tunits,
354 config.check_warn, (long)(config.warning_value),
355 config.check_crit, (long)(config.critical_value),
356 true, 0, false, 0));
357 } else {
358 xasprintf(&data, "%s %s", data,
359 perfdata("temp", (long)ups_temperature, tunits, false, 0,
360 false, 0, true, 0, false, 0));
361 }
362 }
363
364 /* get the ups real power if possible */
365 res = get_ups_variable("ups.realpower", temp_buffer, config);
366 if (res == NOSUCHVAR) {
367 supported_options &= ~UPS_REALPOWER;
368 } else if (res != OK) {
369 return STATE_CRITICAL;
370 } else {
371 supported_options |= UPS_REALPOWER;
372 double ups_realpower = 0.0;
373 ups_realpower = atof(temp_buffer);
374 xasprintf(&message, "%sReal power=%3.1fW ", message, ups_realpower);
375
376 if (config.check_variable == UPS_REALPOWER) {
377 if (config.check_crit && ups_realpower >= config.critical_value) {
378 result = STATE_CRITICAL;
379 } else if (config.check_warn &&
380 ups_realpower >= config.warning_value) {
381 result = max_state(result, STATE_WARNING);
308 } 382 }
309 xasprintf (&data, "%s %s", data, 383 xasprintf(&data, "%s %s", data,
310 perfdata ("temp", (long)ups_temperature, tunits, 384 perfdata("realpower", (long)ups_realpower, "W",
311 check_warn, (long)(warning_value), 385 config.check_warn, (long)(config.warning_value),
312 check_crit, (long)(critical_value), 386 config.check_crit, (long)(config.critical_value),
313 TRUE, 0, FALSE, 0)); 387 true, 0, false, 0));
314 } else { 388 } else {
315 xasprintf (&data, "%s %s", data, 389 xasprintf(&data, "%s %s", data,
316 perfdata ("temp", (long)ups_temperature, tunits, 390 perfdata("realpower", (long)ups_realpower, "W", false, 0,
317 FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); 391 false, 0, true, 0, false, 0));
318 } 392 }
319 } 393 }
320 394
321 /* if the UPS does not support any options we are looking for, report an error */ 395 /* if the UPS does not support any options we are looking for, report an
396 * error */
322 if (supported_options == UPS_NONE) { 397 if (supported_options == UPS_NONE) {
323 result = STATE_CRITICAL; 398 result = STATE_CRITICAL;
324 xasprintf (&message, _("UPS does not support any available options\n")); 399 xasprintf(&message, _("UPS does not support any available options\n"));
325 } 400 }
326 401
327 /* reset timeout */ 402 /* reset timeout */
328 alarm (0); 403 alarm(0);
329 404
330 printf ("UPS %s - %s|%s\n", state_text(result), message, data); 405 printf("UPS %s - %s|%s\n", state_text(result), message, data);
331 return result; 406 return result;
332} 407}
333 408
334
335
336/* determines what options are supported by the UPS */ 409/* determines what options are supported by the UPS */
337int 410int determine_status(ups_config *config, int *supported_options) {
338determine_status (void)
339{
340 char recv_buffer[MAX_INPUT_BUFFER]; 411 char recv_buffer[MAX_INPUT_BUFFER];
341 char temp_buffer[MAX_INPUT_BUFFER];
342 char *ptr;
343 int res;
344 412
345 res=get_ups_variable ("ups.status", recv_buffer); 413 int res = get_ups_variable("ups.status", recv_buffer, *config);
346 if (res == NOSUCHVAR) return OK; 414 if (res == NOSUCHVAR) {
415 return OK;
416 }
417
347 if (res != STATE_OK) { 418 if (res != STATE_OK) {
348 printf ("%s\n", _("Invalid response received from host")); 419 printf("%s\n", _("Invalid response received from host"));
349 return ERROR; 420 return ERROR;
350 } 421 }
351 422
352 supported_options |= UPS_STATUS; 423 *supported_options |= UPS_STATUS;
353 424
354 strcpy (temp_buffer, recv_buffer); 425 char temp_buffer[MAX_INPUT_BUFFER];
355 for (ptr = (char *) strtok (temp_buffer, " "); ptr != NULL; 426
356 ptr = (char *) strtok (NULL, " ")) { 427 strcpy(temp_buffer, recv_buffer);
357 if (!strcmp (ptr, "OFF")) 428 for (char *ptr = (char *)strtok(temp_buffer, " "); ptr != NULL;
358 status |= UPSSTATUS_OFF; 429 ptr = (char *)strtok(NULL, " ")) {
359 else if (!strcmp (ptr, "OL")) 430 if (!strcmp(ptr, "OFF")) {
360 status |= UPSSTATUS_OL; 431 config->status |= UPSSTATUS_OFF;
361 else if (!strcmp (ptr, "OB")) 432 } else if (!strcmp(ptr, "OL")) {
362 status |= UPSSTATUS_OB; 433 config->status |= UPSSTATUS_OL;
363 else if (!strcmp (ptr, "LB")) 434 } else if (!strcmp(ptr, "OB")) {
364 status |= UPSSTATUS_LB; 435 config->status |= UPSSTATUS_OB;
365 else if (!strcmp (ptr, "CAL")) 436 } else if (!strcmp(ptr, "LB")) {
366 status |= UPSSTATUS_CAL; 437 config->status |= UPSSTATUS_LB;
367 else if (!strcmp (ptr, "RB")) 438 } else if (!strcmp(ptr, "CAL")) {
368 status |= UPSSTATUS_RB; 439 config->status |= UPSSTATUS_CAL;
369 else if (!strcmp (ptr, "BYPASS")) 440 } else if (!strcmp(ptr, "RB")) {
370 status |= UPSSTATUS_BYPASS; 441 config->status |= UPSSTATUS_RB;
371 else if (!strcmp (ptr, "OVER")) 442 } else if (!strcmp(ptr, "BYPASS")) {
372 status |= UPSSTATUS_OVER; 443 config->status |= UPSSTATUS_BYPASS;
373 else if (!strcmp (ptr, "TRIM")) 444 } else if (!strcmp(ptr, "OVER")) {
374 status |= UPSSTATUS_TRIM; 445 config->status |= UPSSTATUS_OVER;
375 else if (!strcmp (ptr, "BOOST")) 446 } else if (!strcmp(ptr, "TRIM")) {
376 status |= UPSSTATUS_BOOST; 447 config->status |= UPSSTATUS_TRIM;
377 else if (!strcmp (ptr, "CHRG")) 448 } else if (!strcmp(ptr, "BOOST")) {
378 status |= UPSSTATUS_CHRG; 449 config->status |= UPSSTATUS_BOOST;
379 else if (!strcmp (ptr, "DISCHRG")) 450 } else if (!strcmp(ptr, "CHRG")) {
380 status |= UPSSTATUS_DISCHRG; 451 config->status |= UPSSTATUS_CHRG;
381 else 452 } else if (!strcmp(ptr, "DISCHRG")) {
382 status |= UPSSTATUS_UNKNOWN; 453 config->status |= UPSSTATUS_DISCHRG;
454 } else if (!strcmp(ptr, "ALARM")) {
455 config->status |= UPSSTATUS_ALARM;
456 } else {
457 config->status |= UPSSTATUS_UNKNOWN;
458 }
383 } 459 }
384 460
385 return OK; 461 return OK;
386} 462}
387 463
388
389/* gets a variable value for a specific UPS */ 464/* gets a variable value for a specific UPS */
390int 465int get_ups_variable(const char *varname, char *buf, const ups_config config) {
391get_ups_variable (const char *varname, char *buf)
392{
393 /* char command[MAX_INPUT_BUFFER]; */
394 char temp_buffer[MAX_INPUT_BUFFER];
395 char send_buffer[MAX_INPUT_BUFFER]; 466 char send_buffer[MAX_INPUT_BUFFER];
396 char *ptr;
397 char *logout = "OK Goodbye\n";
398 int logout_len = strlen(logout);
399 int len;
400
401 *buf=0;
402 467
403 /* create the command string to send to the UPS daemon */ 468 /* create the command string to send to the UPS daemon */
404 /* Add LOGOUT to avoid read failure logs */ 469 /* Add LOGOUT to avoid read failure logs */
405 if (snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname) >= sizeof(send_buffer)) { 470 int res = snprintf(send_buffer, sizeof(send_buffer),
471 "GET VAR %s %s\nLOGOUT\n", config.ups_name, varname);
472 if ((res > 0) && ((size_t)res >= sizeof(send_buffer))) {
406 printf("%s\n", _("UPS name to long for buffer")); 473 printf("%s\n", _("UPS name to long for buffer"));
407 return ERROR; 474 return ERROR;
408 } 475 }
409 476
477 char temp_buffer[MAX_INPUT_BUFFER];
478
410 /* send the command to the daemon and get a response back */ 479 /* send the command to the daemon and get a response back */
411 if (process_tcp_request 480 if (process_tcp_request(config.server_address, config.server_port,
412 (server_address, server_port, send_buffer, temp_buffer, 481 send_buffer, temp_buffer,
413 sizeof (temp_buffer)) != STATE_OK) { 482 sizeof(temp_buffer)) != STATE_OK) {
414 printf ("%s\n", _("Invalid response received from host")); 483 printf("%s\n", _("Invalid response received from host"));
415 return ERROR; 484 return ERROR;
416 } 485 }
417 486
418 ptr = temp_buffer; 487 char *ptr = temp_buffer;
419 len = strlen(ptr); 488 int len = strlen(ptr);
420 if (len > logout_len && strcmp (ptr + len - logout_len, logout) == 0) len -= logout_len; 489 const char *logout = "OK Goodbye\n";
421 if (len > 0 && ptr[len-1] == '\n') ptr[len-1]=0; 490 const int logout_len = strlen(logout);
422 if (strcmp (ptr, "ERR UNKNOWN-UPS") == 0) { 491
423 printf (_("CRITICAL - no such UPS '%s' on that host\n"), ups_name); 492 if (len > logout_len && strcmp(ptr + len - logout_len, logout) == 0) {
493 len -= logout_len;
494 }
495 if (len > 0 && ptr[len - 1] == '\n') {
496 ptr[len - 1] = 0;
497 }
498 if (strcmp(ptr, "ERR UNKNOWN-UPS") == 0) {
499 printf(_("CRITICAL - no such UPS '%s' on that host\n"),
500 config.ups_name);
424 return ERROR; 501 return ERROR;
425 } 502 }
426 503
427 if (strcmp (ptr, "ERR VAR-NOT-SUPPORTED") == 0) { 504 if (strcmp(ptr, "ERR VAR-NOT-SUPPORTED") == 0) {
428 /*printf ("Error: Variable '%s' is not supported\n", varname);*/ 505 /*printf ("Error: Variable '%s' is not supported\n", varname);*/
429 return NOSUCHVAR; 506 return NOSUCHVAR;
430 } 507 }
431 508
432 if (strcmp (ptr, "ERR DATA-STALE") == 0) { 509 if (strcmp(ptr, "ERR DATA-STALE") == 0) {
433 printf ("%s\n", _("CRITICAL - UPS data is stale")); 510 printf("%s\n", _("CRITICAL - UPS data is stale"));
434 return ERROR; 511 return ERROR;
435 } 512 }
436 513
437 if (strncmp (ptr, "ERR", 3) == 0) { 514 if (strncmp(ptr, "ERR", 3) == 0) {
438 printf (_("Unknown error: %s\n"), ptr); 515 printf(_("Unknown error: %s\n"), ptr);
439 return ERROR; 516 return ERROR;
440 } 517 }
441 518
442 ptr = temp_buffer + strlen (varname) + strlen (ups_name) + 6; 519 ptr = temp_buffer + strlen(varname) + strlen(config.ups_name) + 6;
443 len = strlen(ptr); 520 len = strlen(ptr);
444 if (len < 2 || ptr[0] != '"' || ptr[len-1] != '"') { 521 if (len < 2 || ptr[0] != '"' || ptr[len - 1] != '"') {
445 printf ("%s\n", _("Error: unable to parse variable")); 522 printf("%s\n", _("Error: unable to parse variable"));
446 return ERROR; 523 return ERROR;
447 } 524 }
448 strncpy (buf, ptr+1, len - 2); 525
526 *buf = 0;
527 strncpy(buf, ptr + 1, len - 2);
449 buf[len - 2] = 0; 528 buf[len - 2] = 0;
450 529
451 return OK; 530 return OK;
452} 531}
453 532
454
455/* Command line: CHECK_UPS -H <host_address> -u ups [-p port] [-v variable] 533/* Command line: CHECK_UPS -H <host_address> -u ups [-p port] [-v variable]
456 [-wv warn_value] [-cv crit_value] [-to to_sec] */ 534 [-wv warn_value] [-cv crit_value] [-to to_sec] */
457 535
458
459/* process command-line arguments */ 536/* process command-line arguments */
460int 537int process_arguments(int argc, char **argv, ups_config *config) {
461process_arguments (int argc, char **argv) 538
462{ 539 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
463 int c; 540 {"ups", required_argument, 0, 'u'},
464 541 {"port", required_argument, 0, 'p'},
465 int option = 0; 542 {"critical", required_argument, 0, 'c'},
466 static struct option longopts[] = { 543 {"warning", required_argument, 0, 'w'},
467 {"hostname", required_argument, 0, 'H'}, 544 {"timeout", required_argument, 0, 't'},
468 {"ups", required_argument, 0, 'u'}, 545 {"temperature", no_argument, 0, 'T'},
469 {"port", required_argument, 0, 'p'}, 546 {"variable", required_argument, 0, 'v'},
470 {"critical", required_argument, 0, 'c'}, 547 {"version", no_argument, 0, 'V'},
471 {"warning", required_argument, 0, 'w'}, 548 {"help", no_argument, 0, 'h'},
472 {"timeout", required_argument, 0, 't'}, 549 {0, 0, 0, 0}};
473 {"temperature", no_argument, 0, 'T'}, 550
474 {"variable", required_argument, 0, 'v'}, 551 if (argc < 2) {
475 {"version", no_argument, 0, 'V'},
476 {"help", no_argument, 0, 'h'},
477 {0, 0, 0, 0}
478 };
479
480 if (argc < 2)
481 return ERROR; 552 return ERROR;
553 }
482 554
555 int c;
483 for (c = 1; c < argc; c++) { 556 for (c = 1; c < argc; c++) {
484 if (strcmp ("-to", argv[c]) == 0) 557 if (strcmp("-to", argv[c]) == 0) {
485 strcpy (argv[c], "-t"); 558 strcpy(argv[c], "-t");
486 else if (strcmp ("-wt", argv[c]) == 0) 559 } else if (strcmp("-wt", argv[c]) == 0) {
487 strcpy (argv[c], "-w"); 560 strcpy(argv[c], "-w");
488 else if (strcmp ("-ct", argv[c]) == 0) 561 } else if (strcmp("-ct", argv[c]) == 0) {
489 strcpy (argv[c], "-c"); 562 strcpy(argv[c], "-c");
563 }
490 } 564 }
491 565
566 int option = 0;
492 while (1) { 567 while (1) {
493 c = getopt_long (argc, argv, "hVTH:u:p:v:c:w:t:", longopts, 568 c = getopt_long(argc, argv, "hVTH:u:p:v:c:w:t:", longopts, &option);
494 &option);
495 569
496 if (c == -1 || c == EOF) 570 if (c == -1 || c == EOF) {
497 break; 571 break;
572 }
498 573
499 switch (c) { 574 switch (c) {
500 case '?': /* help */ 575 case '?': /* help */
501 usage5 (); 576 usage5();
502 case 'H': /* hostname */ 577 case 'H': /* hostname */
503 if (is_host (optarg)) { 578 if (is_host(optarg)) {
504 server_address = optarg; 579 config->server_address = optarg;
505 } 580 } else {
506 else { 581 usage2(_("Invalid hostname/address"), optarg);
507 usage2 (_("Invalid hostname/address"), optarg);
508 } 582 }
509 break; 583 break;
510 case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Fahrenheit) */ 584 case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for
511 temp_output_c = 1; 585 Fahrenheit) */
586 config->temp_output_c = true;
512 break; 587 break;
513 case 'u': /* ups name */ 588 case 'u': /* ups name */
514 ups_name = optarg; 589 config->ups_name = optarg;
515 break; 590 break;
516 case 'p': /* port */ 591 case 'p': /* port */
517 if (is_intpos (optarg)) { 592 if (is_intpos(optarg)) {
518 server_port = atoi (optarg); 593 config->server_port = atoi(optarg);
519 } 594 } else {
520 else { 595 usage2(_("Port must be a positive integer"), optarg);
521 usage2 (_("Port must be a positive integer"), optarg);
522 } 596 }
523 break; 597 break;
524 case 'c': /* critical time threshold */ 598 case 'c': /* critical time threshold */
525 if (is_intnonneg (optarg)) { 599 if (is_intnonneg(optarg)) {
526 critical_value = atoi (optarg); 600 config->critical_value = atoi(optarg);
527 check_crit = TRUE; 601 config->check_crit = true;
528 } 602 } else {
529 else { 603 usage2(_("Critical time must be a positive integer"), optarg);
530 usage2 (_("Critical time must be a positive integer"), optarg);
531 } 604 }
532 break; 605 break;
533 case 'w': /* warning time threshold */ 606 case 'w': /* warning time threshold */
534 if (is_intnonneg (optarg)) { 607 if (is_intnonneg(optarg)) {
535 warning_value = atoi (optarg); 608 config->warning_value = atoi(optarg);
536 check_warn = TRUE; 609 config->check_warn = true;
537 } 610 } else {
538 else { 611 usage2(_("Warning time must be a positive integer"), optarg);
539 usage2 (_("Warning time must be a positive integer"), optarg);
540 } 612 }
541 break; 613 break;
542 case 'v': /* variable */ 614 case 'v': /* variable */
543 if (!strcmp (optarg, "LINE")) 615 if (!strcmp(optarg, "LINE")) {
544 check_variable = UPS_UTILITY; 616 config->check_variable = UPS_UTILITY;
545 else if (!strcmp (optarg, "TEMP")) 617 } else if (!strcmp(optarg, "TEMP")) {
546 check_variable = UPS_TEMP; 618 config->check_variable = UPS_TEMP;
547 else if (!strcmp (optarg, "BATTPCT")) 619 } else if (!strcmp(optarg, "BATTPCT")) {
548 check_variable = UPS_BATTPCT; 620 config->check_variable = UPS_BATTPCT;
549 else if (!strcmp (optarg, "LOADPCT")) 621 } else if (!strcmp(optarg, "LOADPCT")) {
550 check_variable = UPS_LOADPCT; 622 config->check_variable = UPS_LOADPCT;
551 else 623 } else if (!strcmp(optarg, "REALPOWER")) {
552 usage2 (_("Unrecognized UPS variable"), optarg); 624 config->check_variable = UPS_REALPOWER;
553 break; 625 } else {
554 case 't': /* timeout */ 626 usage2(_("Unrecognized UPS variable"), optarg);
555 if (is_intnonneg (optarg)) {
556 socket_timeout = atoi (optarg);
557 } 627 }
558 else { 628 break;
559 usage4 (_("Timeout interval must be a positive integer")); 629 case 't': /* timeout */
630 if (is_intnonneg(optarg)) {
631 socket_timeout = atoi(optarg);
632 } else {
633 usage4(_("Timeout interval must be a positive integer"));
560 } 634 }
561 break; 635 break;
562 case 'V': /* version */ 636 case 'V': /* version */
563 print_revision (progname, NP_VERSION); 637 print_revision(progname, NP_VERSION);
564 exit (STATE_UNKNOWN); 638 exit(STATE_UNKNOWN);
565 case 'h': /* help */ 639 case 'h': /* help */
566 print_help (); 640 print_help();
567 exit (STATE_UNKNOWN); 641 exit(STATE_UNKNOWN);
568 } 642 }
569 } 643 }
570 644
571 645 if (config->server_address == NULL && argc > optind) {
572 if (server_address == NULL && argc > optind) { 646 if (is_host(argv[optind])) {
573 if (is_host (argv[optind])) 647 config->server_address = argv[optind++];
574 server_address = argv[optind++]; 648 } else {
575 else 649 usage2(_("Invalid hostname/address"), optarg);
576 usage2 (_("Invalid hostname/address"), optarg); 650 }
577 } 651 }
578 652
579 if (server_address == NULL) 653 if (config->server_address == NULL) {
580 server_address = strdup("127.0.0.1"); 654 config->server_address = strdup("127.0.0.1");
655 }
581 656
582 return validate_arguments(); 657 return validate_arguments(*config);
583} 658}
584 659
585 660int validate_arguments(ups_config config) {
586int 661 if (!config.ups_name) {
587validate_arguments (void) 662 printf("%s\n", _("Error : no UPS indicated"));
588{
589 if (! ups_name) {
590 printf ("%s\n", _("Error : no UPS indicated"));
591 return ERROR; 663 return ERROR;
592 } 664 }
593 return OK; 665 return OK;
594} 666}
595 667
668void print_help(void) {
669 print_revision(progname, NP_VERSION);
596 670
597void 671 printf("Copyright (c) 2000 Tom Shields\n");
598print_help (void) 672 printf("Copyright (c) 2004 Alain Richard <alain.richard@equation.fr>\n");
599{ 673 printf("Copyright (c) 2004 Arnaud Quette <arnaud.quette@mgeups.com>\n");
600 char *myport; 674 printf(COPYRIGHT, copyright, email);
601 xasprintf (&myport, "%d", PORT);
602
603 print_revision (progname, NP_VERSION);
604
605 printf ("Copyright (c) 2000 Tom Shields\n");
606 printf ("Copyright (c) 2004 Alain Richard <alain.richard@equation.fr>\n");
607 printf ("Copyright (c) 2004 Arnaud Quette <arnaud.quette@mgeups.com>\n");
608 printf (COPYRIGHT, copyright, email);
609
610 printf ("%s\n", _("This plugin tests the UPS service on the specified host. Network UPS Tools"));
611 printf ("%s\n", _("from www.networkupstools.org must be running for this plugin to work."));
612
613 printf ("\n\n");
614
615 print_usage ();
616 675
617 printf (UT_HELP_VRSN); 676 printf("%s\n", _("This plugin tests the UPS service on the specified host. "
618 printf (UT_EXTRA_OPTS); 677 "Network UPS Tools"));
678 printf("%s\n", _("from www.networkupstools.org must be running for this "
679 "plugin to work."));
619 680
620 printf (UT_HOST_PORT, 'p', myport); 681 printf("\n\n");
621 682
622 printf (" %s\n", "-u, --ups=STRING"); 683 print_usage();
623 printf (" %s\n", _("Name of UPS"));
624 printf (" %s\n", "-T, --temperature");
625 printf (" %s\n", _("Output of temperatures in Celsius"));
626 printf (" %s\n", "-v, --variable=STRING");
627 printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT or LOADPCT");
628 684
629 printf (UT_WARN_CRIT); 685 printf(UT_HELP_VRSN);
686 printf(UT_EXTRA_OPTS);
630 687
631 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 688 char *myport;
632 689 xasprintf(&myport, "%d", PORT);
633/* TODO: -v clashing with -v/-variable. Commenting out help text since verbose 690 printf(UT_HOST_PORT, 'p', myport);
634 is unused up to now */ 691
635/* printf (UT_VERBOSE); */ 692 printf(" %s\n", "-u, --ups=STRING");
636 693 printf(" %s\n", _("Name of UPS"));
637 printf ("\n"); 694 printf(" %s\n", "-T, --temperature");
638 printf ("%s\n", _("This plugin attempts to determine the status of a UPS (Uninterruptible Power")); 695 printf(" %s\n", _("Output of temperatures in Celsius"));
639 printf ("%s\n", _("Supply) on a local or remote host. If the UPS is online or calibrating, the")); 696 printf(" %s\n", "-v, --variable=STRING");
640 printf ("%s\n", _("plugin will return an OK state. If the battery is on it will return a WARNING")); 697 printf(" %s %s\n", _("Valid values for STRING are"),
641 printf ("%s\n", _("state. If the UPS is off or has a low battery the plugin will return a CRITICAL")); 698 "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER");
642 printf ("%s\n", _("state.")); 699
643 700 printf(UT_WARN_CRIT);
644 printf ("\n"); 701
645 printf ("%s\n", _("Notes:")); 702 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
646 printf (" %s\n", _("You may also specify a variable to check (such as temperature, utility voltage,")); 703
647 printf (" %s\n", _("battery load, etc.) as well as warning and critical thresholds for the value")); 704 /* TODO: -v clashing with -v/-variable. Commenting out help text since
648 printf (" %s\n", _("of that variable. If the remote host has multiple UPS that are being monitored")); 705 verbose is unused up to now */
649 printf (" %s\n", _("you will have to use the --ups option to specify which UPS to check.")); 706 /* printf (UT_VERBOSE); */
650 printf ("\n"); 707
651 printf (" %s\n", _("This plugin requires that the UPSD daemon distributed with Russell Kroll's")); 708 printf("\n");
652 printf (" %s\n", _("Network UPS Tools be installed on the remote host. If you do not have the")); 709 printf("%s\n", _("This plugin attempts to determine the status of a UPS "
653 printf (" %s\n", _("package installed on your system, you can download it from")); 710 "(Uninterruptible Power"));
654 printf (" %s\n", _("http://www.networkupstools.org")); 711 printf("%s\n", _("Supply) on a local or remote host. If the UPS is online "
655 712 "or calibrating, the"));
656 printf (UT_SUPPORT); 713 printf("%s\n", _("plugin will return an OK state. If the battery is on it "
714 "will return a WARNING"));
715 printf("%s\n", _("state. If the UPS is off or has a low battery the plugin "
716 "will return a CRITICAL"));
717 printf("%s\n", _("state."));
718
719 printf("\n");
720 printf("%s\n", _("Notes:"));
721 printf(" %s\n", _("You may also specify a variable to check (such as "
722 "temperature, utility voltage,"));
723 printf(" %s\n", _("battery load, etc.) as well as warning and critical "
724 "thresholds for the value"));
725 printf(" %s\n", _("of that variable. If the remote host has multiple UPS "
726 "that are being monitored"));
727 printf(" %s\n", _("you will have to use the --ups option to specify which "
728 "UPS to check."));
729 printf("\n");
730 printf(" %s\n", _("This plugin requires that the UPSD daemon distributed "
731 "with Russell Kroll's"));
732 printf(" %s\n", _("Network UPS Tools be installed on the remote host. If "
733 "you do not have the"));
734 printf(" %s\n",
735 _("package installed on your system, you can download it from"));
736 printf(" %s\n", _("http://www.networkupstools.org"));
737
738 printf(UT_SUPPORT);
657} 739}
658 740
659 741void print_usage(void) {
660void 742 printf("%s\n", _("Usage:"));
661print_usage (void) 743 printf("%s -H host -u ups [-p port] [-v variable] [-w warn_value] [-c "
662{ 744 "crit_value] [-to to_sec] [-T]\n",
663 printf ("%s\n", _("Usage:")); 745 progname);
664 printf ("%s -H host -u ups [-p port] [-v variable] [-w warn_value] [-c crit_value] [-to to_sec] [-T]\n", progname);
665} 746}