diff options
Diffstat (limited to 'plugins/check_overcr.c')
-rw-r--r-- | plugins/check_overcr.c | 426 |
1 files changed, 187 insertions, 239 deletions
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index 5165c82..599540b 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c | |||
@@ -1,36 +1,36 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_overcr plugin | 3 | * Monitoring check_overcr plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 2000-2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_overcr plugin | 10 | * This file contains the check_overcr plugin |
11 | * | 11 | * |
12 | * This plugin attempts to contact the Over-CR collector daemon running on the | 12 | * This plugin attempts to contact the Over-CR collector daemon running on the |
13 | * remote UNIX server in order to gather the requested system information. | 13 | * remote UNIX server in order to gather the requested system information. |
14 | * | 14 | * |
15 | * | 15 | * |
16 | * This program is free software: you can redistribute it and/or modify | 16 | * This program is free software: you can redistribute it and/or modify |
17 | * it under the terms of the GNU General Public License as published by | 17 | * it under the terms of the GNU General Public License as published by |
18 | * the Free Software Foundation, either version 3 of the License, or | 18 | * the Free Software Foundation, either version 3 of the License, or |
19 | * (at your option) any later version. | 19 | * (at your option) any later version. |
20 | * | 20 | * |
21 | * This program is distributed in the hope that it will be useful, | 21 | * This program is distributed in the hope that it will be useful, |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | * GNU General Public License for more details. | 24 | * GNU General Public License for more details. |
25 | * | 25 | * |
26 | * You should have received a copy of the GNU General Public License | 26 | * You should have received a copy of the GNU General Public License |
27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | * | 28 | * |
29 | * | 29 | * |
30 | *****************************************************************************/ | 30 | *****************************************************************************/ |
31 | 31 | ||
32 | const char *progname = "check_overcr"; | 32 | const char *progname = "check_overcr"; |
33 | const char *copyright = "2000-2007"; | 33 | const char *copyright = "2000-2024"; |
34 | const char *email = "devel@monitoring-plugins.org"; | 34 | const char *email = "devel@monitoring-plugins.org"; |
35 | 35 | ||
36 | #include "common.h" | 36 | #include "common.h" |
@@ -52,27 +52,24 @@ enum { | |||
52 | PORT = 2000 | 52 | PORT = 2000 |
53 | }; | 53 | }; |
54 | 54 | ||
55 | char *server_address = NULL; | 55 | static char *server_address = NULL; |
56 | int server_port = PORT; | 56 | static int server_port = PORT; |
57 | double warning_value = 0L; | 57 | static double warning_value = 0L; |
58 | double critical_value = 0L; | 58 | static double critical_value = 0L; |
59 | bool check_warning_value = false; | 59 | static bool check_warning_value = false; |
60 | bool check_critical_value = false; | 60 | static bool check_critical_value = false; |
61 | enum checkvar vars_to_check = NONE; | 61 | static enum checkvar vars_to_check = NONE; |
62 | int cmd_timeout = 1; | 62 | |
63 | 63 | static int netstat_port = 0; | |
64 | int netstat_port = 0; | 64 | static char *disk_name = NULL; |
65 | char *disk_name = NULL; | 65 | static char *process_name = NULL; |
66 | char *process_name = NULL; | 66 | static char send_buffer[MAX_INPUT_BUFFER]; |
67 | char send_buffer[MAX_INPUT_BUFFER]; | 67 | |
68 | 68 | static int process_arguments(int, char **); | |
69 | int process_arguments (int, char **); | 69 | void print_usage(void); |
70 | void print_usage (void); | 70 | static void print_help(void); |
71 | void print_help (void); | 71 | |
72 | 72 | int main(int argc, char **argv) { | |
73 | int | ||
74 | main (int argc, char **argv) | ||
75 | { | ||
76 | int result = STATE_UNKNOWN; | 73 | int result = STATE_UNKNOWN; |
77 | char recv_buffer[MAX_INPUT_BUFFER]; | 74 | char recv_buffer[MAX_INPUT_BUFFER]; |
78 | char temp_buffer[MAX_INPUT_BUFFER]; | 75 | char temp_buffer[MAX_INPUT_BUFFER]; |
@@ -91,66 +88,62 @@ main (int argc, char **argv) | |||
91 | int uptime_hours = 0; | 88 | int uptime_hours = 0; |
92 | int uptime_minutes = 0; | 89 | int uptime_minutes = 0; |
93 | 90 | ||
94 | setlocale (LC_ALL, ""); | 91 | setlocale(LC_ALL, ""); |
95 | bindtextdomain (PACKAGE, LOCALEDIR); | 92 | bindtextdomain(PACKAGE, LOCALEDIR); |
96 | textdomain (PACKAGE); | 93 | textdomain(PACKAGE); |
97 | 94 | ||
98 | /* Parse extra opts if any */ | 95 | /* Parse extra opts if any */ |
99 | argv=np_extra_opts (&argc, argv, progname); | 96 | argv = np_extra_opts(&argc, argv, progname); |
100 | 97 | ||
101 | if (process_arguments (argc, argv) == ERROR) | 98 | if (process_arguments(argc, argv) == ERROR) |
102 | usage4 (_("Could not parse arguments")); | 99 | usage4(_("Could not parse arguments")); |
103 | 100 | ||
104 | /* initialize alarm signal handling */ | 101 | /* initialize alarm signal handling */ |
105 | signal (SIGALRM, socket_timeout_alarm_handler); | 102 | signal(SIGALRM, socket_timeout_alarm_handler); |
106 | 103 | ||
107 | /* set socket timeout */ | 104 | /* set socket timeout */ |
108 | alarm (socket_timeout); | 105 | alarm(socket_timeout); |
109 | 106 | ||
110 | result = process_tcp_request2 (server_address, | 107 | result = process_tcp_request2(server_address, server_port, send_buffer, recv_buffer, sizeof(recv_buffer)); |
111 | server_port, | ||
112 | send_buffer, | ||
113 | recv_buffer, | ||
114 | sizeof (recv_buffer)); | ||
115 | 108 | ||
116 | switch (vars_to_check) { | 109 | switch (vars_to_check) { |
117 | 110 | ||
118 | case LOAD1: | 111 | case LOAD1: |
119 | case LOAD5: | 112 | case LOAD5: |
120 | case LOAD15: | 113 | case LOAD15: |
121 | 114 | ||
122 | if (result != STATE_OK) | 115 | if (result != STATE_OK) |
123 | die (result, _("Unknown error fetching load data\n")); | 116 | die(result, _("Unknown error fetching load data\n")); |
124 | 117 | ||
125 | temp_ptr = (char *) strtok (recv_buffer, "\r\n"); | 118 | temp_ptr = (char *)strtok(recv_buffer, "\r\n"); |
126 | if (temp_ptr == NULL) | 119 | if (temp_ptr == NULL) |
127 | die (STATE_CRITICAL, _("Invalid response from server - no load information\n")); | 120 | die(STATE_CRITICAL, _("Invalid response from server - no load information\n")); |
128 | else | 121 | else |
129 | load_1min = strtod (temp_ptr, NULL); | 122 | load_1min = strtod(temp_ptr, NULL); |
130 | 123 | ||
131 | temp_ptr = (char *) strtok (NULL, "\r\n"); | 124 | temp_ptr = (char *)strtok(NULL, "\r\n"); |
132 | if (temp_ptr == NULL) | 125 | if (temp_ptr == NULL) |
133 | die (STATE_CRITICAL, _("Invalid response from server after load 1\n")); | 126 | die(STATE_CRITICAL, _("Invalid response from server after load 1\n")); |
134 | else | 127 | else |
135 | load_5min = strtod (temp_ptr, NULL); | 128 | load_5min = strtod(temp_ptr, NULL); |
136 | 129 | ||
137 | temp_ptr = (char *) strtok (NULL, "\r\n"); | 130 | temp_ptr = (char *)strtok(NULL, "\r\n"); |
138 | if (temp_ptr == NULL) | 131 | if (temp_ptr == NULL) |
139 | die (STATE_CRITICAL, _("Invalid response from server after load 5\n")); | 132 | die(STATE_CRITICAL, _("Invalid response from server after load 5\n")); |
140 | else | 133 | else |
141 | load_15min = strtod (temp_ptr, NULL); | 134 | load_15min = strtod(temp_ptr, NULL); |
142 | 135 | ||
143 | switch (vars_to_check) { | 136 | switch (vars_to_check) { |
144 | case LOAD1: | 137 | case LOAD1: |
145 | strcpy (temp_buffer, "1"); | 138 | strcpy(temp_buffer, "1"); |
146 | load = load_1min; | 139 | load = load_1min; |
147 | break; | 140 | break; |
148 | case LOAD5: | 141 | case LOAD5: |
149 | strcpy (temp_buffer, "5"); | 142 | strcpy(temp_buffer, "5"); |
150 | load = load_5min; | 143 | load = load_5min; |
151 | break; | 144 | break; |
152 | default: | 145 | default: |
153 | strcpy (temp_buffer, "15"); | 146 | strcpy(temp_buffer, "15"); |
154 | load = load_15min; | 147 | load = load_15min; |
155 | break; | 148 | break; |
156 | } | 149 | } |
@@ -160,98 +153,82 @@ main (int argc, char **argv) | |||
160 | else if (check_warning_value && (load >= warning_value)) | 153 | else if (check_warning_value && (load >= warning_value)) |
161 | result = STATE_WARNING; | 154 | result = STATE_WARNING; |
162 | 155 | ||
163 | die (result, | 156 | die(result, _("Load %s - %s-min load average = %0.2f"), state_text(result), temp_buffer, load); |
164 | _("Load %s - %s-min load average = %0.2f"), | ||
165 | state_text(result), | ||
166 | temp_buffer, | ||
167 | load); | ||
168 | 157 | ||
169 | break; | 158 | break; |
170 | 159 | ||
171 | case DPU: | 160 | case DPU: |
172 | 161 | ||
173 | if (result != STATE_OK) | 162 | if (result != STATE_OK) |
174 | die (result, _("Unknown error fetching disk data\n")); | 163 | die(result, _("Unknown error fetching disk data\n")); |
175 | 164 | ||
176 | for (temp_ptr = (char *) strtok (recv_buffer, " "); | 165 | for (temp_ptr = (char *)strtok(recv_buffer, " "); temp_ptr != NULL; temp_ptr = (char *)strtok(NULL, " ")) { |
177 | temp_ptr != NULL; | ||
178 | temp_ptr = (char *) strtok (NULL, " ")) { | ||
179 | 166 | ||
180 | if (!strcmp (temp_ptr, disk_name)) { | 167 | if (!strcmp(temp_ptr, disk_name)) { |
181 | found_disk = true; | 168 | found_disk = true; |
182 | temp_ptr = (char *) strtok (NULL, "%"); | 169 | temp_ptr = (char *)strtok(NULL, "%"); |
183 | if (temp_ptr == NULL) | 170 | if (temp_ptr == NULL) |
184 | die (STATE_CRITICAL, _("Invalid response from server\n")); | 171 | die(STATE_CRITICAL, _("Invalid response from server\n")); |
185 | else | 172 | else |
186 | percent_used_disk_space = strtoul (temp_ptr, NULL, 10); | 173 | percent_used_disk_space = strtoul(temp_ptr, NULL, 10); |
187 | break; | 174 | break; |
188 | } | 175 | } |
189 | 176 | ||
190 | temp_ptr = (char *) strtok (NULL, "\r\n"); | 177 | temp_ptr = (char *)strtok(NULL, "\r\n"); |
191 | } | 178 | } |
192 | 179 | ||
193 | /* error if we couldn't find the info for the disk */ | 180 | /* error if we couldn't find the info for the disk */ |
194 | if (!found_disk) | 181 | if (!found_disk) |
195 | die (STATE_CRITICAL, | 182 | die(STATE_CRITICAL, "CRITICAL - Disk '%s' non-existent or not mounted", disk_name); |
196 | "CRITICAL - Disk '%s' non-existent or not mounted", | ||
197 | disk_name); | ||
198 | 183 | ||
199 | if (check_critical_value && (percent_used_disk_space >= critical_value)) | 184 | if (check_critical_value && (percent_used_disk_space >= critical_value)) |
200 | result = STATE_CRITICAL; | 185 | result = STATE_CRITICAL; |
201 | else if (check_warning_value && (percent_used_disk_space >= warning_value)) | 186 | else if (check_warning_value && (percent_used_disk_space >= warning_value)) |
202 | result = STATE_WARNING; | 187 | result = STATE_WARNING; |
203 | 188 | ||
204 | die (result, "Disk %s - %lu%% used on %s", state_text(result), percent_used_disk_space, disk_name); | 189 | die(result, "Disk %s - %lu%% used on %s", state_text(result), percent_used_disk_space, disk_name); |
205 | 190 | ||
206 | break; | 191 | break; |
207 | 192 | ||
208 | case NETSTAT: | 193 | case NETSTAT: |
209 | 194 | ||
210 | if (result != STATE_OK) | 195 | if (result != STATE_OK) |
211 | die (result, _("Unknown error fetching network status\n")); | 196 | die(result, _("Unknown error fetching network status\n")); |
212 | else | 197 | else |
213 | port_connections = strtod (recv_buffer, NULL); | 198 | port_connections = strtod(recv_buffer, NULL); |
214 | 199 | ||
215 | if (check_critical_value && (port_connections >= critical_value)) | 200 | if (check_critical_value && (port_connections >= critical_value)) |
216 | result = STATE_CRITICAL; | 201 | result = STATE_CRITICAL; |
217 | else if (check_warning_value && (port_connections >= warning_value)) | 202 | else if (check_warning_value && (port_connections >= warning_value)) |
218 | result = STATE_WARNING; | 203 | result = STATE_WARNING; |
219 | 204 | ||
220 | die (result, | 205 | die(result, _("Net %s - %d connection%s on port %d"), state_text(result), port_connections, (port_connections == 1) ? "" : "s", |
221 | _("Net %s - %d connection%s on port %d"), | 206 | netstat_port); |
222 | state_text(result), | ||
223 | port_connections, | ||
224 | (port_connections == 1) ? "" : "s", | ||
225 | netstat_port); | ||
226 | 207 | ||
227 | break; | 208 | break; |
228 | 209 | ||
229 | case PROCS: | 210 | case PROCS: |
230 | 211 | ||
231 | if (result != STATE_OK) | 212 | if (result != STATE_OK) |
232 | die (result, _("Unknown error fetching process status\n")); | 213 | die(result, _("Unknown error fetching process status\n")); |
233 | 214 | ||
234 | temp_ptr = (char *) strtok (recv_buffer, "("); | 215 | temp_ptr = (char *)strtok(recv_buffer, "("); |
235 | if (temp_ptr == NULL) | 216 | if (temp_ptr == NULL) |
236 | die (STATE_CRITICAL, _("Invalid response from server\n")); | 217 | die(STATE_CRITICAL, _("Invalid response from server\n")); |
237 | 218 | ||
238 | temp_ptr = (char *) strtok (NULL, ")"); | 219 | temp_ptr = (char *)strtok(NULL, ")"); |
239 | if (temp_ptr == NULL) | 220 | if (temp_ptr == NULL) |
240 | die (STATE_CRITICAL, _("Invalid response from server\n")); | 221 | die(STATE_CRITICAL, _("Invalid response from server\n")); |
241 | else | 222 | else |
242 | processes = strtod (temp_ptr, NULL); | 223 | processes = strtod(temp_ptr, NULL); |
243 | 224 | ||
244 | if (check_critical_value && (processes >= critical_value)) | 225 | if (check_critical_value && (processes >= critical_value)) |
245 | result = STATE_CRITICAL; | 226 | result = STATE_CRITICAL; |
246 | else if (check_warning_value && (processes >= warning_value)) | 227 | else if (check_warning_value && (processes >= warning_value)) |
247 | result = STATE_WARNING; | 228 | result = STATE_WARNING; |
248 | 229 | ||
249 | die (result, | 230 | die(result, _("Process %s - %d instance%s of %s running"), state_text(result), processes, (processes == 1) ? "" : "s", |
250 | _("Process %s - %d instance%s of %s running"), | 231 | process_name); |
251 | state_text(result), | ||
252 | processes, | ||
253 | (processes == 1) ? "" : "s", | ||
254 | process_name); | ||
255 | break; | 232 | break; |
256 | 233 | ||
257 | case UPTIME: | 234 | case UPTIME: |
@@ -259,8 +236,8 @@ main (int argc, char **argv) | |||
259 | if (result != STATE_OK) | 236 | if (result != STATE_OK) |
260 | return result; | 237 | return result; |
261 | 238 | ||
262 | uptime_raw_hours = strtod (recv_buffer, NULL); | 239 | uptime_raw_hours = strtod(recv_buffer, NULL); |
263 | uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0); | 240 | uptime_raw_minutes = (unsigned long)(uptime_raw_hours * 60.0); |
264 | 241 | ||
265 | if (check_critical_value && (uptime_raw_minutes <= critical_value)) | 242 | if (check_critical_value && (uptime_raw_minutes <= critical_value)) |
266 | result = STATE_CRITICAL; | 243 | result = STATE_CRITICAL; |
@@ -273,46 +250,31 @@ main (int argc, char **argv) | |||
273 | uptime_raw_minutes %= 60; | 250 | uptime_raw_minutes %= 60; |
274 | uptime_minutes = uptime_raw_minutes; | 251 | uptime_minutes = uptime_raw_minutes; |
275 | 252 | ||
276 | die (result, | 253 | die(result, _("Uptime %s - Up %d days %d hours %d minutes"), state_text(result), uptime_days, uptime_hours, uptime_minutes); |
277 | _("Uptime %s - Up %d days %d hours %d minutes"), | ||
278 | state_text(result), | ||
279 | uptime_days, | ||
280 | uptime_hours, | ||
281 | uptime_minutes); | ||
282 | break; | 254 | break; |
283 | 255 | ||
284 | default: | 256 | default: |
285 | die (STATE_UNKNOWN, _("Nothing to check!\n")); | 257 | die(STATE_UNKNOWN, _("Nothing to check!\n")); |
286 | break; | 258 | break; |
287 | } | 259 | } |
288 | } | 260 | } |
289 | 261 | ||
290 | |||
291 | /* process command-line arguments */ | 262 | /* process command-line arguments */ |
292 | int | 263 | int process_arguments(int argc, char **argv) { |
293 | process_arguments (int argc, char **argv) | ||
294 | { | ||
295 | int c; | 264 | int c; |
296 | 265 | ||
297 | int option = 0; | 266 | int option = 0; |
298 | static struct option longopts[] = { | 267 | static struct option longopts[] = { |
299 | {"port", required_argument, 0, 'p'}, | 268 | {"port", required_argument, 0, 'p'}, {"timeout", required_argument, 0, 't'}, {"critical", required_argument, 0, 'c'}, |
300 | {"timeout", required_argument, 0, 't'}, | 269 | {"warning", required_argument, 0, 'w'}, {"variable", required_argument, 0, 'v'}, {"hostname", required_argument, 0, 'H'}, |
301 | {"critical", required_argument, 0, 'c'}, | 270 | {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; |
302 | {"warning", required_argument, 0, 'w'}, | ||
303 | {"variable", required_argument, 0, 'v'}, | ||
304 | {"hostname", required_argument, 0, 'H'}, | ||
305 | {"version", no_argument, 0, 'V'}, | ||
306 | {"help", no_argument, 0, 'h'}, | ||
307 | {0, 0, 0, 0} | ||
308 | }; | ||
309 | 271 | ||
310 | /* no options were supplied */ | 272 | /* no options were supplied */ |
311 | if (argc < 2) | 273 | if (argc < 2) |
312 | return ERROR; | 274 | return ERROR; |
313 | 275 | ||
314 | /* backwards compatibility */ | 276 | /* backwards compatibility */ |
315 | if (!is_option (argv[1])) { | 277 | if (!is_option(argv[1])) { |
316 | server_address = argv[1]; | 278 | server_address = argv[1]; |
317 | argv[1] = argv[0]; | 279 | argv[1] = argv[0]; |
318 | argv = &argv[1]; | 280 | argv = &argv[1]; |
@@ -320,150 +282,136 @@ process_arguments (int argc, char **argv) | |||
320 | } | 282 | } |
321 | 283 | ||
322 | for (c = 1; c < argc; c++) { | 284 | for (c = 1; c < argc; c++) { |
323 | if (strcmp ("-to", argv[c]) == 0) | 285 | if (strcmp("-to", argv[c]) == 0) |
324 | strcpy (argv[c], "-t"); | 286 | strcpy(argv[c], "-t"); |
325 | else if (strcmp ("-wv", argv[c]) == 0) | 287 | else if (strcmp("-wv", argv[c]) == 0) |
326 | strcpy (argv[c], "-w"); | 288 | strcpy(argv[c], "-w"); |
327 | else if (strcmp ("-cv", argv[c]) == 0) | 289 | else if (strcmp("-cv", argv[c]) == 0) |
328 | strcpy (argv[c], "-c"); | 290 | strcpy(argv[c], "-c"); |
329 | } | 291 | } |
330 | 292 | ||
331 | while (1) { | 293 | while (1) { |
332 | c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", longopts, | 294 | c = getopt_long(argc, argv, "+hVH:t:c:w:p:v:", longopts, &option); |
333 | &option); | ||
334 | 295 | ||
335 | if (c == -1 || c == EOF || c == 1) | 296 | if (c == -1 || c == EOF || c == 1) |
336 | break; | 297 | break; |
337 | 298 | ||
338 | switch (c) { | 299 | switch (c) { |
339 | case '?': /* print short usage statement if args not parsable */ | 300 | case '?': /* print short usage statement if args not parsable */ |
340 | usage5 (); | 301 | usage5(); |
341 | case 'h': /* help */ | 302 | case 'h': /* help */ |
342 | print_help (); | 303 | print_help(); |
343 | exit (STATE_UNKNOWN); | 304 | exit(STATE_UNKNOWN); |
344 | case 'V': /* version */ | 305 | case 'V': /* version */ |
345 | print_revision (progname, NP_VERSION); | 306 | print_revision(progname, NP_VERSION); |
346 | exit (STATE_UNKNOWN); | 307 | exit(STATE_UNKNOWN); |
347 | case 'H': /* hostname */ | 308 | case 'H': /* hostname */ |
348 | server_address = optarg; | 309 | server_address = optarg; |
349 | break; | 310 | break; |
350 | case 'p': /* port */ | 311 | case 'p': /* port */ |
351 | if (is_intnonneg (optarg)) | 312 | if (is_intnonneg(optarg)) |
352 | server_port = atoi (optarg); | 313 | server_port = atoi(optarg); |
353 | else | 314 | else |
354 | die (STATE_UNKNOWN, | 315 | die(STATE_UNKNOWN, _("Server port an integer\n")); |
355 | _("Server port an integer\n")); | ||
356 | break; | 316 | break; |
357 | case 'v': /* variable */ | 317 | case 'v': /* variable */ |
358 | if (strcmp (optarg, "LOAD") == 0) { | 318 | if (strcmp(optarg, "LOAD") == 0) { |
359 | strcpy (send_buffer, "LOAD\r\nQUIT\r\n"); | 319 | strcpy(send_buffer, "LOAD\r\nQUIT\r\n"); |
360 | if (strcmp (optarg, "LOAD1") == 0) | 320 | if (strcmp(optarg, "LOAD1") == 0) |
361 | vars_to_check = LOAD1; | 321 | vars_to_check = LOAD1; |
362 | else if (strcmp (optarg, "LOAD5") == 0) | 322 | else if (strcmp(optarg, "LOAD5") == 0) |
363 | vars_to_check = LOAD5; | 323 | vars_to_check = LOAD5; |
364 | else if (strcmp (optarg, "LOAD15") == 0) | 324 | else if (strcmp(optarg, "LOAD15") == 0) |
365 | vars_to_check = LOAD15; | 325 | vars_to_check = LOAD15; |
366 | } | 326 | } else if (strcmp(optarg, "UPTIME") == 0) { |
367 | else if (strcmp (optarg, "UPTIME") == 0) { | ||
368 | vars_to_check = UPTIME; | 327 | vars_to_check = UPTIME; |
369 | strcpy (send_buffer, "UPTIME\r\n"); | 328 | strcpy(send_buffer, "UPTIME\r\n"); |
370 | } | 329 | } else if (strstr(optarg, "PROC") == optarg) { |
371 | else if (strstr (optarg, "PROC") == optarg) { | ||
372 | vars_to_check = PROCS; | 330 | vars_to_check = PROCS; |
373 | process_name = strscpy (process_name, optarg + 4); | 331 | process_name = strscpy(process_name, optarg + 4); |
374 | sprintf (send_buffer, "PROCESS %s\r\n", process_name); | 332 | sprintf(send_buffer, "PROCESS %s\r\n", process_name); |
375 | } | 333 | } else if (strstr(optarg, "NET") == optarg) { |
376 | else if (strstr (optarg, "NET") == optarg) { | ||
377 | vars_to_check = NETSTAT; | 334 | vars_to_check = NETSTAT; |
378 | netstat_port = atoi (optarg + 3); | 335 | netstat_port = atoi(optarg + 3); |
379 | sprintf (send_buffer, "NETSTAT %d\r\n", netstat_port); | 336 | sprintf(send_buffer, "NETSTAT %d\r\n", netstat_port); |
380 | } | 337 | } else if (strstr(optarg, "DPU") == optarg) { |
381 | else if (strstr (optarg, "DPU") == optarg) { | ||
382 | vars_to_check = DPU; | 338 | vars_to_check = DPU; |
383 | strcpy (send_buffer, "DISKSPACE\r\n"); | 339 | strcpy(send_buffer, "DISKSPACE\r\n"); |
384 | disk_name = strscpy (disk_name, optarg + 3); | 340 | disk_name = strscpy(disk_name, optarg + 3); |
385 | } | 341 | } else |
386 | else | ||
387 | return ERROR; | 342 | return ERROR; |
388 | break; | 343 | break; |
389 | case 'w': /* warning threshold */ | 344 | case 'w': /* warning threshold */ |
390 | warning_value = strtoul (optarg, NULL, 10); | 345 | warning_value = strtoul(optarg, NULL, 10); |
391 | check_warning_value = true; | 346 | check_warning_value = true; |
392 | break; | 347 | break; |
393 | case 'c': /* critical threshold */ | 348 | case 'c': /* critical threshold */ |
394 | critical_value = strtoul (optarg, NULL, 10); | 349 | critical_value = strtoul(optarg, NULL, 10); |
395 | check_critical_value = true; | 350 | check_critical_value = true; |
396 | break; | 351 | break; |
397 | case 't': /* timeout */ | 352 | case 't': /* timeout */ |
398 | socket_timeout = atoi (optarg); | 353 | socket_timeout = atoi(optarg); |
399 | if (socket_timeout <= 0) | 354 | if (socket_timeout <= 0) |
400 | return ERROR; | 355 | return ERROR; |
401 | } | 356 | } |
402 | |||
403 | } | 357 | } |
404 | return OK; | 358 | return OK; |
405 | } | 359 | } |
406 | 360 | ||
407 | 361 | void print_help(void) { | |
408 | void | ||
409 | print_help (void) | ||
410 | { | ||
411 | char *myport; | 362 | char *myport; |
412 | xasprintf (&myport, "%d", PORT); | 363 | xasprintf(&myport, "%d", PORT); |
413 | 364 | ||
414 | print_revision (progname, NP_VERSION); | 365 | print_revision(progname, NP_VERSION); |
415 | 366 | ||
416 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | 367 | printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
417 | printf (COPYRIGHT, copyright, email); | 368 | printf(COPYRIGHT, copyright, email); |
418 | 369 | ||
419 | printf ("%s\n", _("This plugin attempts to contact the Over-CR collector daemon running on the")); | 370 | printf("%s\n", _("This plugin attempts to contact the Over-CR collector daemon running on the")); |
420 | printf ("%s\n", _("remote UNIX server in order to gather the requested system information.")); | 371 | printf("%s\n", _("remote UNIX server in order to gather the requested system information.")); |
421 | 372 | ||
422 | printf ("\n\n"); | 373 | printf("\n\n"); |
423 | 374 | ||
424 | print_usage (); | 375 | print_usage(); |
425 | 376 | ||
426 | printf (UT_HELP_VRSN); | 377 | printf(UT_HELP_VRSN); |
427 | printf (UT_EXTRA_OPTS); | 378 | printf(UT_EXTRA_OPTS); |
428 | 379 | ||
429 | printf (UT_HOST_PORT, 'p', myport); | 380 | printf(UT_HOST_PORT, 'p', myport); |
430 | 381 | ||
431 | printf (" %s\n", "-w, --warning=INTEGER"); | 382 | printf(" %s\n", "-w, --warning=INTEGER"); |
432 | printf (" %s\n", _("Threshold which will result in a warning status")); | 383 | printf(" %s\n", _("Threshold which will result in a warning status")); |
433 | printf (" %s\n", "-c, --critical=INTEGER"); | 384 | printf(" %s\n", "-c, --critical=INTEGER"); |
434 | printf (" %s\n", _("Threshold which will result in a critical status")); | 385 | printf(" %s\n", _("Threshold which will result in a critical status")); |
435 | printf (" %s\n", "-v, --variable=STRING"); | 386 | printf(" %s\n", "-v, --variable=STRING"); |
436 | printf (" %s\n", _("Variable to check. Valid variables include:")); | 387 | printf(" %s\n", _("Variable to check. Valid variables include:")); |
437 | printf (" %s\n", _("LOAD1 = 1 minute average CPU load")); | 388 | printf(" %s\n", _("LOAD1 = 1 minute average CPU load")); |
438 | printf (" %s\n", _("LOAD5 = 5 minute average CPU load")); | 389 | printf(" %s\n", _("LOAD5 = 5 minute average CPU load")); |
439 | printf (" %s\n", _("LOAD15 = 15 minute average CPU load")); | 390 | printf(" %s\n", _("LOAD15 = 15 minute average CPU load")); |
440 | printf (" %s\n", _("DPU<filesys> = percent used disk space on filesystem <filesys>")); | 391 | printf(" %s\n", _("DPU<filesys> = percent used disk space on filesystem <filesys>")); |
441 | printf (" %s\n", _("PROC<process> = number of running processes with name <process>")); | 392 | printf(" %s\n", _("PROC<process> = number of running processes with name <process>")); |
442 | printf (" %s\n", _("NET<port> = number of active connections on TCP port <port>")); | 393 | printf(" %s\n", _("NET<port> = number of active connections on TCP port <port>")); |
443 | printf (" %s\n", _("UPTIME = system uptime in seconds")); | 394 | printf(" %s\n", _("UPTIME = system uptime in seconds")); |
444 | 395 | ||
445 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 396 | printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
446 | 397 | ||
447 | printf (UT_VERBOSE); | 398 | printf(UT_VERBOSE); |
448 | 399 | ||
449 | printf ("\n"); | 400 | printf("\n"); |
450 | printf ("%s\n", _("This plugin requires that Eric Molitors' Over-CR collector daemon be")); | 401 | printf("%s\n", _("This plugin requires that Eric Molitors' Over-CR collector daemon be")); |
451 | printf ("%s\n", _("running on the remote server.")); | 402 | printf("%s\n", _("running on the remote server.")); |
452 | printf ("%s\n", _("Over-CR can be downloaded from http://www.molitor.org/overcr")); | 403 | printf("%s\n", _("Over-CR can be downloaded from http://www.molitor.org/overcr")); |
453 | printf ("%s\n", _("This plugin was tested with version 0.99.53 of the Over-CR collector")); | 404 | printf("%s\n", _("This plugin was tested with version 0.99.53 of the Over-CR collector")); |
454 | 405 | ||
455 | printf ("\n"); | 406 | printf("\n"); |
456 | printf ("%s\n", _("Notes:")); | 407 | printf("%s\n", _("Notes:")); |
457 | printf (" %s\n", _("For the available options, the critical threshold value should always be")); | 408 | printf(" %s\n", _("For the available options, the critical threshold value should always be")); |
458 | printf (" %s\n", _("higher than the warning threshold value, EXCEPT with the uptime variable")); | 409 | printf(" %s\n", _("higher than the warning threshold value, EXCEPT with the uptime variable")); |
459 | 410 | ||
460 | printf (UT_SUPPORT); | 411 | printf(UT_SUPPORT); |
461 | } | 412 | } |
462 | 413 | ||
463 | 414 | void print_usage(void) { | |
464 | void | 415 | printf("%s\n", _("Usage:")); |
465 | print_usage (void) | 416 | printf("%s -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]\n", progname); |
466 | { | ||
467 | printf ("%s\n", _("Usage:")); | ||
468 | printf ("%s -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]\n", progname); | ||
469 | } | 417 | } |