summaryrefslogtreecommitdiffstats
path: root/plugins/check_ups.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-15 12:59:37 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-15 12:59:37 +0200
commit802e46f8ea36c344f112d7e1dd8d64d17a4cc939 (patch)
treecabf480269113686430053d66df3dadcd4d137a7 /plugins/check_ups.c
parenta3cf9041af810770daf5d9b83f1906fa9bb0dd11 (diff)
downloadmonitoring-plugins-802e46f8ea36c344f112d7e1dd8d64d17a4cc939.tar.gz
Run clang-format again
Diffstat (limited to 'plugins/check_ups.c')
-rw-r--r--plugins/check_ups.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index ecc0760f..54decce3 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -106,7 +106,8 @@ int main(int argc, char **argv) {
106 if (ups_status_flags & UPSSTATUS_OFF) { 106 if (ups_status_flags & UPSSTATUS_OFF) {
107 xasprintf(&ups_status, "Off"); 107 xasprintf(&ups_status, "Off");
108 result = STATE_CRITICAL; 108 result = STATE_CRITICAL;
109 } else if ((ups_status_flags & (UPSSTATUS_OB | UPSSTATUS_LB)) == (UPSSTATUS_OB | UPSSTATUS_LB)) { 109 } else if ((ups_status_flags & (UPSSTATUS_OB | UPSSTATUS_LB)) ==
110 (UPSSTATUS_OB | UPSSTATUS_LB)) {
110 xasprintf(&ups_status, _("On Battery, Low Battery")); 111 xasprintf(&ups_status, _("On Battery, Low Battery"));
111 result = STATE_CRITICAL; 112 result = STATE_CRITICAL;
112 } else { 113 } else {
@@ -192,11 +193,14 @@ int main(int argc, char **argv) {
192 result = max_state(result, STATE_WARNING); 193 result = max_state(result, STATE_WARNING);
193 } 194 }
194 xasprintf(&performance_data, "%s", 195 xasprintf(&performance_data, "%s",
195 perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", config.check_warn, (long)(1000 * config.warning_value), 196 perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV",
196 config.check_crit, (long)(1000 * config.critical_value), true, 0, false, 0)); 197 config.check_warn, (long)(1000 * config.warning_value),
198 config.check_crit, (long)(1000 * config.critical_value), true, 0,
199 false, 0));
197 } else { 200 } else {
198 xasprintf(&performance_data, "%s", 201 xasprintf(&performance_data, "%s",
199 perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", false, 0, false, 0, true, 0, false, 0)); 202 perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", false, 0, false,
203 0, true, 0, false, 0));
200 } 204 }
201 } 205 }
202 206
@@ -220,11 +224,13 @@ int main(int argc, char **argv) {
220 result = max_state(result, STATE_WARNING); 224 result = max_state(result, STATE_WARNING);
221 } 225 }
222 xasprintf(&performance_data, "%s %s", performance_data, 226 xasprintf(&performance_data, "%s %s", performance_data,
223 perfdata("battery", (long)ups_battery_percent, "%", config.check_warn, (long)(config.warning_value), 227 perfdata("battery", (long)ups_battery_percent, "%", config.check_warn,
224 config.check_crit, (long)(config.critical_value), true, 0, true, 100)); 228 (long)(config.warning_value), config.check_crit,
229 (long)(config.critical_value), true, 0, true, 100));
225 } else { 230 } else {
226 xasprintf(&performance_data, "%s %s", performance_data, 231 xasprintf(&performance_data, "%s %s", performance_data,
227 perfdata("battery", (long)ups_battery_percent, "%", false, 0, false, 0, true, 0, true, 100)); 232 perfdata("battery", (long)ups_battery_percent, "%", false, 0, false, 0, true,
233 0, true, 100));
228 } 234 }
229 } 235 }
230 236
@@ -248,11 +254,13 @@ int main(int argc, char **argv) {
248 result = max_state(result, STATE_WARNING); 254 result = max_state(result, STATE_WARNING);
249 } 255 }
250 xasprintf(&performance_data, "%s %s", performance_data, 256 xasprintf(&performance_data, "%s %s", performance_data,
251 perfdata("load", (long)ups_load_percent, "%", config.check_warn, (long)(config.warning_value), config.check_crit, 257 perfdata("load", (long)ups_load_percent, "%", config.check_warn,
258 (long)(config.warning_value), config.check_crit,
252 (long)(config.critical_value), true, 0, true, 100)); 259 (long)(config.critical_value), true, 0, true, 100));
253 } else { 260 } else {
254 xasprintf(&performance_data, "%s %s", performance_data, 261 xasprintf(&performance_data, "%s %s", performance_data,
255 perfdata("load", (long)ups_load_percent, "%", false, 0, false, 0, true, 0, true, 100)); 262 perfdata("load", (long)ups_load_percent, "%", false, 0, false, 0, true, 0,
263 true, 100));
256 } 264 }
257 } 265 }
258 266
@@ -285,11 +293,13 @@ int main(int argc, char **argv) {
285 result = max_state(result, STATE_WARNING); 293 result = max_state(result, STATE_WARNING);
286 } 294 }
287 xasprintf(&performance_data, "%s %s", performance_data, 295 xasprintf(&performance_data, "%s %s", performance_data,
288 perfdata("temp", (long)ups_temperature, tunits, config.check_warn, (long)(config.warning_value), config.check_crit, 296 perfdata("temp", (long)ups_temperature, tunits, config.check_warn,
297 (long)(config.warning_value), config.check_crit,
289 (long)(config.critical_value), true, 0, false, 0)); 298 (long)(config.critical_value), true, 0, false, 0));
290 } else { 299 } else {
291 xasprintf(&performance_data, "%s %s", performance_data, 300 xasprintf(&performance_data, "%s %s", performance_data,
292 perfdata("temp", (long)ups_temperature, tunits, false, 0, false, 0, true, 0, false, 0)); 301 perfdata("temp", (long)ups_temperature, tunits, false, 0, false, 0, true, 0,
302 false, 0));
293 } 303 }
294 } 304 }
295 305
@@ -312,11 +322,13 @@ int main(int argc, char **argv) {
312 result = max_state(result, STATE_WARNING); 322 result = max_state(result, STATE_WARNING);
313 } 323 }
314 xasprintf(&performance_data, "%s %s", performance_data, 324 xasprintf(&performance_data, "%s %s", performance_data,
315 perfdata("realpower", (long)ups_realpower, "W", config.check_warn, (long)(config.warning_value), config.check_crit, 325 perfdata("realpower", (long)ups_realpower, "W", config.check_warn,
326 (long)(config.warning_value), config.check_crit,
316 (long)(config.critical_value), true, 0, false, 0)); 327 (long)(config.critical_value), true, 0, false, 0));
317 } else { 328 } else {
318 xasprintf(&performance_data, "%s %s", performance_data, 329 xasprintf(&performance_data, "%s %s", performance_data,
319 perfdata("realpower", (long)ups_realpower, "W", false, 0, false, 0, true, 0, false, 0)); 330 perfdata("realpower", (long)ups_realpower, "W", false, 0, false, 0, true, 0,
331 false, 0));
320 } 332 }
321 } 333 }
322 334
@@ -401,7 +413,8 @@ int get_ups_variable(const char *varname, char *buf, const check_ups_config conf
401 413
402 /* create the command string to send to the UPS daemon */ 414 /* create the command string to send to the UPS daemon */
403 /* Add LOGOUT to avoid read failure logs */ 415 /* Add LOGOUT to avoid read failure logs */
404 int res = snprintf(send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", config.ups_name, varname); 416 int res = snprintf(send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", config.ups_name,
417 varname);
405 if ((res > 0) && ((size_t)res >= sizeof(send_buffer))) { 418 if ((res > 0) && ((size_t)res >= sizeof(send_buffer))) {
406 printf("%s\n", _("UPS name to long for buffer")); 419 printf("%s\n", _("UPS name to long for buffer"));
407 return ERROR; 420 return ERROR;
@@ -410,7 +423,8 @@ int get_ups_variable(const char *varname, char *buf, const check_ups_config conf
410 char temp_buffer[MAX_INPUT_BUFFER]; 423 char temp_buffer[MAX_INPUT_BUFFER];
411 424
412 /* send the command to the daemon and get a response back */ 425 /* send the command to the daemon and get a response back */
413 if (process_tcp_request(config.server_address, config.server_port, send_buffer, temp_buffer, sizeof(temp_buffer)) != STATE_OK) { 426 if (process_tcp_request(config.server_address, config.server_port, send_buffer, temp_buffer,
427 sizeof(temp_buffer)) != STATE_OK) {
414 printf("%s\n", _("Invalid response received from host")); 428 printf("%s\n", _("Invalid response received from host"));
415 return ERROR; 429 return ERROR;
416 } 430 }
@@ -630,7 +644,8 @@ void print_help(void) {
630 printf(" %s\n", "-T, --temperature"); 644 printf(" %s\n", "-T, --temperature");
631 printf(" %s\n", _("Output of temperatures in Celsius")); 645 printf(" %s\n", _("Output of temperatures in Celsius"));
632 printf(" %s\n", "-v, --variable=STRING"); 646 printf(" %s\n", "-v, --variable=STRING");
633 printf(" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER"); 647 printf(" %s %s\n", _("Valid values for STRING are"),
648 "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER");
634 649
635 printf(UT_WARN_CRIT); 650 printf(UT_WARN_CRIT);
636 651