summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format4
-rw-r--r--plugins/check_ups.c106
2 files changed, 35 insertions, 75 deletions
diff --git a/.clang-format b/.clang-format
index c7f0b5e..f29680a 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,10 +1,10 @@
1BasedOnStyle: LLVM
2UseTab: ForContinuationAndIndentation 1UseTab: ForContinuationAndIndentation
3IndentWidth: 4 2IndentWidth: 4
4TabWidth: 4 3TabWidth: 4
5AllowShortIfStatementsOnASingleLine: false 4AllowShortIfStatementsOnASingleLine: false
6BreakBeforeBraces: Attach 5BreakBeforeBraces: Attach
7AlignConsecutiveMacros: true 6AlignConsecutiveMacros: true
8ColumnLimit: 180 7ColumnLimit: 140
9IndentPPDirectives: AfterHash 8IndentPPDirectives: AfterHash
10SortIncludes: Never 9SortIncludes: Never
10BinPackArguments: true
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 380ff3b..f60c0e9 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -6,7 +6,7 @@
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-2023 Monitoring Plugins Development Team 9 * Copyright (c) 2002-2024 Monitoring Plugins Development Team
10 * 10 *
11 * Description: 11 * Description:
12 * 12 *
@@ -33,7 +33,7 @@
33 *****************************************************************************/ 33 *****************************************************************************/
34 34
35const char *progname = "check_ups"; 35const char *progname = "check_ups";
36const char *copyright = "2000-2023"; 36const char *copyright = "2000-2024";
37const char *email = "devel@monitoring-plugins.org"; 37const char *email = "devel@monitoring-plugins.org";
38 38
39#include "common.h" 39#include "common.h"
@@ -141,7 +141,6 @@ int main(int argc, char **argv) {
141 return STATE_CRITICAL; 141 return STATE_CRITICAL;
142 } 142 }
143 143
144
145 if (supported_options & UPS_STATUS) { 144 if (supported_options & UPS_STATUS) {
146 145
147 ups_status = strdup(""); 146 ups_status = strdup("");
@@ -151,8 +150,7 @@ int main(int argc, char **argv) {
151 if (config.status & UPSSTATUS_OFF) { 150 if (config.status & UPSSTATUS_OFF) {
152 xasprintf(&ups_status, "Off"); 151 xasprintf(&ups_status, "Off");
153 result = STATE_CRITICAL; 152 result = STATE_CRITICAL;
154 } else if ((config.status & (UPSSTATUS_OB | UPSSTATUS_LB)) == 153 } else if ((config.status & (UPSSTATUS_OB | UPSSTATUS_LB)) == (UPSSTATUS_OB | UPSSTATUS_LB)) {
155 (UPSSTATUS_OB | UPSSTATUS_LB)) {
156 xasprintf(&ups_status, _("On Battery, Low Battery")); 154 xasprintf(&ups_status, _("On Battery, Low Battery"));
157 result = STATE_CRITICAL; 155 result = STATE_CRITICAL;
158 } else { 156 } else {
@@ -171,8 +169,7 @@ int main(int argc, char **argv) {
171 xasprintf(&ups_status, "%s%s", ups_status, _(", Calibrating")); 169 xasprintf(&ups_status, "%s%s", ups_status, _(", Calibrating"));
172 } 170 }
173 if (config.status & UPSSTATUS_RB) { 171 if (config.status & UPSSTATUS_RB) {
174 xasprintf(&ups_status, "%s%s", ups_status, 172 xasprintf(&ups_status, "%s%s", ups_status, _(", Replace Battery"));
175 _(", Replace Battery"));
176 result = max_state(result, STATE_WARNING); 173 result = max_state(result, STATE_WARNING);
177 } 174 }
178 if (config.status & UPSSTATUS_BYPASS) { 175 if (config.status & UPSSTATUS_BYPASS) {
@@ -233,24 +230,16 @@ int main(int argc, char **argv) {
233 } 230 }
234 231
235 if (config.check_variable == UPS_UTILITY) { 232 if (config.check_variable == UPS_UTILITY) {
236 if (config.check_crit && 233 if (config.check_crit && ups_utility_deviation >= config.critical_value) {
237 ups_utility_deviation >= config.critical_value) {
238 result = STATE_CRITICAL; 234 result = STATE_CRITICAL;
239 } else if (config.check_warn && 235 } else if (config.check_warn && ups_utility_deviation >= config.warning_value) {
240 ups_utility_deviation >= config.warning_value) {
241 result = max_state(result, STATE_WARNING); 236 result = max_state(result, STATE_WARNING);
242 } 237 }
243 xasprintf(&data, "%s", 238 xasprintf(&data, "%s",
244 perfdata("voltage", (long)(1000 * ups_utility_voltage), 239 perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", config.check_warn, (long)(1000 * config.warning_value),
245 "mV", config.check_warn, 240 config.check_crit, (long)(1000 * config.critical_value), true, 0, false, 0));
246 (long)(1000 * config.warning_value),
247 config.check_crit,
248 (long)(1000 * config.critical_value), true, 0,
249 false, 0));
250 } else { 241 } else {
251 xasprintf(&data, "%s", 242 xasprintf(&data, "%s", perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", false, 0, false, 0, true, 0, false, 0));
252 perfdata("voltage", (long)(1000 * ups_utility_voltage),
253 "mV", false, 0, false, 0, true, 0, false, 0));
254 } 243 }
255 } 244 }
256 245
@@ -268,22 +257,16 @@ int main(int argc, char **argv) {
268 xasprintf(&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); 257 xasprintf(&message, "%sBatt=%3.1f%% ", message, ups_battery_percent);
269 258
270 if (config.check_variable == UPS_BATTPCT) { 259 if (config.check_variable == UPS_BATTPCT) {
271 if (config.check_crit && 260 if (config.check_crit && ups_battery_percent <= config.critical_value) {
272 ups_battery_percent <= config.critical_value) {
273 result = STATE_CRITICAL; 261 result = STATE_CRITICAL;
274 } else if (config.check_warn && 262 } else if (config.check_warn && ups_battery_percent <= config.warning_value) {
275 ups_battery_percent <= config.warning_value) {
276 result = max_state(result, STATE_WARNING); 263 result = max_state(result, STATE_WARNING);
277 } 264 }
278 xasprintf(&data, "%s %s", data, 265 xasprintf(&data, "%s %s", data,
279 perfdata("battery", (long)ups_battery_percent, "%", 266 perfdata("battery", (long)ups_battery_percent, "%", config.check_warn, (long)(config.warning_value),
280 config.check_warn, (long)(config.warning_value), 267 config.check_crit, (long)(config.critical_value), true, 0, true, 100));
281 config.check_crit, (long)(config.critical_value),
282 true, 0, true, 100));
283 } else { 268 } else {
284 xasprintf(&data, "%s %s", data, 269 xasprintf(&data, "%s %s", data, perfdata("battery", (long)ups_battery_percent, "%", false, 0, false, 0, true, 0, true, 100));
285 perfdata("battery", (long)ups_battery_percent, "%", false,
286 0, false, 0, true, 0, true, 100));
287 } 270 }
288 } 271 }
289 272
@@ -301,22 +284,16 @@ int main(int argc, char **argv) {
301 xasprintf(&message, "%sLoad=%3.1f%% ", message, ups_load_percent); 284 xasprintf(&message, "%sLoad=%3.1f%% ", message, ups_load_percent);
302 285
303 if (config.check_variable == UPS_LOADPCT) { 286 if (config.check_variable == UPS_LOADPCT) {
304 if (config.check_crit && 287 if (config.check_crit && ups_load_percent >= config.critical_value) {
305 ups_load_percent >= config.critical_value) {
306 result = STATE_CRITICAL; 288 result = STATE_CRITICAL;
307 } else if (config.check_warn && 289 } else if (config.check_warn && ups_load_percent >= config.warning_value) {
308 ups_load_percent >= config.warning_value) {
309 result = max_state(result, STATE_WARNING); 290 result = max_state(result, STATE_WARNING);
310 } 291 }
311 xasprintf(&data, "%s %s", data, 292 xasprintf(&data, "%s %s", data,
312 perfdata("load", (long)ups_load_percent, "%", 293 perfdata("load", (long)ups_load_percent, "%", config.check_warn, (long)(config.warning_value), config.check_crit,
313 config.check_warn, (long)(config.warning_value), 294 (long)(config.critical_value), true, 0, true, 100));
314 config.check_crit, (long)(config.critical_value),
315 true, 0, true, 100));
316 } else { 295 } else {
317 xasprintf(&data, "%s %s", data, 296 xasprintf(&data, "%s %s", data, perfdata("load", (long)ups_load_percent, "%", false, 0, false, 0, true, 0, true, 100));
318 perfdata("load", (long)ups_load_percent, "%", false, 0,
319 false, 0, true, 0, true, 100));
320 } 297 }
321 } 298 }
322 299
@@ -345,19 +322,14 @@ int main(int argc, char **argv) {
345 if (config.check_variable == UPS_TEMP) { 322 if (config.check_variable == UPS_TEMP) {
346 if (config.check_crit && ups_temperature >= config.critical_value) { 323 if (config.check_crit && ups_temperature >= config.critical_value) {
347 result = STATE_CRITICAL; 324 result = STATE_CRITICAL;
348 } else if (config.check_warn && 325 } else if (config.check_warn && ups_temperature >= config.warning_value) {
349 ups_temperature >= config.warning_value) {
350 result = max_state(result, STATE_WARNING); 326 result = max_state(result, STATE_WARNING);
351 } 327 }
352 xasprintf(&data, "%s %s", data, 328 xasprintf(&data, "%s %s", data,
353 perfdata("temp", (long)ups_temperature, tunits, 329 perfdata("temp", (long)ups_temperature, tunits, config.check_warn, (long)(config.warning_value), config.check_crit,
354 config.check_warn, (long)(config.warning_value), 330 (long)(config.critical_value), true, 0, false, 0));
355 config.check_crit, (long)(config.critical_value),
356 true, 0, false, 0));
357 } else { 331 } else {
358 xasprintf(&data, "%s %s", data, 332 xasprintf(&data, "%s %s", data, perfdata("temp", (long)ups_temperature, tunits, false, 0, false, 0, true, 0, false, 0));
359 perfdata("temp", (long)ups_temperature, tunits, false, 0,
360 false, 0, true, 0, false, 0));
361 } 333 }
362 } 334 }
363 335
@@ -376,19 +348,14 @@ int main(int argc, char **argv) {
376 if (config.check_variable == UPS_REALPOWER) { 348 if (config.check_variable == UPS_REALPOWER) {
377 if (config.check_crit && ups_realpower >= config.critical_value) { 349 if (config.check_crit && ups_realpower >= config.critical_value) {
378 result = STATE_CRITICAL; 350 result = STATE_CRITICAL;
379 } else if (config.check_warn && 351 } else if (config.check_warn && ups_realpower >= config.warning_value) {
380 ups_realpower >= config.warning_value) {
381 result = max_state(result, STATE_WARNING); 352 result = max_state(result, STATE_WARNING);
382 } 353 }
383 xasprintf(&data, "%s %s", data, 354 xasprintf(&data, "%s %s", data,
384 perfdata("realpower", (long)ups_realpower, "W", 355 perfdata("realpower", (long)ups_realpower, "W", config.check_warn, (long)(config.warning_value), config.check_crit,
385 config.check_warn, (long)(config.warning_value), 356 (long)(config.critical_value), true, 0, false, 0));
386 config.check_crit, (long)(config.critical_value),
387 true, 0, false, 0));
388 } else { 357 } else {
389 xasprintf(&data, "%s %s", data, 358 xasprintf(&data, "%s %s", data, perfdata("realpower", (long)ups_realpower, "W", false, 0, false, 0, true, 0, false, 0));
390 perfdata("realpower", (long)ups_realpower, "W", false, 0,
391 false, 0, true, 0, false, 0));
392 } 359 }
393 } 360 }
394 361
@@ -425,8 +392,7 @@ int determine_status(ups_config *config, int *supported_options) {
425 char temp_buffer[MAX_INPUT_BUFFER]; 392 char temp_buffer[MAX_INPUT_BUFFER];
426 393
427 strcpy(temp_buffer, recv_buffer); 394 strcpy(temp_buffer, recv_buffer);
428 for (char *ptr = (char *)strtok(temp_buffer, " "); ptr != NULL; 395 for (char *ptr = (char *)strtok(temp_buffer, " "); ptr != NULL; ptr = (char *)strtok(NULL, " ")) {
429 ptr = (char *)strtok(NULL, " ")) {
430 if (!strcmp(ptr, "OFF")) { 396 if (!strcmp(ptr, "OFF")) {
431 config->status |= UPSSTATUS_OFF; 397 config->status |= UPSSTATUS_OFF;
432 } else if (!strcmp(ptr, "OL")) { 398 } else if (!strcmp(ptr, "OL")) {
@@ -467,8 +433,7 @@ int get_ups_variable(const char *varname, char *buf, const ups_config config) {
467 433
468 /* create the command string to send to the UPS daemon */ 434 /* create the command string to send to the UPS daemon */
469 /* Add LOGOUT to avoid read failure logs */ 435 /* Add LOGOUT to avoid read failure logs */
470 int res = snprintf(send_buffer, sizeof(send_buffer), 436 int res = snprintf(send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", config.ups_name, varname);
471 "GET VAR %s %s\nLOGOUT\n", config.ups_name, varname);
472 if ((res > 0) && ((size_t)res >= sizeof(send_buffer))) { 437 if ((res > 0) && ((size_t)res >= sizeof(send_buffer))) {
473 printf("%s\n", _("UPS name to long for buffer")); 438 printf("%s\n", _("UPS name to long for buffer"));
474 return ERROR; 439 return ERROR;
@@ -477,9 +442,7 @@ int get_ups_variable(const char *varname, char *buf, const ups_config config) {
477 char temp_buffer[MAX_INPUT_BUFFER]; 442 char temp_buffer[MAX_INPUT_BUFFER];
478 443
479 /* send the command to the daemon and get a response back */ 444 /* send the command to the daemon and get a response back */
480 if (process_tcp_request(config.server_address, config.server_port, 445 if (process_tcp_request(config.server_address, config.server_port, send_buffer, temp_buffer, sizeof(temp_buffer)) != STATE_OK) {
481 send_buffer, temp_buffer,
482 sizeof(temp_buffer)) != STATE_OK) {
483 printf("%s\n", _("Invalid response received from host")); 446 printf("%s\n", _("Invalid response received from host"));
484 return ERROR; 447 return ERROR;
485 } 448 }
@@ -496,8 +459,7 @@ int get_ups_variable(const char *varname, char *buf, const ups_config config) {
496 ptr[len - 1] = 0; 459 ptr[len - 1] = 0;
497 } 460 }
498 if (strcmp(ptr, "ERR UNKNOWN-UPS") == 0) { 461 if (strcmp(ptr, "ERR UNKNOWN-UPS") == 0) {
499 printf(_("CRITICAL - no such UPS '%s' on that host\n"), 462 printf(_("CRITICAL - no such UPS '%s' on that host\n"), config.ups_name);
500 config.ups_name);
501 return ERROR; 463 return ERROR;
502 } 464 }
503 465
@@ -694,8 +656,7 @@ void print_help(void) {
694 printf(" %s\n", "-T, --temperature"); 656 printf(" %s\n", "-T, --temperature");
695 printf(" %s\n", _("Output of temperatures in Celsius")); 657 printf(" %s\n", _("Output of temperatures in Celsius"));
696 printf(" %s\n", "-v, --variable=STRING"); 658 printf(" %s\n", "-v, --variable=STRING");
697 printf(" %s %s\n", _("Valid values for STRING are"), 659 printf(" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER");
698 "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER");
699 660
700 printf(UT_WARN_CRIT); 661 printf(UT_WARN_CRIT);
701 662
@@ -731,8 +692,7 @@ void print_help(void) {
731 "with Russell Kroll's")); 692 "with Russell Kroll's"));
732 printf(" %s\n", _("Network UPS Tools be installed on the remote host. If " 693 printf(" %s\n", _("Network UPS Tools be installed on the remote host. If "
733 "you do not have the")); 694 "you do not have the"));
734 printf(" %s\n", 695 printf(" %s\n", _("package installed on your system, you can download it from"));
735 _("package installed on your system, you can download it from"));
736 printf(" %s\n", _("http://www.networkupstools.org")); 696 printf(" %s\n", _("http://www.networkupstools.org"));
737 697
738 printf(UT_SUPPORT); 698 printf(UT_SUPPORT);