diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-09 13:36:49 (GMT) |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-09 13:36:49 (GMT) |
commit | 90b45deb4138efb47efbdd98a4aede1aebb47146 (patch) | |
tree | d27a0180ce89542ee546a0b1e958b68a114ea7ce /plugins/check_ups.c | |
parent | 4784cac1f017a67978c2f3f2af75b161d1ef33c0 (diff) | |
download | monitoring-plugins-90b45deb4138efb47efbdd98a4aede1aebb47146.tar.gz |
more pedantic compiler warnings
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@674 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_ups.c')
-rw-r--r-- | plugins/check_ups.c | 148 |
1 files changed, 81 insertions, 67 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 499b922..fcee747 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -29,68 +29,6 @@ enum { | |||
29 | PORT = 3493 | 29 | PORT = 3493 |
30 | }; | 30 | }; |
31 | 31 | ||
32 | void | ||
33 | print_usage (void) | ||
34 | { | ||
35 | printf (_("\ | ||
36 | Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\ | ||
37 | [-t timeout] [-v]\n"), progname); | ||
38 | printf (_(UT_HLP_VRS), progname, progname); | ||
39 | } | ||
40 | |||
41 | void | ||
42 | print_help (void) | ||
43 | { | ||
44 | char *myport; | ||
45 | asprintf (&myport, "%d", PORT); | ||
46 | |||
47 | print_revision (progname, revision); | ||
48 | |||
49 | printf (_("Copyright (c) 2000 Tom Shields")); | ||
50 | printf (_(COPYRIGHT), copyright, email); | ||
51 | |||
52 | printf (_("This plugin tests the UPS service on the specified host.\n\ | ||
53 | Network UPS Tools from www.exploits.org must be running for this plugin to\n\ | ||
54 | work.\n\n")); | ||
55 | |||
56 | print_usage (); | ||
57 | |||
58 | printf (_(UT_HELP_VRSN)); | ||
59 | |||
60 | printf (_(UT_HOST_PORT), 'p', myport); | ||
61 | |||
62 | printf (_("\ | ||
63 | -u, --ups=STRING\n\ | ||
64 | Name of UPS\n")); | ||
65 | |||
66 | printf (_(UT_WARN_CRIT)); | ||
67 | |||
68 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
69 | |||
70 | printf (_(UT_VERBOSE)); | ||
71 | |||
72 | printf (_("\ | ||
73 | This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\ | ||
74 | Supply) on a local or remote host. If the UPS is online or calibrating, the\n\ | ||
75 | plugin will return an OK state. If the battery is on it will return a WARNING\n\ | ||
76 | state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\ | ||
77 | state.\n\n")); | ||
78 | |||
79 | printf (_("\ | ||
80 | You may also specify a variable to check [such as temperature, utility voltage,\n\ | ||
81 | battery load, etc.] as well as warning and critical thresholds for the value of\n\ | ||
82 | that variable. If the remote host has multiple UPS that are being monitored you\n\ | ||
83 | will have to use the [ups] option to specify which UPS to check.\n\n")); | ||
84 | |||
85 | printf (_("Notes:\n\n\ | ||
86 | This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\ | ||
87 | Smart UPS Tools be installed on the remote host. If you do not have the\n\ | ||
88 | package installed on your system, you can download it from\n\ | ||
89 | http://www.exploits.org/nut\n\n")); | ||
90 | |||
91 | printf (_(UT_SUPPORT)); | ||
92 | } | ||
93 | |||
94 | #define CHECK_NONE 0 | 32 | #define CHECK_NONE 0 |
95 | 33 | ||
96 | #define UPS_NONE 0 /* no supported options */ | 34 | #define UPS_NONE 0 /* no supported options */ |
@@ -110,7 +48,7 @@ http://www.exploits.org/nut\n\n")); | |||
110 | #define UPSSTATUS_UNKOWN 64 | 48 | #define UPSSTATUS_UNKOWN 64 |
111 | 49 | ||
112 | int server_port = PORT; | 50 | int server_port = PORT; |
113 | char *server_address = "127.0.0.1"; | 51 | char *server_address; |
114 | char *ups_name = NULL; | 52 | char *ups_name = NULL; |
115 | double warning_value = 0.0; | 53 | double warning_value = 0.0; |
116 | double critical_value = 0.0; | 54 | double critical_value = 0.0; |
@@ -124,14 +62,16 @@ double ups_utility_voltage = 0.0; | |||
124 | double ups_battery_percent = 0.0; | 62 | double ups_battery_percent = 0.0; |
125 | double ups_load_percent = 0.0; | 63 | double ups_load_percent = 0.0; |
126 | double ups_temperature = 0.0; | 64 | double ups_temperature = 0.0; |
127 | char *ups_status = "N/A"; | 65 | char *ups_status; |
128 | 66 | ||
129 | int determine_status (void); | 67 | int determine_status (void); |
130 | int determine_supported_vars (void); | 68 | int determine_supported_vars (void); |
131 | int get_ups_variable (const char *, char *, int); | 69 | int get_ups_variable (const char *, char *, size_t); |
132 | 70 | ||
133 | int process_arguments (int, char **); | 71 | int process_arguments (int, char **); |
134 | int validate_arguments (void); | 72 | int validate_arguments (void); |
73 | void print_help (void); | ||
74 | void print_usage (void); | ||
135 | 75 | ||
136 | int | 76 | int |
137 | main (int argc, char **argv) | 77 | main (int argc, char **argv) |
@@ -141,6 +81,7 @@ main (int argc, char **argv) | |||
141 | char temp_buffer[MAX_INPUT_BUFFER]; | 81 | char temp_buffer[MAX_INPUT_BUFFER]; |
142 | 82 | ||
143 | double ups_utility_deviation = 0.0; | 83 | double ups_utility_deviation = 0.0; |
84 | ups_status = strdup ("N/A"); | ||
144 | 85 | ||
145 | if (process_arguments (argc, argv) != OK) | 86 | if (process_arguments (argc, argv) != OK) |
146 | usage ("Invalid command arguments supplied\n"); | 87 | usage ("Invalid command arguments supplied\n"); |
@@ -160,7 +101,7 @@ main (int argc, char **argv) | |||
160 | 101 | ||
161 | if (determine_status () != OK) | 102 | if (determine_status () != OK) |
162 | return STATE_CRITICAL; | 103 | return STATE_CRITICAL; |
163 | asprintf (&ups_status, ""); | 104 | ups_status = strdup (""); |
164 | result = STATE_OK; | 105 | result = STATE_OK; |
165 | 106 | ||
166 | if (status & UPSSTATUS_OFF) { | 107 | if (status & UPSSTATUS_OFF) { |
@@ -395,7 +336,7 @@ determine_supported_vars (void) | |||
395 | 336 | ||
396 | /* gets a variable value for a specific UPS */ | 337 | /* gets a variable value for a specific UPS */ |
397 | int | 338 | int |
398 | get_ups_variable (const char *varname, char *buf, int buflen) | 339 | get_ups_variable (const char *varname, char *buf, size_t buflen) |
399 | { | 340 | { |
400 | /* char command[MAX_INPUT_BUFFER]; */ | 341 | /* char command[MAX_INPUT_BUFFER]; */ |
401 | char temp_buffer[MAX_INPUT_BUFFER]; | 342 | char temp_buffer[MAX_INPUT_BUFFER]; |
@@ -569,6 +510,9 @@ process_arguments (int argc, char **argv) | |||
569 | usage ("Invalid host name"); | 510 | usage ("Invalid host name"); |
570 | } | 511 | } |
571 | 512 | ||
513 | if (server_address == NULL) | ||
514 | server_address = strdup("127.0.0.1"); | ||
515 | |||
572 | return validate_arguments(); | 516 | return validate_arguments(); |
573 | } | 517 | } |
574 | 518 | ||
@@ -581,3 +525,73 @@ validate_arguments (void) | |||
581 | { | 525 | { |
582 | return OK; | 526 | return OK; |
583 | } | 527 | } |
528 | |||
529 | |||
530 | |||
531 | |||
532 | |||
533 | |||
534 | void | ||
535 | print_help (void) | ||
536 | { | ||
537 | char *myport; | ||
538 | asprintf (&myport, "%d", PORT); | ||
539 | |||
540 | print_revision (progname, revision); | ||
541 | |||
542 | printf (_("Copyright (c) 2000 Tom Shields")); | ||
543 | printf (_(COPYRIGHT), copyright, email); | ||
544 | |||
545 | printf (_("This plugin tests the UPS service on the specified host.\n\ | ||
546 | Network UPS Tools from www.exploits.org must be running for this plugin to\n\ | ||
547 | work.\n\n")); | ||
548 | |||
549 | print_usage (); | ||
550 | |||
551 | printf (_(UT_HELP_VRSN)); | ||
552 | |||
553 | printf (_(UT_HOST_PORT), 'p', myport); | ||
554 | |||
555 | printf (_("\ | ||
556 | -u, --ups=STRING\n\ | ||
557 | Name of UPS\n")); | ||
558 | |||
559 | printf (_(UT_WARN_CRIT)); | ||
560 | |||
561 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
562 | |||
563 | printf (_(UT_VERBOSE)); | ||
564 | |||
565 | printf (_("\ | ||
566 | This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\ | ||
567 | Supply) on a local or remote host. If the UPS is online or calibrating, the\n\ | ||
568 | plugin will return an OK state. If the battery is on it will return a WARNING\n\ | ||
569 | state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\ | ||
570 | state.\n\n")); | ||
571 | |||
572 | printf (_("\ | ||
573 | You may also specify a variable to check [such as temperature, utility voltage,\n\ | ||
574 | battery load, etc.] as well as warning and critical thresholds for the value of\n\ | ||
575 | that variable. If the remote host has multiple UPS that are being monitored you\n\ | ||
576 | will have to use the [ups] option to specify which UPS to check.\n\n")); | ||
577 | |||
578 | printf (_("Notes:\n\n\ | ||
579 | This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\ | ||
580 | Smart UPS Tools be installed on the remote host. If you do not have the\n\ | ||
581 | package installed on your system, you can download it from\n\ | ||
582 | http://www.exploits.org/nut\n\n")); | ||
583 | |||
584 | printf (_(UT_SUPPORT)); | ||
585 | } | ||
586 | |||
587 | |||
588 | |||
589 | |||
590 | void | ||
591 | print_usage (void) | ||
592 | { | ||
593 | printf (_("\ | ||
594 | Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\ | ||
595 | [-t timeout] [-v]\n"), progname); | ||
596 | printf (_(UT_HLP_VRS), progname, progname); | ||
597 | } | ||