diff options
author | Louis Sautier <sautier.louis@gmail.com> | 2023-11-09 23:40:28 +0100 |
---|---|---|
committer | Louis Sautier <sautier.louis@gmail.com> | 2023-11-10 00:08:49 +0100 |
commit | eebb280ca32975b7bd48d6defce47fbdc8027861 (patch) | |
tree | 5602bc593f8e86a7eb672bd41786900d9e2e5c58 /plugins | |
parent | 6131659fe307fcbe16beb028c2e4d1c877646f13 (diff) | |
download | monitoring-plugins-eebb280ca32975b7bd48d6defce47fbdc8027861.tar.gz |
check_ups: output ups.realpower if supported
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ups.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index bb91c4ad..2fb04eef 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -46,12 +46,13 @@ enum { | |||
46 | 46 | ||
47 | #define CHECK_NONE 0 | 47 | #define CHECK_NONE 0 |
48 | 48 | ||
49 | #define UPS_NONE 0 /* no supported options */ | 49 | #define UPS_NONE 0 /* no supported options */ |
50 | #define UPS_UTILITY 1 /* supports utility line voltage */ | 50 | #define UPS_UTILITY 1 /* supports utility line */ |
51 | #define UPS_BATTPCT 2 /* supports percent battery remaining */ | 51 | #define UPS_BATTPCT 2 /* supports percent battery remaining */ |
52 | #define UPS_STATUS 4 /* supports UPS status */ | 52 | #define UPS_STATUS 4 /* supports UPS status */ |
53 | #define UPS_TEMP 8 /* supports UPS temperature */ | 53 | #define UPS_TEMP 8 /* supports UPS temperature */ |
54 | #define UPS_LOADPCT 16 /* supports load percent */ | 54 | #define UPS_LOADPCT 16 /* supports load percent */ |
55 | #define UPS_REALPOWER 32 /* supports real power */ | ||
55 | 56 | ||
56 | #define UPSSTATUS_NONE 0 | 57 | #define UPSSTATUS_NONE 0 |
57 | #define UPSSTATUS_OFF 1 | 58 | #define UPSSTATUS_OFF 1 |
@@ -85,6 +86,7 @@ double ups_utility_voltage = 0.0; | |||
85 | double ups_battery_percent = 0.0; | 86 | double ups_battery_percent = 0.0; |
86 | double ups_load_percent = 0.0; | 87 | double ups_load_percent = 0.0; |
87 | double ups_temperature = 0.0; | 88 | double ups_temperature = 0.0; |
89 | double ups_realpower = 0.0; | ||
88 | char *ups_status; | 90 | char *ups_status; |
89 | bool temp_output_c = false; | 91 | bool temp_output_c = false; |
90 | 92 | ||
@@ -318,6 +320,35 @@ main (int argc, char **argv) | |||
318 | } | 320 | } |
319 | } | 321 | } |
320 | 322 | ||
323 | /* get the ups real power if possible */ | ||
324 | res=get_ups_variable ("ups.realpower", temp_buffer); | ||
325 | if ( res == NOSUCHVAR ) supported_options &= ~UPS_REALPOWER; | ||
326 | else if ( res != OK) | ||
327 | return STATE_CRITICAL; | ||
328 | else { | ||
329 | supported_options |= UPS_REALPOWER; | ||
330 | ups_realpower = atof (temp_buffer); | ||
331 | xasprintf (&message, "%sReal power=%3.1fW ", message, ups_realpower); | ||
332 | |||
333 | if (check_variable == UPS_REALPOWER) { | ||
334 | if (check_crit && ups_realpower>=critical_value) { | ||
335 | result = STATE_CRITICAL; | ||
336 | } | ||
337 | else if (check_warn && ups_realpower>=warning_value) { | ||
338 | result = max_state (result, STATE_WARNING); | ||
339 | } | ||
340 | xasprintf (&data, "%s %s", data, | ||
341 | perfdata ("realpower", (long)ups_realpower, "W", | ||
342 | check_warn, (long)(warning_value), | ||
343 | check_crit, (long)(critical_value), | ||
344 | true, 0, false, 0)); | ||
345 | } else { | ||
346 | xasprintf (&data, "%s %s", data, | ||
347 | perfdata ("realpower", (long)ups_realpower, "W", | ||
348 | false, 0, false, 0, true, 0, false, 0)); | ||
349 | } | ||
350 | } | ||
351 | |||
321 | /* if the UPS does not support any options we are looking for, report an error */ | 352 | /* if the UPS does not support any options we are looking for, report an error */ |
322 | if (supported_options == UPS_NONE) { | 353 | if (supported_options == UPS_NONE) { |
323 | result = STATE_CRITICAL; | 354 | result = STATE_CRITICAL; |
@@ -549,6 +580,8 @@ process_arguments (int argc, char **argv) | |||
549 | check_variable = UPS_BATTPCT; | 580 | check_variable = UPS_BATTPCT; |
550 | else if (!strcmp (optarg, "LOADPCT")) | 581 | else if (!strcmp (optarg, "LOADPCT")) |
551 | check_variable = UPS_LOADPCT; | 582 | check_variable = UPS_LOADPCT; |
583 | else if (!strcmp (optarg, "REALPOWER")) | ||
584 | check_variable = UPS_REALPOWER; | ||
552 | else | 585 | else |
553 | usage2 (_("Unrecognized UPS variable"), optarg); | 586 | usage2 (_("Unrecognized UPS variable"), optarg); |
554 | break; | 587 | break; |
@@ -625,7 +658,7 @@ print_help (void) | |||
625 | printf (" %s\n", "-T, --temperature"); | 658 | printf (" %s\n", "-T, --temperature"); |
626 | printf (" %s\n", _("Output of temperatures in Celsius")); | 659 | printf (" %s\n", _("Output of temperatures in Celsius")); |
627 | printf (" %s\n", "-v, --variable=STRING"); | 660 | printf (" %s\n", "-v, --variable=STRING"); |
628 | printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT or LOADPCT"); | 661 | printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER"); |
629 | 662 | ||
630 | printf (UT_WARN_CRIT); | 663 | printf (UT_WARN_CRIT); |
631 | 664 | ||