diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-10 06:53:22 (GMT) |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-10 06:53:22 (GMT) |
commit | f4f92be60c94fd4e0dd4b2b4b3101543eedb706a (patch) | |
tree | 28d25bd0ab624d82435823c940a186370947ad4d | |
parent | cbf702f51f839af5a8e9c66bdae7d6a3dc363ace (diff) | |
download | monitoring-plugins-f4f92be60c94fd4e0dd4b2b4b3101543eedb706a.tar.gz |
the last round of pedantic compiler warnings
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@676 f882894a-f735-0410-b71e-b25c423dba1c
34 files changed, 1090 insertions, 1060 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 59e8ea0..b0aa189 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -169,8 +169,8 @@ process_arguments (int argc, char **argv) | |||
169 | int c; | 169 | int c; |
170 | char *p1, *p2; | 170 | char *p1, *p2; |
171 | 171 | ||
172 | int option_index = 0; | 172 | int option = 0; |
173 | static struct option long_options[] = { | 173 | static struct option longopts[] = { |
174 | {"version", no_argument, 0, 'V'}, | 174 | {"version", no_argument, 0, 'V'}, |
175 | {"help", no_argument, 0, 'h'}, | 175 | {"help", no_argument, 0, 'h'}, |
176 | {"verbose", no_argument, 0, 'v'}, | 176 | {"verbose", no_argument, 0, 'v'}, |
@@ -200,8 +200,8 @@ process_arguments (int argc, char **argv) | |||
200 | strcpy (argv[c], "-t"); | 200 | strcpy (argv[c], "-t"); |
201 | 201 | ||
202 | while (1) { | 202 | while (1) { |
203 | c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", long_options, | 203 | c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", longopts, |
204 | &option_index); | 204 | &option); |
205 | 205 | ||
206 | if (c == -1 || c == EOF) | 206 | if (c == -1 || c == EOF) |
207 | break; | 207 | break; |
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index ff16059..f376e30 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -160,8 +160,8 @@ process_arguments (int argc, char **argv) | |||
160 | { | 160 | { |
161 | int c; | 161 | int c; |
162 | 162 | ||
163 | int option_index = 0; | 163 | int option = 0; |
164 | static struct option long_options[] = { | 164 | static struct option longopts[] = { |
165 | {"hostname", required_argument, 0, 'H'}, | 165 | {"hostname", required_argument, 0, 'H'}, |
166 | {"query_address", required_argument, 0, 'e'}, | 166 | {"query_address", required_argument, 0, 'e'}, |
167 | {"verbose", no_argument, 0, 'v'}, | 167 | {"verbose", no_argument, 0, 'v'}, |
@@ -174,7 +174,7 @@ process_arguments (int argc, char **argv) | |||
174 | return ERROR; | 174 | return ERROR; |
175 | 175 | ||
176 | while (1) { | 176 | while (1) { |
177 | c = getopt_long (argc, argv, "hVvt:l:H:", long_options, &option_index); | 177 | c = getopt_long (argc, argv, "hVvt:l:H:", longopts, &option); |
178 | 178 | ||
179 | if (c == -1 || c == EOF) | 179 | if (c == -1 || c == EOF) |
180 | break; | 180 | break; |
@@ -300,7 +300,7 @@ print_help (void) | |||
300 | 300 | ||
301 | printf (_(UT_VERBOSE)); | 301 | printf (_(UT_VERBOSE)); |
302 | 302 | ||
303 | support (); | 303 | printf (_(UT_SUPPORT)); |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 7974d14..c8cfecd 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -237,8 +237,8 @@ process_arguments (int argc, char **argv) | |||
237 | 237 | ||
238 | unsigned long l; | 238 | unsigned long l; |
239 | 239 | ||
240 | int option_index = 0; | 240 | int option = 0; |
241 | static struct option long_options[] = { | 241 | static struct option longopts[] = { |
242 | {"timeout", required_argument, 0, 't'}, | 242 | {"timeout", required_argument, 0, 't'}, |
243 | {"warning", required_argument, 0, 'w'}, | 243 | {"warning", required_argument, 0, 'w'}, |
244 | {"critical", required_argument, 0, 'c'}, | 244 | {"critical", required_argument, 0, 'c'}, |
@@ -274,7 +274,7 @@ process_arguments (int argc, char **argv) | |||
274 | strcpy (argv[c], "-t"); | 274 | strcpy (argv[c], "-t"); |
275 | 275 | ||
276 | while (1) { | 276 | while (1) { |
277 | c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", long_options, &option_index); | 277 | c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", longopts, &option); |
278 | 278 | ||
279 | if (c == -1 || c == EOF) | 279 | if (c == -1 || c == EOF) |
280 | break; | 280 | break; |
@@ -363,7 +363,7 @@ process_arguments (int argc, char **argv) | |||
363 | break; | 363 | break; |
364 | case 'p': /* select path */ | 364 | case 'p': /* select path */ |
365 | se = (struct name_list *) malloc (sizeof (struct name_list)); | 365 | se = (struct name_list *) malloc (sizeof (struct name_list)); |
366 | se->name = strdup (optarg); | 366 | se->name = optarg; |
367 | se->name_next = NULL; | 367 | se->name_next = NULL; |
368 | se->w_df = w_df; | 368 | se->w_df = w_df; |
369 | se->c_df = c_df; | 369 | se->c_df = c_df; |
@@ -374,14 +374,14 @@ process_arguments (int argc, char **argv) | |||
374 | break; | 374 | break; |
375 | case 'x': /* exclude path or partition */ | 375 | case 'x': /* exclude path or partition */ |
376 | se = (struct name_list *) malloc (sizeof (struct name_list)); | 376 | se = (struct name_list *) malloc (sizeof (struct name_list)); |
377 | se->name = strdup (optarg); | 377 | se->name = optarg; |
378 | se->name_next = NULL; | 378 | se->name_next = NULL; |
379 | *dptail = se; | 379 | *dptail = se; |
380 | dptail = &se->name_next; | 380 | dptail = &se->name_next; |
381 | break; | 381 | break; |
382 | case 'X': /* exclude file system type */ | 382 | case 'X': /* exclude file system type */ |
383 | se = (struct name_list *) malloc (sizeof (struct name_list)); | 383 | se = (struct name_list *) malloc (sizeof (struct name_list)); |
384 | se->name = strdup (optarg); | 384 | se->name = optarg; |
385 | se->name_next = NULL; | 385 | se->name_next = NULL; |
386 | *fstail = se; | 386 | *fstail = se; |
387 | fstail = &se->name_next; | 387 | fstail = &se->name_next; |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 8b3bb4f..afc23a4 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -54,47 +54,11 @@ const char *revision = "$Revision$"; | |||
54 | const char *copyright = "2000-2003"; | 54 | const char *copyright = "2000-2003"; |
55 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 55 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
56 | 56 | ||
57 | void | ||
58 | print_usage (void) | ||
59 | { | ||
60 | printf (_("\ | ||
61 | Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\ | ||
62 | %s --help\n\ | ||
63 | %s --version\n"), | ||
64 | progname, progname, progname); | ||
65 | } | ||
66 | |||
67 | void | ||
68 | print_help (void) | ||
69 | { | ||
70 | print_revision (progname, revision); | ||
71 | |||
72 | printf (_(COPYRIGHT), copyright, email); | ||
73 | |||
74 | print_usage (); | ||
75 | |||
76 | printf (_(UT_HELP_VRSN)); | ||
77 | |||
78 | printf (_("\ | ||
79 | -H, --hostname=HOST\n\ | ||
80 | The name or address you want to query\n\ | ||
81 | -s, --server=HOST\n\ | ||
82 | Optional DNS server you want to use for the lookup\n\ | ||
83 | -a, --expected-address=IP-ADDRESS\n\ | ||
84 | Optional IP address you expect the DNS server to return\n")); | ||
85 | |||
86 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
87 | |||
88 | printf (_("\n\ | ||
89 | This plugin uses the nslookup program to obtain the IP address\n\ | ||
90 | for the given host/domain query. A optional DNS server to use may\n\ | ||
91 | be specified. If no DNS server is specified, the default server(s)\n\ | ||
92 | specified in /etc/resolv.conf will be used.\n")); | ||
93 | } | ||
94 | |||
95 | int process_arguments (int, char **); | 57 | int process_arguments (int, char **); |
96 | int validate_arguments (void); | 58 | int validate_arguments (void); |
97 | int error_scan (char *); | 59 | int error_scan (char *); |
60 | void print_help (void); | ||
61 | void print_usage (void); | ||
98 | 62 | ||
99 | #define ADDRESS_LENGTH 256 | 63 | #define ADDRESS_LENGTH 256 |
100 | char query_address[ADDRESS_LENGTH] = ""; | 64 | char query_address[ADDRESS_LENGTH] = ""; |
@@ -421,3 +385,51 @@ validate_arguments () | |||
421 | else | 385 | else |
422 | return OK; | 386 | return OK; |
423 | } | 387 | } |
388 | |||
389 | |||
390 | |||
391 | |||
392 | |||
393 | |||
394 | void | ||
395 | print_help (void) | ||
396 | { | ||
397 | print_revision (progname, revision); | ||
398 | |||
399 | printf (_(COPYRIGHT), copyright, email); | ||
400 | |||
401 | print_usage (); | ||
402 | |||
403 | printf (_(UT_HELP_VRSN)); | ||
404 | |||
405 | printf (_("\ | ||
406 | -H, --hostname=HOST\n\ | ||
407 | The name or address you want to query\n\ | ||
408 | -s, --server=HOST\n\ | ||
409 | Optional DNS server you want to use for the lookup\n\ | ||
410 | -a, --expected-address=IP-ADDRESS\n\ | ||
411 | Optional IP address you expect the DNS server to return\n")); | ||
412 | |||
413 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
414 | |||
415 | printf (_("\n\ | ||
416 | This plugin uses the nslookup program to obtain the IP address\n\ | ||
417 | for the given host/domain query. A optional DNS server to use may\n\ | ||
418 | be specified. If no DNS server is specified, the default server(s)\n\ | ||
419 | specified in /etc/resolv.conf will be used.\n")); | ||
420 | |||
421 | printf (_(UT_SUPPORT)); | ||
422 | } | ||
423 | |||
424 | |||
425 | |||
426 | |||
427 | void | ||
428 | print_usage (void) | ||
429 | { | ||
430 | printf (_("\ | ||
431 | Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\ | ||
432 | %s --help\n\ | ||
433 | %s --version\n"), | ||
434 | progname, progname, progname); | ||
435 | } | ||
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 7e4049c..bb17830 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
@@ -34,6 +34,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
34 | 34 | ||
35 | #include "common.h" | 35 | #include "common.h" |
36 | #include "popen.h" | 36 | #include "popen.h" |
37 | #include "netutils.h" | ||
37 | #include "utils.h" | 38 | #include "utils.h" |
38 | 39 | ||
39 | #define PACKET_COUNT 1 | 40 | #define PACKET_COUNT 1 |
@@ -44,54 +45,11 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
44 | #define PL 0 | 45 | #define PL 0 |
45 | #define RTA 1 | 46 | #define RTA 1 |
46 | 47 | ||
47 | void | ||
48 | print_usage (void) | ||
49 | { | ||
50 | printf (_("Usage: %s <host_address>\n"), progname); | ||
51 | } | ||
52 | |||
53 | void | ||
54 | print_help (void) | ||
55 | { | ||
56 | |||
57 | print_revision (progname, "$Revision$"); | ||
58 | |||
59 | printf (_("\ | ||
60 | Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n\ | ||
61 | This plugin will use the /bin/fping command (from saint) to ping the\n\ | ||
62 | specified host for a fast check if the host is alive. Note that it is\n\ | ||
63 | necessary to set the suid flag on fping.\n\n")); | ||
64 | |||
65 | print_usage (); | ||
66 | |||
67 | printf (_(UT_HELP_VRSN)); | ||
68 | |||
69 | printf (_("\ | ||
70 | -H, --hostname=HOST\n\ | ||
71 | Name or IP Address of host to ping (IP Address bypasses name lookup,\n\ | ||
72 | reducing system load)\n\ | ||
73 | -w, --warning=THRESHOLD\n\ | ||
74 | warning threshold pair\n\ | ||
75 | -c, --critical=THRESHOLD\n\ | ||
76 | critical threshold pair\n\ | ||
77 | -b, --bytes=INTEGER\n\ | ||
78 | Size of ICMP packet (default: %d)\n\ | ||
79 | -n, --number=INTEGER\n\ | ||
80 | Number of ICMP packets to send (default: %d)\n"), | ||
81 | PACKET_SIZE, PACKET_COUNT); | ||
82 | |||
83 | printf (_(UT_VERBOSE)); | ||
84 | |||
85 | printf (_("\n\ | ||
86 | THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel\n\ | ||
87 | time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n\ | ||
88 | percentage of packet loss to trigger an alarm state.\n")); | ||
89 | |||
90 | } | ||
91 | |||
92 | int textscan (char *buf); | 48 | int textscan (char *buf); |
93 | int process_arguments (int, char **); | 49 | int process_arguments (int, char **); |
94 | int get_threshold (char *arg, char *rv[2]); | 50 | int get_threshold (char *arg, char *rv[2]); |
51 | void print_help (void); | ||
52 | void print_usage (void); | ||
95 | 53 | ||
96 | char *server_name = NULL; | 54 | char *server_name = NULL; |
97 | int cpl = UNKNOWN_PACKET_LOSS; | 55 | int cpl = UNKNOWN_PACKET_LOSS; |
@@ -200,11 +158,11 @@ textscan (char *buf) | |||
200 | rta = strtod (rtastr, NULL); | 158 | rta = strtod (rtastr, NULL); |
201 | if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl) | 159 | if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl) |
202 | status = STATE_CRITICAL; | 160 | status = STATE_CRITICAL; |
203 | else if (crta != UNKNOWN_TRIP_TIME && rta > crta) | 161 | else if (crta <= 0 && rta > crta) |
204 | status = STATE_CRITICAL; | 162 | status = STATE_CRITICAL; |
205 | else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl) | 163 | else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl) |
206 | status = STATE_WARNING; | 164 | status = STATE_WARNING; |
207 | else if (wrta != UNKNOWN_TRIP_TIME && rta > wrta) | 165 | else if (wrta >= 0 && rta > wrta) |
208 | status = STATE_WARNING; | 166 | status = STATE_WARNING; |
209 | else | 167 | else |
210 | status = STATE_OK; | 168 | status = STATE_OK; |
@@ -218,7 +176,7 @@ textscan (char *buf) | |||
218 | losstr = 1 + strstr (losstr, "/"); | 176 | losstr = 1 + strstr (losstr, "/"); |
219 | losstr = 1 + strstr (losstr, "/"); | 177 | losstr = 1 + strstr (losstr, "/"); |
220 | loss = strtod (losstr, NULL); | 178 | loss = strtod (losstr, NULL); |
221 | if (loss == 100) | 179 | if (atoi(losstr) == 100) |
222 | status = STATE_CRITICAL; | 180 | status = STATE_CRITICAL; |
223 | else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl) | 181 | else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl) |
224 | status = STATE_CRITICAL; | 182 | status = STATE_CRITICAL; |
@@ -248,8 +206,8 @@ process_arguments (int argc, char **argv) | |||
248 | int c; | 206 | int c; |
249 | char *rv[2]; | 207 | char *rv[2]; |
250 | 208 | ||
251 | int option_index = 0; | 209 | int option = 0; |
252 | static struct option long_options[] = { | 210 | static struct option longopts[] = { |
253 | {"hostname", required_argument, 0, 'H'}, | 211 | {"hostname", required_argument, 0, 'H'}, |
254 | {"critical", required_argument, 0, 'c'}, | 212 | {"critical", required_argument, 0, 'c'}, |
255 | {"warning", required_argument, 0, 'w'}, | 213 | {"warning", required_argument, 0, 'w'}, |
@@ -275,7 +233,7 @@ process_arguments (int argc, char **argv) | |||
275 | } | 233 | } |
276 | 234 | ||
277 | while (1) { | 235 | while (1) { |
278 | c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", long_options, &option_index); | 236 | c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", longopts, &option); |
279 | 237 | ||
280 | if (c == -1 || c == EOF || c == 1) | 238 | if (c == -1 || c == EOF || c == 1) |
281 | break; | 239 | break; |
@@ -389,3 +347,58 @@ get_threshold (char *arg, char *rv[2]) | |||
389 | 347 | ||
390 | return OK; | 348 | return OK; |
391 | } | 349 | } |
350 | |||
351 | |||
352 | |||
353 | |||
354 | |||
355 | |||
356 | void | ||
357 | print_help (void) | ||
358 | { | ||
359 | |||
360 | print_revision (progname, "$Revision$"); | ||
361 | |||
362 | printf (_("\ | ||
363 | Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n\ | ||
364 | This plugin will use the /bin/fping command (from saint) to ping the\n\ | ||
365 | specified host for a fast check if the host is alive. Note that it is\n\ | ||
366 | necessary to set the suid flag on fping.\n\n")); | ||
367 | |||
368 | print_usage (); | ||
369 | |||
370 | printf (_(UT_HELP_VRSN)); | ||
371 | |||
372 | printf (_("\ | ||
373 | -H, --hostname=HOST\n\ | ||
374 | Name or IP Address of host to ping (IP Address bypasses name lookup,\n\ | ||
375 | reducing system load)\n\ | ||
376 | -w, --warning=THRESHOLD\n\ | ||
377 | warning threshold pair\n\ | ||
378 | -c, --critical=THRESHOLD\n\ | ||
379 | critical threshold pair\n\ | ||
380 | -b, --bytes=INTEGER\n\ | ||
381 | Size of ICMP packet (default: %d)\n\ | ||
382 | -n, --number=INTEGER\n\ | ||
383 | Number of ICMP packets to send (default: %d)\n"), | ||
384 | PACKET_SIZE, PACKET_COUNT); | ||
385 | |||
386 | printf (_(UT_VERBOSE)); | ||
387 | |||
388 | printf (_("\n\ | ||
389 | THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel\n\ | ||
390 | time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n\ | ||
391 | percentage of packet loss to trigger an alarm state.\n")); | ||
392 | |||
393 | printf (_(UT_SUPPORT)); | ||
394 | } | ||
395 | |||
396 | |||
397 | |||
398 | |||
399 | void | ||
400 | print_usage (void) | ||
401 | { | ||
402 | printf (_("Usage: %s <host_address>\n"), progname); | ||
403 | printf (_(UT_HLP_VRS), progname, progname); | ||
404 | } | ||
diff --git a/plugins/check_game.c b/plugins/check_game.c index 2b10991..d5de13d 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c | |||
@@ -25,48 +25,10 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
25 | #include "popen.h" | 25 | #include "popen.h" |
26 | #include "utils.h" | 26 | #include "utils.h" |
27 | 27 | ||
28 | void | ||
29 | print_usage (void) | ||
30 | { | ||
31 | printf (_("\ | ||
32 | Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\ | ||
33 | [-pf ping_field]\n"), progname); | ||
34 | printf (_(UT_HLP_VRS), progname, progname); | ||
35 | } | ||
36 | |||
37 | void | ||
38 | print_help (void) | ||
39 | { | ||
40 | print_revision (progname, revision); | ||
41 | |||
42 | printf (_(COPYRIGHT), copyright, email); | ||
43 | |||
44 | printf (_("This plugin tests %s connections with the specified host."), progname); | ||
45 | |||
46 | print_usage (); | ||
47 | |||
48 | printf (_(UT_HELP_VRSN)); | ||
49 | |||
50 | printf (_("\ | ||
51 | <game> = Game type that is recognised by qstat (without the leading dash)\n\ | ||
52 | <ip_address> = The IP address of the device you wish to query\n\ | ||
53 | [port] = Optional port of which to connect\n\ | ||
54 | [game_field] = Field number in raw qstat output that contains game name\n\ | ||
55 | [map_field] = Field number in raw qstat output that contains map name\n\ | ||
56 | [ping_field] = Field number in raw qstat output that contains ping time\n"), | ||
57 | DEFAULT_SOCKET_TIMEOUT); | ||
58 | |||
59 | printf (_("\n\ | ||
60 | Notes:\n\ | ||
61 | - This plugin uses the 'qstat' command, the popular game server status query tool .\n\ | ||
62 | If you don't have the package installed, you will need to download it from\n\ | ||
63 | http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n")); | ||
64 | |||
65 | printf (_(UT_SUPPORT)); | ||
66 | } | ||
67 | |||
68 | int process_arguments (int, char **); | 28 | int process_arguments (int, char **); |
69 | int validate_arguments (void); | 29 | int validate_arguments (void); |
30 | void print_help (void); | ||
31 | void print_usage (void); | ||
70 | 32 | ||
71 | #define QSTAT_DATA_DELIMITER "," | 33 | #define QSTAT_DATA_DELIMITER "," |
72 | 34 | ||
@@ -152,7 +114,7 @@ main (int argc, char **argv) | |||
152 | 114 | ||
153 | /* initialize the returned data buffer */ | 115 | /* initialize the returned data buffer */ |
154 | for (i = 0; i < QSTAT_MAX_RETURN_ARGS; i++) | 116 | for (i = 0; i < QSTAT_MAX_RETURN_ARGS; i++) |
155 | ret[i] = ""; | 117 | ret[i] = strdup(""); |
156 | 118 | ||
157 | i = 0; | 119 | i = 0; |
158 | p = (char *) strtok (input_buffer, QSTAT_DATA_DELIMITER); | 120 | p = (char *) strtok (input_buffer, QSTAT_DATA_DELIMITER); |
@@ -253,7 +215,7 @@ process_arguments (int argc, char **argv) | |||
253 | case 'H': /* hostname */ | 215 | case 'H': /* hostname */ |
254 | if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH) | 216 | if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH) |
255 | die (STATE_UNKNOWN, _("Input buffer overflow\n")); | 217 | die (STATE_UNKNOWN, _("Input buffer overflow\n")); |
256 | server_ip = strdup (optarg); | 218 | server_ip = optarg; |
257 | break; | 219 | break; |
258 | case 'P': /* port */ | 220 | case 'P': /* port */ |
259 | port = atoi (optarg); | 221 | port = atoi (optarg); |
@@ -261,7 +223,7 @@ process_arguments (int argc, char **argv) | |||
261 | case 'G': /* hostname */ | 223 | case 'G': /* hostname */ |
262 | if (strlen (optarg) >= MAX_INPUT_BUFFER) | 224 | if (strlen (optarg) >= MAX_INPUT_BUFFER) |
263 | die (STATE_UNKNOWN, _("Input buffer overflow\n")); | 225 | die (STATE_UNKNOWN, _("Input buffer overflow\n")); |
264 | game_type = strdup (optarg); | 226 | game_type = optarg; |
265 | break; | 227 | break; |
266 | case 'p': /* index of ping field */ | 228 | case 'p': /* index of ping field */ |
267 | qstat_ping_field = atoi (optarg); | 229 | qstat_ping_field = atoi (optarg); |
@@ -308,3 +270,52 @@ validate_arguments (void) | |||
308 | { | 270 | { |
309 | return OK; | 271 | return OK; |
310 | } | 272 | } |
273 | |||
274 | |||
275 | |||
276 | |||
277 | |||
278 | |||
279 | void | ||
280 | print_help (void) | ||
281 | { | ||
282 | print_revision (progname, revision); | ||
283 | |||
284 | printf (_(COPYRIGHT), copyright, email); | ||
285 | |||
286 | printf (_("This plugin tests %s connections with the specified host."), progname); | ||
287 | |||
288 | print_usage (); | ||
289 | |||
290 | printf (_(UT_HELP_VRSN)); | ||
291 | |||
292 | printf (_("\ | ||
293 | <game> = Game type that is recognised by qstat (without the leading dash)\n\ | ||
294 | <ip_address> = The IP address of the device you wish to query\n\ | ||
295 | [port] = Optional port of which to connect\n\ | ||
296 | [game_field] = Field number in raw qstat output that contains game name\n\ | ||
297 | [map_field] = Field number in raw qstat output that contains map name\n\ | ||
298 | [ping_field] = Field number in raw qstat output that contains ping time\n")); | ||
299 | |||
300 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
301 | |||
302 | printf (_("\n\ | ||
303 | Notes:\n\ | ||
304 | - This plugin uses the 'qstat' command, the popular game server status query tool .\n\ | ||
305 | If you don't have the package installed, you will need to download it from\n\ | ||
306 | http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n")); | ||
307 | |||
308 | printf (_(UT_SUPPORT)); | ||
309 | } | ||
310 | |||
311 | |||
312 | |||
313 | |||
314 | void | ||
315 | print_usage (void) | ||
316 | { | ||
317 | printf (_("\ | ||
318 | Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\ | ||
319 | [-pf ping_field]\n"), progname); | ||
320 | printf (_(UT_HLP_VRS), progname, progname); | ||
321 | } | ||
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index cb93a36..edde341 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -29,36 +29,7 @@ const char *copyright = "2000-2003"; | |||
29 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 29 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
30 | 30 | ||
31 | const char *option_summary = "-H host [-C community]\n"; | 31 | const char *option_summary = "-H host [-C community]\n"; |
32 | void | ||
33 | print_usage (void) | ||
34 | { | ||
35 | printf (_("\ | ||
36 | Usage: %s -H host [-C community]\n"), progname); | ||
37 | printf (_(UT_HLP_VRS), progname, progname); | ||
38 | } | ||
39 | 32 | ||
40 | void | ||
41 | print_help (void) | ||
42 | { | ||
43 | print_revision (progname, revision); | ||
44 | |||
45 | printf (_(COPYRIGHT), copyright, email); | ||
46 | |||
47 | printf (_("\ | ||
48 | This plugin tests the STATUS of an HP printer with a JetDirect card.\n\ | ||
49 | Net-snmp must be installed on the computer running the plugin.\n\n")); | ||
50 | |||
51 | print_usage (); | ||
52 | |||
53 | printf (_(UT_HELP_VRSN)); | ||
54 | |||
55 | printf (_("\ | ||
56 | -C, --community=STRING\n\ | ||
57 | The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY); | ||
58 | |||
59 | printf (_(UT_SUPPORT)); | ||
60 | } | ||
61 | |||
62 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" | 33 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" |
63 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" | 34 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" |
64 | #define HPJD_INTERVENTION_REQUIRED ".1.3.6.1.4.1.11.2.3.9.1.1.2.3" | 35 | #define HPJD_INTERVENTION_REQUIRED ".1.3.6.1.4.1.11.2.3.9.1.1.2.3" |
@@ -77,8 +48,10 @@ Net-snmp must be installed on the computer running the plugin.\n\n")); | |||
77 | 48 | ||
78 | int process_arguments (int, char **); | 49 | int process_arguments (int, char **); |
79 | int validate_arguments (void); | 50 | int validate_arguments (void); |
51 | void print_help (void); | ||
52 | void print_usage (void); | ||
80 | 53 | ||
81 | char *community = DEFAULT_COMMUNITY; | 54 | char *community = NULL; |
82 | char *address = NULL; | 55 | char *address = NULL; |
83 | 56 | ||
84 | int | 57 | int |
@@ -89,7 +62,7 @@ main (int argc, char **argv) | |||
89 | int line; | 62 | int line; |
90 | char input_buffer[MAX_INPUT_BUFFER]; | 63 | char input_buffer[MAX_INPUT_BUFFER]; |
91 | char query_string[512]; | 64 | char query_string[512]; |
92 | char error_message[MAX_INPUT_BUFFER]; | 65 | char *errmsg; |
93 | char *temp_buffer; | 66 | char *temp_buffer; |
94 | int line_status = ONLINE; | 67 | int line_status = ONLINE; |
95 | int paper_status = 0; | 68 | int paper_status = 0; |
@@ -103,7 +76,8 @@ main (int argc, char **argv) | |||
103 | int door_open = 0; | 76 | int door_open = 0; |
104 | int paper_output = 0; | 77 | int paper_output = 0; |
105 | char display_message[MAX_INPUT_BUFFER]; | 78 | char display_message[MAX_INPUT_BUFFER]; |
106 | char *temp ; | 79 | |
80 | errmsg = malloc(MAX_INPUT_BUFFER); | ||
107 | 81 | ||
108 | if (process_arguments (argc, argv) != OK) | 82 | if (process_arguments (argc, argv) != OK) |
109 | usage (_("Invalid command arguments supplied\n")); | 83 | usage (_("Invalid command arguments supplied\n")); |
@@ -154,118 +128,55 @@ main (int argc, char **argv) | |||
154 | temp_buffer = strtok (input_buffer, "="); | 128 | temp_buffer = strtok (input_buffer, "="); |
155 | temp_buffer = strtok (NULL, "="); | 129 | temp_buffer = strtok (NULL, "="); |
156 | 130 | ||
157 | switch (line) { | 131 | if (temp_buffer != NULL) { |
158 | 132 | ||
159 | case 1: /* 1st line should contain the line status */ | ||
160 | if (temp_buffer != NULL) | ||
161 | line_status = atoi (temp_buffer); | ||
162 | else { | ||
163 | result = STATE_UNKNOWN; | 133 | result = STATE_UNKNOWN; |
164 | strcpy (error_message, input_buffer); | 134 | strcpy (errmsg, input_buffer); |
165 | } | ||
166 | break; | ||
167 | 135 | ||
168 | case 2: /* 2nd line should contain the paper status */ | 136 | } else { |
169 | if (temp_buffer != NULL) | ||
170 | paper_status = atoi (temp_buffer); | ||
171 | else { | ||
172 | result = STATE_UNKNOWN; | ||
173 | strcpy (error_message, input_buffer); | ||
174 | } | ||
175 | break; | ||
176 | 137 | ||
177 | case 3: /* 3rd line should be intervention required */ | 138 | switch (line) { |
178 | if (temp_buffer != NULL) | ||
179 | intervention_required = atoi (temp_buffer); | ||
180 | else { | ||
181 | result = STATE_UNKNOWN; | ||
182 | strcpy (error_message, input_buffer); | ||
183 | } | ||
184 | break; | ||
185 | 139 | ||
186 | case 4: /* 4th line should be peripheral error */ | 140 | case 1: /* 1st line should contain the line status */ |
187 | if (temp_buffer != NULL) | 141 | line_status = atoi (temp_buffer); |
142 | break; | ||
143 | case 2: /* 2nd line should contain the paper status */ | ||
144 | paper_status = atoi (temp_buffer); | ||
145 | break; | ||
146 | case 3: /* 3rd line should be intervention required */ | ||
147 | intervention_required = atoi (temp_buffer); | ||
148 | break; | ||
149 | case 4: /* 4th line should be peripheral error */ | ||
188 | peripheral_error = atoi (temp_buffer); | 150 | peripheral_error = atoi (temp_buffer); |
189 | else { | 151 | break; |
190 | result = STATE_UNKNOWN; | 152 | case 5: /* 5th line should contain the paper jam status */ |
191 | strcpy (error_message, input_buffer); | ||
192 | } | ||
193 | break; | ||
194 | |||
195 | case 5: /* 5th line should contain the paper jam status */ | ||
196 | if (temp_buffer != NULL) | ||
197 | paper_jam = atoi (temp_buffer); | 153 | paper_jam = atoi (temp_buffer); |
198 | else { | 154 | break; |
199 | result = STATE_UNKNOWN; | 155 | case 6: /* 6th line should contain the paper out status */ |
200 | strcpy (error_message, input_buffer); | ||
201 | } | ||
202 | break; | ||
203 | |||
204 | case 6: /* 6th line should contain the paper out status */ | ||
205 | if (temp_buffer != NULL) | ||
206 | paper_out = atoi (temp_buffer); | 156 | paper_out = atoi (temp_buffer); |
207 | else { | 157 | break; |
208 | result = STATE_UNKNOWN; | 158 | case 7: /* 7th line should contain the toner low status */ |
209 | strcpy (error_message, input_buffer); | ||
210 | } | ||
211 | break; | ||
212 | |||
213 | case 7: /* 7th line should contain the toner low status */ | ||
214 | if (temp_buffer != NULL) | ||
215 | toner_low = atoi (temp_buffer); | 159 | toner_low = atoi (temp_buffer); |
216 | else { | 160 | break; |
217 | result = STATE_UNKNOWN; | 161 | case 8: /* did data come too slow for engine */ |
218 | strcpy (error_message, input_buffer); | ||
219 | } | ||
220 | break; | ||
221 | |||
222 | case 8: /* did data come too slow for engine */ | ||
223 | if (temp_buffer != NULL) | ||
224 | page_punt = atoi (temp_buffer); | 162 | page_punt = atoi (temp_buffer); |
225 | else { | 163 | break; |
226 | result = STATE_UNKNOWN; | 164 | case 9: /* did we run out of memory */ |
227 | strcpy (error_message, input_buffer); | ||
228 | } | ||
229 | break; | ||
230 | |||
231 | case 9: /* did we run out of memory */ | ||
232 | if (temp_buffer != NULL) | ||
233 | memory_out = atoi (temp_buffer); | 165 | memory_out = atoi (temp_buffer); |
234 | else { | 166 | break; |
235 | result = STATE_UNKNOWN; | 167 | case 10: /* is there a door open */ |
236 | strcpy (error_message, input_buffer); | ||
237 | } | ||
238 | break; | ||
239 | |||
240 | case 10: /* is there a door open */ | ||
241 | if (temp_buffer != NULL) | ||
242 | door_open = atoi (temp_buffer); | 168 | door_open = atoi (temp_buffer); |
243 | else { | 169 | break; |
244 | result = STATE_UNKNOWN; | 170 | case 11: /* is output tray full */ |
245 | strcpy (error_message, input_buffer); | ||
246 | } | ||
247 | break; | ||
248 | |||
249 | case 11: /* is output tray full */ | ||
250 | if (temp_buffer != NULL) | ||
251 | paper_output = atoi (temp_buffer); | 171 | paper_output = atoi (temp_buffer); |
252 | else { | 172 | break; |
253 | result = STATE_UNKNOWN; | 173 | case 12: /* display panel message */ |
254 | strcpy (error_message, input_buffer); | ||
255 | } | ||
256 | break; | ||
257 | |||
258 | case 12: /* display panel message */ | ||
259 | if (temp_buffer != NULL) | ||
260 | strcpy (display_message, temp_buffer + 1); | 174 | strcpy (display_message, temp_buffer + 1); |
261 | else { | 175 | break; |
262 | result = STATE_UNKNOWN; | 176 | default: |
263 | strcpy (error_message, input_buffer); | 177 | break; |
264 | } | 178 | } |
265 | break; | ||
266 | 179 | ||
267 | default: | ||
268 | break; | ||
269 | } | 180 | } |
270 | 181 | ||
271 | /* break out of the read loop if we encounter an error */ | 182 | /* break out of the read loop if we encounter an error */ |
@@ -279,7 +190,7 @@ main (int argc, char **argv) | |||
279 | /* remove CRLF */ | 190 | /* remove CRLF */ |
280 | if (input_buffer[strlen (input_buffer) - 1] == '\n') | 191 | if (input_buffer[strlen (input_buffer) - 1] == '\n') |
281 | input_buffer[strlen (input_buffer) - 1] = 0; | 192 | input_buffer[strlen (input_buffer) - 1] = 0; |
282 | sprintf (error_message, "%s", input_buffer ); | 193 | sprintf (errmsg, "%s", input_buffer ); |
283 | 194 | ||
284 | } | 195 | } |
285 | 196 | ||
@@ -295,8 +206,7 @@ main (int argc, char **argv) | |||
295 | 206 | ||
296 | /* might not be the problem, but most likely is. */ | 207 | /* might not be the problem, but most likely is. */ |
297 | result = STATE_UNKNOWN ; | 208 | result = STATE_UNKNOWN ; |
298 | asprintf (&temp, error_message); | 209 | asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address ); |
299 | sprintf (error_message, "%s : Timeout from host %s\n", temp, address ); | ||
300 | 210 | ||
301 | } | 211 | } |
302 | 212 | ||
@@ -305,49 +215,49 @@ main (int argc, char **argv) | |||
305 | 215 | ||
306 | if (paper_jam) { | 216 | if (paper_jam) { |
307 | result = STATE_WARNING; | 217 | result = STATE_WARNING; |
308 | strcpy (error_message, _("Paper Jam")); | 218 | strcpy (errmsg, _("Paper Jam")); |
309 | } | 219 | } |
310 | else if (paper_out) { | 220 | else if (paper_out) { |
311 | result = STATE_WARNING; | 221 | result = STATE_WARNING; |
312 | strcpy (error_message, _("Out of Paper")); | 222 | strcpy (errmsg, _("Out of Paper")); |
313 | } | 223 | } |
314 | else if (line_status == OFFLINE) { | 224 | else if (line_status == OFFLINE) { |
315 | if (strcmp (error_message, "POWERSAVE ON") != 0) { | 225 | if (strcmp (errmsg, "POWERSAVE ON") != 0) { |
316 | result = STATE_WARNING; | 226 | result = STATE_WARNING; |
317 | strcpy (error_message, _("Printer Offline")); | 227 | strcpy (errmsg, _("Printer Offline")); |
318 | } | 228 | } |
319 | } | 229 | } |
320 | else if (peripheral_error) { | 230 | else if (peripheral_error) { |
321 | result = STATE_WARNING; | 231 | result = STATE_WARNING; |
322 | strcpy (error_message, _("Peripheral Error")); | 232 | strcpy (errmsg, _("Peripheral Error")); |
323 | } | 233 | } |
324 | else if (intervention_required) { | 234 | else if (intervention_required) { |
325 | result = STATE_WARNING; | 235 | result = STATE_WARNING; |
326 | strcpy (error_message, _("Intervention Required")); | 236 | strcpy (errmsg, _("Intervention Required")); |
327 | } | 237 | } |
328 | else if (toner_low) { | 238 | else if (toner_low) { |
329 | result = STATE_WARNING; | 239 | result = STATE_WARNING; |
330 | strcpy (error_message, _("Toner Low")); | 240 | strcpy (errmsg, _("Toner Low")); |
331 | } | 241 | } |
332 | else if (memory_out) { | 242 | else if (memory_out) { |
333 | result = STATE_WARNING; | 243 | result = STATE_WARNING; |
334 | strcpy (error_message, _("Insufficient Memory")); | 244 | strcpy (errmsg, _("Insufficient Memory")); |
335 | } | 245 | } |
336 | else if (door_open) { | 246 | else if (door_open) { |
337 | result = STATE_WARNING; | 247 | result = STATE_WARNING; |
338 | strcpy (error_message, _("A Door is Open")); | 248 | strcpy (errmsg, _("A Door is Open")); |
339 | } | 249 | } |
340 | else if (paper_output) { | 250 | else if (paper_output) { |
341 | result = STATE_WARNING; | 251 | result = STATE_WARNING; |
342 | strcpy (error_message, _("Output Tray is Full")); | 252 | strcpy (errmsg, _("Output Tray is Full")); |
343 | } | 253 | } |
344 | else if (page_punt) { | 254 | else if (page_punt) { |
345 | result = STATE_WARNING; | 255 | result = STATE_WARNING; |
346 | strcpy (error_message, _("Data too Slow for Engine")); | 256 | strcpy (errmsg, _("Data too Slow for Engine")); |
347 | } | 257 | } |
348 | else if (paper_status) { | 258 | else if (paper_status) { |
349 | result = STATE_WARNING; | 259 | result = STATE_WARNING; |
350 | strcpy (error_message, _("Unknown Paper Error")); | 260 | strcpy (errmsg, _("Unknown Paper Error")); |
351 | } | 261 | } |
352 | } | 262 | } |
353 | 263 | ||
@@ -356,15 +266,15 @@ main (int argc, char **argv) | |||
356 | 266 | ||
357 | else if (result == STATE_UNKNOWN) { | 267 | else if (result == STATE_UNKNOWN) { |
358 | 268 | ||
359 | printf ("%s\n", error_message); | 269 | printf ("%s\n", errmsg); |
360 | 270 | ||
361 | /* if printer could not be reached, escalate to critical */ | 271 | /* if printer could not be reached, escalate to critical */ |
362 | if (strstr (error_message, "Timeout")) | 272 | if (strstr (errmsg, "Timeout")) |
363 | result = STATE_CRITICAL; | 273 | result = STATE_CRITICAL; |
364 | } | 274 | } |
365 | 275 | ||
366 | else if (result == STATE_WARNING) | 276 | else if (result == STATE_WARNING) |
367 | printf ("%s (%s)\n", error_message, display_message); | 277 | printf ("%s (%s)\n", errmsg, display_message); |
368 | 278 | ||
369 | return result; | 279 | return result; |
370 | } | 280 | } |
@@ -379,8 +289,8 @@ process_arguments (int argc, char **argv) | |||
379 | { | 289 | { |
380 | int c; | 290 | int c; |
381 | 291 | ||
382 | int option_index = 0; | 292 | int option = 0; |
383 | static struct option long_options[] = { | 293 | static struct option longopts[] = { |
384 | {"hostname", required_argument, 0, 'H'}, | 294 | {"hostname", required_argument, 0, 'H'}, |
385 | {"community", required_argument, 0, 'C'}, | 295 | {"community", required_argument, 0, 'C'}, |
386 | /* {"critical", required_argument,0,'c'}, */ | 296 | /* {"critical", required_argument,0,'c'}, */ |
@@ -396,7 +306,7 @@ process_arguments (int argc, char **argv) | |||
396 | 306 | ||
397 | 307 | ||
398 | while (1) { | 308 | while (1) { |
399 | c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index); | 309 | c = getopt_long (argc, argv, "+hVH:C:", longopts, &option); |
400 | 310 | ||
401 | if (c == -1 || c == EOF || c == 1) | 311 | if (c == -1 || c == EOF || c == 1) |
402 | break; | 312 | break; |
@@ -434,8 +344,11 @@ process_arguments (int argc, char **argv) | |||
434 | } | 344 | } |
435 | } | 345 | } |
436 | 346 | ||
437 | if (argv[c] != NULL ) { | 347 | if (community == NULL) { |
438 | community = argv[c]; | 348 | if (argv[c] != NULL ) |
349 | community = argv[c]; | ||
350 | else | ||
351 | community = strdup (DEFAULT_COMMUNITY); | ||
439 | } | 352 | } |
440 | 353 | ||
441 | return validate_arguments (); | 354 | return validate_arguments (); |
@@ -450,3 +363,41 @@ validate_arguments (void) | |||
450 | { | 363 | { |
451 | return OK; | 364 | return OK; |
452 | } | 365 | } |
366 | |||
367 | |||
368 | |||
369 | |||
370 | |||
371 | |||
372 | void | ||
373 | print_help (void) | ||
374 | { | ||
375 | print_revision (progname, revision); | ||
376 | |||
377 | printf (_(COPYRIGHT), copyright, email); | ||
378 | |||
379 | printf (_("\ | ||
380 | This plugin tests the STATUS of an HP printer with a JetDirect card.\n\ | ||
381 | Net-snmp must be installed on the computer running the plugin.\n\n")); | ||
382 | |||
383 | print_usage (); | ||
384 | |||
385 | printf (_(UT_HELP_VRSN)); | ||
386 | |||
387 | printf (_("\ | ||
388 | -C, --community=STRING\n\ | ||
389 | The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY); | ||
390 | |||
391 | printf (_(UT_SUPPORT)); | ||
392 | } | ||
393 | |||
394 | |||
395 | |||
396 | |||
397 | void | ||
398 | print_usage (void) | ||
399 | { | ||
400 | printf (_("\ | ||
401 | Usage: %s -H host [-C community]\n"), progname); | ||
402 | printf (_(UT_HLP_VRS), progname, progname); | ||
403 | } | ||
diff --git a/plugins/check_http.c b/plugins/check_http.c index 3321d5a..27127d6 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -184,8 +184,8 @@ process_arguments (int argc, char **argv) | |||
184 | { | 184 | { |
185 | int c = 1; | 185 | int c = 1; |
186 | 186 | ||
187 | int option_index = 0; | 187 | int option = 0; |
188 | static struct option long_options[] = { | 188 | static struct option longopts[] = { |
189 | STD_LONG_OPTS, | 189 | STD_LONG_OPTS, |
190 | {"file",required_argument,0,'F'}, | 190 | {"file",required_argument,0,'F'}, |
191 | {"link", no_argument, 0, 'L'}, | 191 | {"link", no_argument, 0, 'L'}, |
@@ -224,7 +224,7 @@ process_arguments (int argc, char **argv) | |||
224 | } | 224 | } |
225 | 225 | ||
226 | while (1) { | 226 | while (1) { |
227 | c = getopt_long (argc, argv, "Vvh46t:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:", long_options, &option_index); | 227 | c = getopt_long (argc, argv, "Vvh46t:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:", longopts, &option); |
228 | if (c == -1 || c == EOF) | 228 | if (c == -1 || c == EOF) |
229 | break; | 229 | break; |
230 | 230 | ||
@@ -304,10 +304,10 @@ process_arguments (int argc, char **argv) | |||
304 | break; | 304 | break; |
305 | /* Note: H, I, and u must be malloc'd or will fail on redirects */ | 305 | /* Note: H, I, and u must be malloc'd or will fail on redirects */ |
306 | case 'H': /* Host Name (virtual host) */ | 306 | case 'H': /* Host Name (virtual host) */ |
307 | host_name = strdup (optarg); | 307 | host_name = optarg; |
308 | break; | 308 | break; |
309 | case 'I': /* Server IP-address */ | 309 | case 'I': /* Server IP-address */ |
310 | server_address = strdup(optarg); | 310 | server_address = optarg; |
311 | break; | 311 | break; |
312 | case 'u': /* URL path */ | 312 | case 'u': /* URL path */ |
313 | asprintf (&server_url, "%s", optarg); | 313 | asprintf (&server_url, "%s", optarg); |
@@ -328,7 +328,7 @@ process_arguments (int argc, char **argv) | |||
328 | case 'P': /* HTTP POST data in URL encoded format */ | 328 | case 'P': /* HTTP POST data in URL encoded format */ |
329 | if (http_method || http_post_data) break; | 329 | if (http_method || http_post_data) break; |
330 | http_method = strdup("POST"); | 330 | http_method = strdup("POST"); |
331 | http_post_data = strdup(optarg); | 331 | http_post_data = optarg; |
332 | break; | 332 | break; |
333 | case 's': /* string or substring */ | 333 | case 's': /* string or substring */ |
334 | strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); | 334 | strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); |
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 2064dd3..d2c6ae2 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
@@ -36,75 +36,18 @@ enum { | |||
36 | DEFAULT_PORT = 389 | 36 | DEFAULT_PORT = 389 |
37 | }; | 37 | }; |
38 | 38 | ||
39 | void | ||
40 | print_usage () | ||
41 | { | ||
42 | printf (_("\ | ||
43 | Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\ | ||
44 | [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\ | ||
45 | (Note: all times are in seconds.)\n"), | ||
46 | progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : "")); | ||
47 | printf (_(UT_HLP_VRS), progname, progname); | ||
48 | } | ||
49 | |||
50 | void | ||
51 | print_help () | ||
52 | { | ||
53 | char *myport; | ||
54 | asprintf (&myport, "%d", DEFAULT_PORT); | ||
55 | |||
56 | print_revision (progname, revision); | ||
57 | |||
58 | printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n")); | ||
59 | printf (_(COPYRIGHT), copyright, email); | ||
60 | |||
61 | print_usage (); | ||
62 | |||
63 | printf (_(UT_HELP_VRSN)); | ||
64 | |||
65 | printf (_(UT_HOST_PORT), 'p', myport); | ||
66 | |||
67 | printf (_(UT_IPv46)); | ||
68 | |||
69 | printf (_("\ | ||
70 | -a [--attr]\n\ | ||
71 | ldap attribute to search (default: \"(objectclass=*)\"\n\ | ||
72 | -b [--base]\n\ | ||
73 | ldap base (eg. ou=my unit, o=my org, c=at)\n\ | ||
74 | -D [--bind]\n\ | ||
75 | ldap bind DN (if required)\n\ | ||
76 | -P [--pass]\n\ | ||
77 | ldap password (if required)\n")); | ||
78 | |||
79 | #ifdef HAVE_LDAP_SET_OPTION | ||
80 | printf (_("\ | ||
81 | -2 [--ver2]\n\ | ||
82 | use ldap protocol version 2\n\ | ||
83 | -3 [--ver3]\n\ | ||
84 | use ldap protocol version 3\n\ | ||
85 | (default protocol version: %d)\n"), | ||
86 | DEFAULT_PROTOCOL); | ||
87 | #endif | ||
88 | |||
89 | printf (_(UT_WARN_CRIT)); | ||
90 | |||
91 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
92 | |||
93 | printf (_(UT_VERBOSE)); | ||
94 | |||
95 | printf (_(UT_SUPPORT)); | ||
96 | } | ||
97 | |||
98 | int process_arguments (int, char **); | 39 | int process_arguments (int, char **); |
99 | int validate_arguments (void); | 40 | int validate_arguments (void); |
41 | void print_help (void); | ||
42 | void print_usage (void); | ||
100 | 43 | ||
101 | char ld_defattr[] = "(objectclass=*)"; | 44 | char ld_defattr[] = "(objectclass=*)"; |
102 | char *ld_attr = ld_defattr; | 45 | char *ld_attr = ld_defattr; |
103 | char *ld_host = ""; | 46 | char *ld_host = NULL; |
104 | char *ld_base = ""; | 47 | char *ld_base = NULL; |
105 | char *ld_passwd = NULL; | 48 | char *ld_passwd = NULL; |
106 | char *ld_binddn = NULL; | 49 | char *ld_binddn = NULL; |
107 | unsigned int ld_port = DEFAULT_PORT; | 50 | int ld_port = DEFAULT_PORT; |
108 | #ifdef HAVE_LDAP_SET_OPTION | 51 | #ifdef HAVE_LDAP_SET_OPTION |
109 | int ld_protocol = DEFAULT_PROTOCOL; | 52 | int ld_protocol = DEFAULT_PROTOCOL; |
110 | #endif | 53 | #endif |
@@ -198,7 +141,7 @@ process_arguments (int argc, char **argv) | |||
198 | { | 141 | { |
199 | int c; | 142 | int c; |
200 | 143 | ||
201 | int option_index = 0; | 144 | int option = 0; |
202 | /* initialize the long option struct */ | 145 | /* initialize the long option struct */ |
203 | static struct option longopts[] = { | 146 | static struct option longopts[] = { |
204 | {"help", no_argument, 0, 'h'}, | 147 | {"help", no_argument, 0, 'h'}, |
@@ -230,7 +173,7 @@ process_arguments (int argc, char **argv) | |||
230 | } | 173 | } |
231 | 174 | ||
232 | while (1) { | 175 | while (1) { |
233 | c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option_index); | 176 | c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option); |
234 | 177 | ||
235 | if (c == -1 || c == EOF) | 178 | if (c == -1 || c == EOF) |
236 | break; | 179 | break; |
@@ -245,7 +188,8 @@ process_arguments (int argc, char **argv) | |||
245 | case 't': /* timeout period */ | 188 | case 't': /* timeout period */ |
246 | if (!is_intnonneg (optarg)) | 189 | if (!is_intnonneg (optarg)) |
247 | usage2 (_("timeout interval must be a positive integer"), optarg); | 190 | usage2 (_("timeout interval must be a positive integer"), optarg); |
248 | socket_timeout = atoi (optarg); | 191 | else |
192 | socket_timeout = atoi (optarg); | ||
249 | break; | 193 | break; |
250 | case 'H': | 194 | case 'H': |
251 | ld_host = optarg; | 195 | ld_host = optarg; |
@@ -296,12 +240,11 @@ process_arguments (int argc, char **argv) | |||
296 | } | 240 | } |
297 | 241 | ||
298 | c = optind; | 242 | c = optind; |
299 | if (strlen(ld_host) == 0 && is_host(argv[c])) { | 243 | if (ld_host == NULL && is_host(argv[c])) |
300 | asprintf (&ld_host, "%s", argv[c++]); | 244 | ld_host = strdup (argv[c++]); |
301 | } | 245 | |
302 | if (strlen(ld_base) == 0 && argv[c]) { | 246 | if (ld_base == NULL && argv[c]) |
303 | asprintf (&ld_base, "%s", argv[c++]); | 247 | ld_base = strdup (argv[c++]); |
304 | } | ||
305 | 248 | ||
306 | return validate_arguments (); | 249 | return validate_arguments (); |
307 | } | 250 | } |
@@ -318,3 +261,70 @@ validate_arguments () | |||
318 | return OK; | 261 | return OK; |
319 | 262 | ||
320 | } | 263 | } |
264 | |||
265 | |||
266 | |||
267 | |||
268 | |||
269 | |||
270 | void | ||
271 | print_help (void) | ||
272 | { | ||
273 | char *myport; | ||
274 | asprintf (&myport, "%d", DEFAULT_PORT); | ||
275 | |||
276 | print_revision (progname, revision); | ||
277 | |||
278 | printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n")); | ||
279 | printf (_(COPYRIGHT), copyright, email); | ||
280 | |||
281 | print_usage (); | ||
282 | |||
283 | printf (_(UT_HELP_VRSN)); | ||
284 | |||
285 | printf (_(UT_HOST_PORT), 'p', myport); | ||
286 | |||
287 | printf (_(UT_IPv46)); | ||
288 | |||
289 | printf (_("\ | ||
290 | -a [--attr]\n\ | ||
291 | ldap attribute to search (default: \"(objectclass=*)\"\n\ | ||
292 | -b [--base]\n\ | ||
293 | ldap base (eg. ou=my unit, o=my org, c=at)\n\ | ||
294 | -D [--bind]\n\ | ||
295 | ldap bind DN (if required)\n\ | ||
296 | -P [--pass]\n\ | ||
297 | ldap password (if required)\n")); | ||
298 | |||
299 | #ifdef HAVE_LDAP_SET_OPTION | ||
300 | printf (_("\ | ||
301 | -2 [--ver2]\n\ | ||
302 | use ldap protocol version 2\n\ | ||
303 | -3 [--ver3]\n\ | ||
304 | use ldap protocol version 3\n\ | ||
305 | (default protocol version: %d)\n"), | ||
306 | DEFAULT_PROTOCOL); | ||
307 | #endif | ||
308 | |||
309 | printf (_(UT_WARN_CRIT)); | ||
310 | |||
311 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
312 | |||
313 | printf (_(UT_VERBOSE)); | ||
314 | |||
315 | printf (_(UT_SUPPORT)); | ||
316 | } | ||
317 | |||
318 | |||
319 | |||
320 | |||
321 | void | ||
322 | print_usage (void) | ||
323 | { | ||
324 | printf (_("\ | ||
325 | Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\ | ||
326 | [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\ | ||
327 | (Note: all times are in seconds.)\n"), | ||
328 | progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : "")); | ||
329 | printf (_(UT_HLP_VRS), progname, progname); | ||
330 | } | ||
diff --git a/plugins/check_load.c b/plugins/check_load.c index bdb1e55..c12cad3 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -158,8 +158,8 @@ process_arguments (int argc, char **argv) | |||
158 | { | 158 | { |
159 | int c = 0; | 159 | int c = 0; |
160 | 160 | ||
161 | int option_index = 0; | 161 | int option = 0; |
162 | static struct option long_options[] = { | 162 | static struct option longopts[] = { |
163 | {"warning", required_argument, 0, 'w'}, | 163 | {"warning", required_argument, 0, 'w'}, |
164 | {"critical", required_argument, 0, 'c'}, | 164 | {"critical", required_argument, 0, 'c'}, |
165 | {"version", no_argument, 0, 'V'}, | 165 | {"version", no_argument, 0, 'V'}, |
@@ -171,7 +171,7 @@ process_arguments (int argc, char **argv) | |||
171 | return ERROR; | 171 | return ERROR; |
172 | 172 | ||
173 | while (1) { | 173 | while (1) { |
174 | c = getopt_long (argc, argv, "Vhc:w:", long_options, &option_index); | 174 | c = getopt_long (argc, argv, "Vhc:w:", longopts, &option); |
175 | 175 | ||
176 | if (c == -1 || c == EOF) | 176 | if (c == -1 || c == EOF) |
177 | break; | 177 | break; |
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 21efac2..849e636 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c | |||
@@ -149,8 +149,8 @@ process_arguments (int argc, char **argv) | |||
149 | { | 149 | { |
150 | int c; | 150 | int c; |
151 | 151 | ||
152 | int option_index = 0; | 152 | int option = 0; |
153 | static struct option long_options[] = { | 153 | static struct option longopts[] = { |
154 | {"logfile", required_argument, 0, 'F'}, | 154 | {"logfile", required_argument, 0, 'F'}, |
155 | {"expires", required_argument, 0, 'e'}, | 155 | {"expires", required_argument, 0, 'e'}, |
156 | {"aggregation", required_argument, 0, 'a'}, | 156 | {"aggregation", required_argument, 0, 'a'}, |
@@ -178,8 +178,8 @@ process_arguments (int argc, char **argv) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | while (1) { | 180 | while (1) { |
181 | c = getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", long_options, | 181 | c = getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", longopts, |
182 | &option_index); | 182 | &option); |
183 | 183 | ||
184 | if (c == -1 || c == EOF) | 184 | if (c == -1 || c == EOF) |
185 | break; | 185 | break; |
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index be2f562..93b2c1d 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c | |||
@@ -201,7 +201,7 @@ process_arguments (int argc, char **argv) | |||
201 | { | 201 | { |
202 | int c; | 202 | int c; |
203 | 203 | ||
204 | int option_index = 0; | 204 | int option = 0; |
205 | static struct option longopts[] = { | 205 | static struct option longopts[] = { |
206 | {"logfile", required_argument, 0, 'F'}, | 206 | {"logfile", required_argument, 0, 'F'}, |
207 | {"expires", required_argument, 0, 'e'}, | 207 | {"expires", required_argument, 0, 'e'}, |
@@ -228,7 +228,7 @@ process_arguments (int argc, char **argv) | |||
228 | } | 228 | } |
229 | 229 | ||
230 | while (1) { | 230 | while (1) { |
231 | c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option_index); | 231 | c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option); |
232 | 232 | ||
233 | if (c == -1 || c == EOF) | 233 | if (c == -1 || c == EOF) |
234 | break; | 234 | break; |
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 16a1f13..a7afa52 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
@@ -25,65 +25,23 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
25 | #include <mysql/mysql.h> | 25 | #include <mysql/mysql.h> |
26 | #include <mysql/errmsg.h> | 26 | #include <mysql/errmsg.h> |
27 | 27 | ||
28 | void | 28 | char *db_user = NULL; |
29 | print_usage (void) | 29 | char *db_host = NULL; |
30 | { | 30 | char *db_pass = NULL; |
31 | printf (_("\ | 31 | char *db = NULL; |
32 | Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"), | ||
33 | progname); | ||
34 | printf (_(UT_HLP_VRS), progname, progname); | ||
35 | } | ||
36 | |||
37 | void | ||
38 | print_help (void) | ||
39 | { | ||
40 | char *myport; | ||
41 | asprintf (&myport, "%d", MYSQL_PORT); | ||
42 | |||
43 | print_revision (progname, revision); | ||
44 | |||
45 | printf (_(COPYRIGHT), copyright, email); | ||
46 | |||
47 | printf (_("This program tests connections to a mysql server\n")); | ||
48 | |||
49 | print_usage (); | ||
50 | |||
51 | printf (_(UT_HELP_VRSN)); | ||
52 | |||
53 | printf (_(UT_HOST_PORT), 'P', myport); | ||
54 | |||
55 | printf (_("\ | ||
56 | -d, --database=STRING\n\ | ||
57 | Check database with indicated name\n\ | ||
58 | -u, --username=STRING\n\ | ||
59 | Connect using the indicated username\n\ | ||
60 | -p, --password=STRING\n\ | ||
61 | Use the indicated password to authenticate the connection\n\ | ||
62 | ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\ | ||
63 | Your clear-text password will be visible as a process table entry\n")); | ||
64 | |||
65 | printf (_("\n\ | ||
66 | There are no required arguments. By default, the local database with\n\ | ||
67 | a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT); | ||
68 | |||
69 | printf (_(UT_SUPPORT)); | ||
70 | } | ||
71 | |||
72 | char *db_user = ""; | ||
73 | char *db_host = ""; | ||
74 | char *db_pass = ""; | ||
75 | char *db = ""; | ||
76 | unsigned int db_port = MYSQL_PORT; | 32 | unsigned int db_port = MYSQL_PORT; |
77 | 33 | ||
78 | int process_arguments (int, char **); | 34 | int process_arguments (int, char **); |
79 | int validate_arguments (void); | 35 | int validate_arguments (void); |
36 | void print_help (void); | ||
37 | void print_usage (void); | ||
80 | 38 | ||
81 | int | 39 | int |
82 | main (int argc, char **argv) | 40 | main (int argc, char **argv) |
83 | { | 41 | { |
84 | 42 | ||
85 | MYSQL mysql; | 43 | MYSQL mysql; |
86 | char result[1024]; | 44 | char *result = NULL; |
87 | 45 | ||
88 | if (process_arguments (argc, argv) != OK) | 46 | if (process_arguments (argc, argv) != OK) |
89 | usage (_("Invalid command arguments supplied\n")); | 47 | usage (_("Invalid command arguments supplied\n")); |
@@ -92,62 +50,32 @@ main (int argc, char **argv) | |||
92 | mysql_init (&mysql); | 50 | mysql_init (&mysql); |
93 | 51 | ||
94 | /* establish a connection to the server and error checking */ | 52 | /* establish a connection to the server and error checking */ |
95 | if (!mysql_real_connect | 53 | if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) { |
96 | (&mysql, db_host, db_user, db_pass, db, db_port, NULL, 0)) { | 54 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) |
97 | 55 | die (STATE_WARNING, "%s\n", mysql_error (&mysql)); | |
98 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) { | 56 | else if (mysql_errno (&mysql) == CR_VERSION_ERROR) |
99 | printf ("%s\n", mysql_error (&mysql)); | 57 | die (STATE_WARNING, "%s\n", mysql_error (&mysql)); |
100 | return STATE_WARNING; | 58 | else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY) |
101 | 59 | die (STATE_WARNING, "%s\n", mysql_error (&mysql)); | |
102 | } | 60 | else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR) |
103 | else if (mysql_errno (&mysql) == CR_VERSION_ERROR) { | 61 | die (STATE_WARNING, "%s\n", mysql_error (&mysql)); |
104 | printf ("%s\n", mysql_error (&mysql)); | 62 | else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR) |
105 | return STATE_WARNING; | 63 | die (STATE_WARNING, "%s\n", mysql_error (&mysql)); |
106 | 64 | else | |
107 | } | 65 | die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); |
108 | else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY) { | ||
109 | printf ("%s\n", mysql_error (&mysql)); | ||
110 | return STATE_WARNING; | ||
111 | |||
112 | } | ||
113 | else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR) { | ||
114 | printf ("%s\n", mysql_error (&mysql)); | ||
115 | return STATE_WARNING; | ||
116 | |||
117 | } | ||
118 | else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR) { | ||
119 | printf ("%s\n", mysql_error (&mysql)); | ||
120 | return STATE_WARNING; | ||
121 | |||
122 | } | ||
123 | else { | ||
124 | printf ("%s\n", mysql_error (&mysql)); | ||
125 | return STATE_CRITICAL; | ||
126 | } | ||
127 | |||
128 | } | 66 | } |
129 | 67 | ||
130 | /* get the server stats */ | 68 | /* get the server stats */ |
131 | sprintf (result, mysql_stat (&mysql)); | 69 | result = strdup (mysql_stat (&mysql)); |
132 | 70 | ||
133 | /* error checking once more */ | 71 | /* error checking once more */ |
134 | if (mysql_error (&mysql)) { | 72 | if (mysql_error (&mysql)) { |
135 | 73 | if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR) | |
136 | if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR) { | 74 | die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); |
137 | printf ("%s\n", mysql_error (&mysql)); | 75 | else if (mysql_errno (&mysql) == CR_SERVER_LOST) |
138 | return STATE_CRITICAL; | 76 | die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); |
139 | 77 | else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR) | |
140 | } | 78 | die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); |
141 | else if (mysql_errno (&mysql) == CR_SERVER_LOST) { | ||
142 | printf ("%s\n", mysql_error (&mysql)); | ||
143 | return STATE_CRITICAL; | ||
144 | |||
145 | } | ||
146 | else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR) { | ||
147 | printf ("%s\n", mysql_error (&mysql)); | ||
148 | return STATE_UNKNOWN; | ||
149 | } | ||
150 | |||
151 | } | 79 | } |
152 | 80 | ||
153 | /* close the connection */ | 81 | /* close the connection */ |
@@ -169,8 +97,8 @@ process_arguments (int argc, char **argv) | |||
169 | { | 97 | { |
170 | int c; | 98 | int c; |
171 | 99 | ||
172 | int option_index = 0; | 100 | int option = 0; |
173 | static struct option long_options[] = { | 101 | static struct option longopts[] = { |
174 | {"hostname", required_argument, 0, 'H'}, | 102 | {"hostname", required_argument, 0, 'H'}, |
175 | {"database", required_argument, 0, 'd'}, | 103 | {"database", required_argument, 0, 'd'}, |
176 | {"username", required_argument, 0, 'u'}, | 104 | {"username", required_argument, 0, 'u'}, |
@@ -186,7 +114,7 @@ process_arguments (int argc, char **argv) | |||
186 | return ERROR; | 114 | return ERROR; |
187 | 115 | ||
188 | while (1) { | 116 | while (1) { |
189 | c = getopt_long (argc, argv, "hVP:p:u:d:H:", long_options, &option_index); | 117 | c = getopt_long (argc, argv, "hVP:p:u:d:H:", longopts, &option); |
190 | 118 | ||
191 | if (c == -1 || c == EOF) | 119 | if (c == -1 || c == EOF) |
192 | break; | 120 | break; |
@@ -256,5 +184,69 @@ process_arguments (int argc, char **argv) | |||
256 | int | 184 | int |
257 | validate_arguments (void) | 185 | validate_arguments (void) |
258 | { | 186 | { |
187 | if (db_user == NULL) | ||
188 | db_user = strdup(""); | ||
189 | |||
190 | if (db_host == NULL) | ||
191 | db_host = strdup(""); | ||
192 | |||
193 | if (db_pass == NULL) | ||
194 | db_pass == strdup(""); | ||
195 | |||
196 | if (db == NULL) | ||
197 | db = strdup(""); | ||
198 | |||
259 | return OK; | 199 | return OK; |
260 | } | 200 | } |
201 | |||
202 | |||
203 | |||
204 | |||
205 | |||
206 | |||
207 | void | ||
208 | print_help (void) | ||
209 | { | ||
210 | char *myport; | ||
211 | asprintf (&myport, "%d", MYSQL_PORT); | ||
212 | |||
213 | print_revision (progname, revision); | ||
214 | |||
215 | printf (_(COPYRIGHT), copyright, email); | ||
216 | |||
217 | printf (_("This program tests connections to a mysql server\n")); | ||
218 | |||
219 | print_usage (); | ||
220 | |||
221 | printf (_(UT_HELP_VRSN)); | ||
222 | |||
223 | printf (_(UT_HOST_PORT), 'P', myport); | ||
224 | |||
225 | printf (_("\ | ||
226 | -d, --database=STRING\n\ | ||
227 | Check database with indicated name\n\ | ||
228 | -u, --username=STRING\n\ | ||
229 | Connect using the indicated username\n\ | ||
230 | -p, --password=STRING\n\ | ||
231 | Use the indicated password to authenticate the connection\n\ | ||
232 | ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\ | ||
233 | Your clear-text password will be visible as a process table entry\n")); | ||
234 | |||
235 | printf (_("\n\ | ||
236 | There are no required arguments. By default, the local database with\n\ | ||
237 | a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT); | ||
238 | |||
239 | printf (_(UT_SUPPORT)); | ||
240 | } | ||
241 | |||
242 | |||
243 | |||
244 | |||
245 | void | ||
246 | print_usage (void) | ||
247 | { | ||
248 | printf (_("\ | ||
249 | Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"), | ||
250 | progname); | ||
251 | printf (_(UT_HLP_VRS), progname, progname); | ||
252 | } | ||
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index a678e2a..5b21ba1 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c | |||
@@ -25,48 +25,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
25 | #include "popen.h" | 25 | #include "popen.h" |
26 | #include "utils.h" | 26 | #include "utils.h" |
27 | 27 | ||
28 | void | ||
29 | print_usage (void) | ||
30 | { | ||
31 | printf (_("\ | ||
32 | Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"), | ||
33 | progname); | ||
34 | } | ||
35 | |||
36 | void | ||
37 | print_help (void) | ||
38 | { | ||
39 | print_revision (progname, revision); | ||
40 | |||
41 | printf (_(COPYRIGHT), copyright, email); | ||
42 | |||
43 | printf (_("\ | ||
44 | This plugin attempts to check the status of the Nagios process on the local\n\ | ||
45 | machine. The plugin will check to make sure the Nagios status log is no older\n\ | ||
46 | than the number of minutes specified by the <expire_minutes> option. It also\n\ | ||
47 | uses the /bin/ps command to check for a process matching whatever you specify\n\ | ||
48 | by the <process_string> argument.\n")); | ||
49 | |||
50 | print_usage (); | ||
51 | |||
52 | printf (_(UT_HELP_VRSN)); | ||
53 | |||
54 | printf (_("\ | ||
55 | -F, --filename=FILE\n\ | ||
56 | Name of the log file to check\n\ | ||
57 | -e, --expires=INTEGER\n\ | ||
58 | Seconds aging afterwhich logfile is condsidered stale\n\ | ||
59 | -C, --command=STRING\n\ | ||
60 | Command to search for in process table\n")); | ||
61 | |||
62 | printf (_("\ | ||
63 | Example:\n\ | ||
64 | ./check_nagios -e 5 \\\ | ||
65 | -F /usr/local/nagios/var/status.log \\\ | ||
66 | -C /usr/local/nagios/bin/nagios\n")); | ||
67 | } | ||
68 | |||
69 | int process_arguments (int, char **); | 28 | int process_arguments (int, char **); |
29 | void print_help (void); | ||
30 | void print_usage (void); | ||
70 | 31 | ||
71 | char *status_log = NULL; | 32 | char *status_log = NULL; |
72 | char *process_string = NULL; | 33 | char *process_string = NULL; |
@@ -198,8 +159,8 @@ process_arguments (int argc, char **argv) | |||
198 | { | 159 | { |
199 | int c; | 160 | int c; |
200 | 161 | ||
201 | int option_index = 0; | 162 | int option = 0; |
202 | static struct option long_options[] = { | 163 | static struct option longopts[] = { |
203 | {"filename", required_argument, 0, 'F'}, | 164 | {"filename", required_argument, 0, 'F'}, |
204 | {"expires", required_argument, 0, 'e'}, | 165 | {"expires", required_argument, 0, 'e'}, |
205 | {"command", required_argument, 0, 'C'}, | 166 | {"command", required_argument, 0, 'C'}, |
@@ -225,7 +186,7 @@ process_arguments (int argc, char **argv) | |||
225 | } | 186 | } |
226 | 187 | ||
227 | while (1) { | 188 | while (1) { |
228 | c = getopt_long (argc, argv, "+hVvF:C:e:", long_options, &option_index); | 189 | c = getopt_long (argc, argv, "+hVvF:C:e:", longopts, &option); |
229 | 190 | ||
230 | if (c == -1 || c == EOF || c == 1) | 191 | if (c == -1 || c == EOF || c == 1) |
231 | break; | 192 | break; |
@@ -252,8 +213,8 @@ process_arguments (int argc, char **argv) | |||
252 | expire_minutes = atoi (optarg); | 213 | expire_minutes = atoi (optarg); |
253 | else | 214 | else |
254 | die (STATE_UNKNOWN, | 215 | die (STATE_UNKNOWN, |
255 | _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"), | 216 | _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"), |
256 | progname); | 217 | progname); |
257 | break; | 218 | break; |
258 | case 'v': | 219 | case 'v': |
259 | verbose++; | 220 | verbose++; |
@@ -264,8 +225,8 @@ process_arguments (int argc, char **argv) | |||
264 | 225 | ||
265 | if (status_log == NULL) | 226 | if (status_log == NULL) |
266 | die (STATE_UNKNOWN, | 227 | die (STATE_UNKNOWN, |
267 | _("You must provide the status_log\nType '%s -h' for additional help\n"), | 228 | _("You must provide the status_log\nType '%s -h' for additional help\n"), |
268 | progname); | 229 | progname); |
269 | else if (process_string == NULL) | 230 | else if (process_string == NULL) |
270 | die (STATE_UNKNOWN, | 231 | die (STATE_UNKNOWN, |
271 | _("You must provide a process string\nType '%s -h' for additional help\n"), | 232 | _("You must provide a process string\nType '%s -h' for additional help\n"), |
@@ -273,3 +234,52 @@ process_arguments (int argc, char **argv) | |||
273 | 234 | ||
274 | return OK; | 235 | return OK; |
275 | } | 236 | } |
237 | |||
238 | |||
239 | |||
240 | |||
241 | |||
242 | |||
243 | void | ||
244 | print_help (void) | ||
245 | { | ||
246 | print_revision (progname, revision); | ||
247 | |||
248 | printf (_(COPYRIGHT), copyright, email); | ||
249 | |||
250 | printf (_("\ | ||
251 | This plugin attempts to check the status of the Nagios process on the local\n\ | ||
252 | machine. The plugin will check to make sure the Nagios status log is no older\n\ | ||
253 | than the number of minutes specified by the <expire_minutes> option. It also\n\ | ||
254 | uses the /bin/ps command to check for a process matching whatever you specify\n\ | ||
255 | by the <process_string> argument.\n")); | ||
256 | |||
257 | print_usage (); | ||
258 | |||
259 | printf (_(UT_HELP_VRSN)); | ||
260 | |||
261 | printf (_("\ | ||
262 | -F, --filename=FILE\n\ | ||
263 | Name of the log file to check\n\ | ||
264 | -e, --expires=INTEGER\n\ | ||
265 | Seconds aging afterwhich logfile is condsidered stale\n\ | ||
266 | -C, --command=STRING\n\ | ||
267 | Command to search for in process table\n")); | ||
268 | |||
269 | printf (_("\ | ||
270 | Example:\n\ | ||
271 | ./check_nagios -e 5 \\\ | ||
272 | -F /usr/local/nagios/var/status.log \\\ | ||
273 | -C /usr/local/nagios/bin/nagios\n")); | ||
274 | } | ||
275 | |||
276 | |||
277 | |||
278 | |||
279 | void | ||
280 | print_usage (void) | ||
281 | { | ||
282 | printf (_("\ | ||
283 | Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"), | ||
284 | progname); | ||
285 | } | ||
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index b1314d4..3b2bd5e 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
@@ -28,7 +28,6 @@ | |||
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | #include "config.h" | ||
32 | #include "common.h" | 31 | #include "common.h" |
33 | #include "netutils.h" | 32 | #include "netutils.h" |
34 | #include "utils.h" | 33 | #include "utils.h" |
@@ -331,8 +330,8 @@ int main(int argc, char **argv){ | |||
331 | int process_arguments(int argc, char **argv){ | 330 | int process_arguments(int argc, char **argv){ |
332 | int c; | 331 | int c; |
333 | 332 | ||
334 | int option_index = 0; | 333 | int option = 0; |
335 | static struct option long_options[] = | 334 | static struct option longopts[] = |
336 | { | 335 | { |
337 | {"port", required_argument,0,'p'}, | 336 | {"port", required_argument,0,'p'}, |
338 | {"timeout", required_argument,0,'t'}, | 337 | {"timeout", required_argument,0,'t'}, |
@@ -366,7 +365,7 @@ int process_arguments(int argc, char **argv){ | |||
366 | } | 365 | } |
367 | 366 | ||
368 | while (1){ | 367 | while (1){ |
369 | c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",long_options,&option_index); | 368 | c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",longopts,&option); |
370 | 369 | ||
371 | if (c==-1||c==EOF||c==1) | 370 | if (c==-1||c==EOF||c==1) |
372 | break; | 371 | break; |
@@ -385,10 +384,10 @@ int process_arguments(int argc, char **argv){ | |||
385 | exit(STATE_OK); | 384 | exit(STATE_OK); |
386 | case 'H': /* hostname */ | 385 | case 'H': /* hostname */ |
387 | if (server_address) free(server_address); | 386 | if (server_address) free(server_address); |
388 | server_address = strdup(optarg); | 387 | server_address = optarg; |
389 | break; | 388 | break; |
390 | case 's': /* password */ | 389 | case 's': /* password */ |
391 | req_password = strdup (optarg); | 390 | req_password = optarg; |
392 | break; | 391 | break; |
393 | case 'p': /* port */ | 392 | case 'p': /* port */ |
394 | if (is_intnonneg(optarg)) | 393 | if (is_intnonneg(optarg)) |
@@ -421,7 +420,7 @@ int process_arguments(int argc, char **argv){ | |||
421 | return ERROR; | 420 | return ERROR; |
422 | break; | 421 | break; |
423 | case 'l': /* value list */ | 422 | case 'l': /* value list */ |
424 | value_list = strdup (optarg); | 423 | value_list = optarg; |
425 | break; | 424 | break; |
426 | case 'w': /* warning threshold */ | 425 | case 'w': /* warning threshold */ |
427 | warning_value=strtoul(optarg,NULL,10); | 426 | warning_value=strtoul(optarg,NULL,10); |
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index 4b22726..92a1f11 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c | |||
@@ -705,8 +705,8 @@ main(int argc, char **argv) { | |||
705 | int process_arguments(int argc, char **argv) { | 705 | int process_arguments(int argc, char **argv) { |
706 | int c; | 706 | int c; |
707 | 707 | ||
708 | int option_index = 0; | 708 | int option = 0; |
709 | static struct option long_options[] = | 709 | static struct option longopts[] = |
710 | { | 710 | { |
711 | {"port", required_argument,0,'p'}, | 711 | {"port", required_argument,0,'p'}, |
712 | {"timeout", required_argument,0,'t'}, | 712 | {"timeout", required_argument,0,'t'}, |
@@ -741,7 +741,7 @@ int process_arguments(int argc, char **argv) { | |||
741 | } | 741 | } |
742 | 742 | ||
743 | while (1) { | 743 | while (1) { |
744 | c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",long_options,&option_index); | 744 | c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",longopts,&option); |
745 | 745 | ||
746 | if (c==-1||c==EOF||c==1) | 746 | if (c==-1||c==EOF||c==1) |
747 | break; | 747 | break; |
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index 9958432..67fb5d1 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c | |||
@@ -285,8 +285,8 @@ process_arguments (int argc, char **argv) | |||
285 | { | 285 | { |
286 | int c; | 286 | int c; |
287 | 287 | ||
288 | int option_index = 0; | 288 | int option = 0; |
289 | static struct option long_options[] = { | 289 | static struct option longopts[] = { |
290 | {"port", required_argument, 0, 'p'}, | 290 | {"port", required_argument, 0, 'p'}, |
291 | {"timeout", required_argument, 0, 't'}, | 291 | {"timeout", required_argument, 0, 't'}, |
292 | {"critical", required_argument, 0, 'c'}, | 292 | {"critical", required_argument, 0, 'c'}, |
@@ -320,8 +320,8 @@ process_arguments (int argc, char **argv) | |||
320 | } | 320 | } |
321 | 321 | ||
322 | while (1) { | 322 | while (1) { |
323 | c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", long_options, | 323 | c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", longopts, |
324 | &option_index); | 324 | &option); |
325 | 325 | ||
326 | if (c == -1 || c == EOF || c == 1) | 326 | if (c == -1 || c == EOF || c == 1) |
327 | break; | 327 | break; |
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 2dce0b3..6cd217e 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
@@ -1,26 +1,19 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | |
3 | * Program: PostgreSQL plugin for Nagios | 3 | This program is free software; you can redistribute it and/or modify |
4 | * License: GPL | 4 | it under the terms of the GNU General Public License as published by |
5 | * | 5 | the Free Software Foundation; either version 2 of the License, or |
6 | * License Information: | 6 | (at your option) any later version. |
7 | * | 7 | |
8 | * This program is free software; you can redistribute it and/or modify | 8 | This program is distributed in the hope that it will be useful, |
9 | * it under the terms of the GNU General Public License as published by | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * (at your option) any later version. | 11 | GNU General Public License for more details. |
12 | * | 12 | |
13 | * This program is distributed in the hope that it will be useful, | 13 | You should have received a copy of the GNU General Public License |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | along with this program; if not, write to the Free Software |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | * GNU General Public License for more details. | 16 | |
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | * | ||
22 | * $Id$ | ||
23 | * | ||
24 | *****************************************************************************/ | 17 | *****************************************************************************/ |
25 | 18 | ||
26 | #define DEFAULT_DB "template1" | 19 | #define DEFAULT_DB "template1" |
@@ -32,9 +25,9 @@ enum { | |||
32 | DEFAULT_CRIT = 8 | 25 | DEFAULT_CRIT = 8 |
33 | }; | 26 | }; |
34 | 27 | ||
35 | #include "config.h" | ||
36 | #include "common.h" | 28 | #include "common.h" |
37 | #include "utils.h" | 29 | #include "utils.h" |
30 | #include "netutils.h" | ||
38 | #include <libpq-fe.h> | 31 | #include <libpq-fe.h> |
39 | 32 | ||
40 | int process_arguments (int, char **); | 33 | int process_arguments (int, char **); |
@@ -121,72 +114,6 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. | |||
121 | 114 | ||
122 | 115 | ||
123 | 116 | ||
124 | void | ||
125 | print_help (void) | ||
126 | { | ||
127 | char *myport; | ||
128 | |||
129 | asprintf (&myport, "%d", DEFAULT_PORT); | ||
130 | |||
131 | print_revision (progname, revision); | ||
132 | |||
133 | printf (_(COPYRIGHT), copyright, email); | ||
134 | |||
135 | printf (_("Test whether a PostgreSQL DBMS is accepting connections.\n\n")); | ||
136 | |||
137 | print_usage (); | ||
138 | |||
139 | printf (_(UT_HELP_VRSN)); | ||
140 | |||
141 | printf (_(UT_HOST_PORT), 'P', myport); | ||
142 | |||
143 | printf (_(UT_IPv46)); | ||
144 | |||
145 | printf (S_("\ | ||
146 | -d, --database=STRING\n\ | ||
147 | Database to check (default: %s)\n\ | ||
148 | -l, --logname = STRING\n\ | ||
149 | Login name of user\n\ | ||
150 | -p, --password = STRING\n\ | ||
151 | Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB); | ||
152 | |||
153 | printf (_(UT_WARN_CRIT)); | ||
154 | |||
155 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
156 | |||
157 | printf (_(UT_VERBOSE)); | ||
158 | |||
159 | printf (S_("\nAll parameters are optional.\n\ | ||
160 | \n\ | ||
161 | This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\ | ||
162 | accepting queries. In its current operation, it simply connects to the\n\ | ||
163 | specified database, and then disconnects. If no database is specified, it\n\ | ||
164 | connects to the template1 database, which is present in every functioning \n\ | ||
165 | PostgreSQL DBMS.\n")); | ||
166 | printf (S_("\n\ | ||
167 | The plugin will connect to a local postmaster if no host is specified. To\n\ | ||
168 | connect to a remote host, be sure that the remote postmaster accepts TCP/IP\n\ | ||
169 | connections (start the postmaster with the -i option).\n")); | ||
170 | printf (S_("\n\ | ||
171 | Typically, the nagios user (unless the --logname option is used) should be\n\ | ||
172 | able to connect to the database without a password. The plugin can also send\n\ | ||
173 | a password, but no effort is made to obsure or encrypt the password.\n")); | ||
174 | |||
175 | support (); | ||
176 | } | ||
177 | |||
178 | void | ||
179 | print_usage (void) | ||
180 | { | ||
181 | printf (S_("\ | ||
182 | Usage:\n %s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n\ | ||
183 | [-t <timeout>]"), progname); | ||
184 | printf (S_("[-d <database>] [-l <logname>] [-p <password>]\n")); | ||
185 | printf (S_("\ | ||
186 | %s (-h | --help) for detailed help\n\ | ||
187 | %s (-V | --version) for version information\n"), | ||
188 | progname, progname); | ||
189 | } | ||
190 | 117 | ||
191 | int | 118 | int |
192 | main (int argc, char **argv) | 119 | main (int argc, char **argv) |
@@ -251,8 +178,8 @@ process_arguments (int argc, char **argv) | |||
251 | { | 178 | { |
252 | int c; | 179 | int c; |
253 | 180 | ||
254 | int option_index = 0; | 181 | int option = 0; |
255 | static struct option long_options[] = { | 182 | static struct option longopts[] = { |
256 | {"help", no_argument, 0, 'h'}, | 183 | {"help", no_argument, 0, 'h'}, |
257 | {"version", no_argument, 0, 'V'}, | 184 | {"version", no_argument, 0, 'V'}, |
258 | {"timeout", required_argument, 0, 't'}, | 185 | {"timeout", required_argument, 0, 't'}, |
@@ -269,7 +196,7 @@ process_arguments (int argc, char **argv) | |||
269 | 196 | ||
270 | while (1) { | 197 | while (1) { |
271 | c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:", | 198 | c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:", |
272 | long_options, &option_index); | 199 | longopts, &option); |
273 | 200 | ||
274 | if (c == EOF) | 201 | if (c == EOF) |
275 | break; | 202 | break; |
@@ -277,6 +204,7 @@ process_arguments (int argc, char **argv) | |||
277 | switch (c) { | 204 | switch (c) { |
278 | case '?': /* usage */ | 205 | case '?': /* usage */ |
279 | usage3 (_("Unknown argument"), optopt); | 206 | usage3 (_("Unknown argument"), optopt); |
207 | break; | ||
280 | case 'h': /* help */ | 208 | case 'h': /* help */ |
281 | print_help (); | 209 | print_help (); |
282 | exit (STATE_OK); | 210 | exit (STATE_OK); |
@@ -286,38 +214,44 @@ process_arguments (int argc, char **argv) | |||
286 | case 't': /* timeout period */ | 214 | case 't': /* timeout period */ |
287 | if (!is_integer (optarg)) | 215 | if (!is_integer (optarg)) |
288 | usage2 (_("Timeout Interval must be an integer"), optarg); | 216 | usage2 (_("Timeout Interval must be an integer"), optarg); |
289 | timeout_interval = atoi (optarg); | 217 | else |
218 | timeout_interval = atoi (optarg); | ||
290 | break; | 219 | break; |
291 | case 'c': /* critical time threshold */ | 220 | case 'c': /* critical time threshold */ |
292 | if (!is_integer (optarg)) | 221 | if (!is_integer (optarg)) |
293 | usage2 (_("Invalid critical threshold"), optarg); | 222 | usage2 (_("Invalid critical threshold"), optarg); |
294 | tcrit = atoi (optarg); | 223 | else |
224 | tcrit = atoi (optarg); | ||
295 | break; | 225 | break; |
296 | case 'w': /* warning time threshold */ | 226 | case 'w': /* warning time threshold */ |
297 | if (!is_integer (optarg)) | 227 | if (!is_integer (optarg)) |
298 | usage2 (_("Invalid critical threshold"), optarg); | 228 | usage2 (_("Invalid critical threshold"), optarg); |
299 | twarn = atoi (optarg); | 229 | else |
230 | twarn = atoi (optarg); | ||
300 | break; | 231 | break; |
301 | case 'H': /* host */ | 232 | case 'H': /* host */ |
302 | if (!is_host (optarg)) | 233 | if (!is_host (optarg)) |
303 | usage2 (_("You gave an invalid host name"), optarg); | 234 | usage2 (_("You gave an invalid host name"), optarg); |
304 | pghost = optarg; | 235 | else |
236 | pghost = optarg; | ||
305 | break; | 237 | break; |
306 | case 'P': /* port */ | 238 | case 'P': /* port */ |
307 | if (!is_integer (optarg)) | 239 | if (!is_integer (optarg)) |
308 | usage2 (_("Port must be an integer"), optarg); | 240 | usage2 (_("Port must be an integer"), optarg); |
309 | pgport = optarg; | 241 | else |
242 | pgport = optarg; | ||
310 | break; | 243 | break; |
311 | case 'd': /* database name */ | 244 | case 'd': /* database name */ |
312 | if (!is_pg_dbname (optarg)) | 245 | if (!is_pg_dbname (optarg)) /* checks length and valid chars */ |
313 | usage2 (_("Database name is not valid"), optarg); | 246 | usage2 (_("Database name is not valid"), optarg); |
314 | strncpy (dbName, optarg, NAMEDATALEN - 1); | 247 | else /* we know length, and know optarg is terminated, so us strcpy */ |
315 | dbName[NAMEDATALEN - 1] = 0; | 248 | strcpy (dbName, optarg); |
316 | break; | 249 | break; |
317 | case 'l': /* login name */ | 250 | case 'l': /* login name */ |
318 | if (!is_pg_logname (optarg)) | 251 | if (!is_pg_logname (optarg)) |
319 | usage2 (_("user name is not valid"), optarg); | 252 | usage2 (_("user name is not valid"), optarg); |
320 | pguser = optarg; | 253 | else |
254 | pguser = optarg; | ||
321 | break; | 255 | break; |
322 | case 'p': /* authentication password */ | 256 | case 'p': /* authentication password */ |
323 | case 'a': | 257 | case 'a': |
@@ -433,3 +367,78 @@ is_pg_logname (char *username) | |||
433 | </article> | 367 | </article> |
434 | -@@ | 368 | -@@ |
435 | ******************************************************************************/ | 369 | ******************************************************************************/ |
370 | |||
371 | |||
372 | |||
373 | |||
374 | |||
375 | void | ||
376 | print_help (void) | ||
377 | { | ||
378 | char *myport; | ||
379 | |||
380 | asprintf (&myport, "%d", DEFAULT_PORT); | ||
381 | |||
382 | print_revision (progname, revision); | ||
383 | |||
384 | printf (_(COPYRIGHT), copyright, email); | ||
385 | |||
386 | printf (_("Test whether a PostgreSQL DBMS is accepting connections.\n\n")); | ||
387 | |||
388 | print_usage (); | ||
389 | |||
390 | printf (_(UT_HELP_VRSN)); | ||
391 | |||
392 | printf (_(UT_HOST_PORT), 'P', myport); | ||
393 | |||
394 | printf (_(UT_IPv46)); | ||
395 | |||
396 | printf (S_("\ | ||
397 | -d, --database=STRING\n\ | ||
398 | Database to check (default: %s)\n\ | ||
399 | -l, --logname = STRING\n\ | ||
400 | Login name of user\n\ | ||
401 | -p, --password = STRING\n\ | ||
402 | Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB); | ||
403 | |||
404 | printf (_(UT_WARN_CRIT)); | ||
405 | |||
406 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
407 | |||
408 | printf (_(UT_VERBOSE)); | ||
409 | |||
410 | printf (S_("\nAll parameters are optional.\n\ | ||
411 | \n\ | ||
412 | This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\ | ||
413 | accepting queries. In its current operation, it simply connects to the\n\ | ||
414 | specified database, and then disconnects. If no database is specified, it\n\ | ||
415 | connects to the template1 database, which is present in every functioning \n\ | ||
416 | PostgreSQL DBMS.\n")); | ||
417 | printf (S_("\n\ | ||
418 | The plugin will connect to a local postmaster if no host is specified. To\n\ | ||
419 | connect to a remote host, be sure that the remote postmaster accepts TCP/IP\n\ | ||
420 | connections (start the postmaster with the -i option).\n")); | ||
421 | printf (S_("\n\ | ||
422 | Typically, the nagios user (unless the --logname option is used) should be\n\ | ||
423 | able to connect to the database without a password. The plugin can also send\n\ | ||
424 | a password, but no effort is made to obsure or encrypt the password.\n")); | ||
425 | |||
426 | printf (_(UT_SUPPORT)); | ||
427 | } | ||
428 | |||
429 | |||
430 | |||
431 | |||
432 | void | ||
433 | print_usage (void) | ||
434 | { | ||
435 | printf (S_("\ | ||
436 | Usage:\n %s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n\ | ||
437 | [-t <timeout>]"), progname); | ||
438 | printf (S_("[-d <database>] [-l <logname>] [-p <password>]\n")); | ||
439 | printf (S_("\ | ||
440 | %s (-h | --help) for detailed help\n\ | ||
441 | %s (-V | --version) for version information\n"), | ||
442 | progname, progname); | ||
443 | } | ||
444 | |||
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index fd73b8c..87f9db0 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -162,8 +162,8 @@ process_arguments (int argc, char **argv) | |||
162 | int c = 1; | 162 | int c = 1; |
163 | char *ptr; | 163 | char *ptr; |
164 | 164 | ||
165 | int option_index = 0; | 165 | int option = 0; |
166 | static struct option long_options[] = { | 166 | static struct option longopts[] = { |
167 | STD_LONG_OPTS, | 167 | STD_LONG_OPTS, |
168 | {"packets", required_argument, 0, 'p'}, | 168 | {"packets", required_argument, 0, 'p'}, |
169 | {"nohtml", no_argument, 0, 'n'}, | 169 | {"nohtml", no_argument, 0, 'n'}, |
@@ -184,7 +184,7 @@ process_arguments (int argc, char **argv) | |||
184 | } | 184 | } |
185 | 185 | ||
186 | while (1) { | 186 | while (1) { |
187 | c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", long_options, &option_index); | 187 | c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option); |
188 | 188 | ||
189 | if (c == -1 || c == EOF) | 189 | if (c == -1 || c == EOF) |
190 | break; | 190 | break; |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 1894b28..5313b97 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -278,8 +278,8 @@ process_arguments (int argc, char **argv) | |||
278 | int c = 1; | 278 | int c = 1; |
279 | char *user; | 279 | char *user; |
280 | struct passwd *pw; | 280 | struct passwd *pw; |
281 | int option_index = 0; | 281 | int option = 0; |
282 | static struct option long_options[] = { | 282 | static struct option longopts[] = { |
283 | {"warning", required_argument, 0, 'w'}, | 283 | {"warning", required_argument, 0, 'w'}, |
284 | {"critical", required_argument, 0, 'c'}, | 284 | {"critical", required_argument, 0, 'c'}, |
285 | {"metric", required_argument, 0, 'm'}, | 285 | {"metric", required_argument, 0, 'm'}, |
@@ -303,7 +303,7 @@ process_arguments (int argc, char **argv) | |||
303 | 303 | ||
304 | while (1) { | 304 | while (1) { |
305 | c = getopt_long (argc, argv, "Vvht:c:w:p:s:u:C:a:z:r:m:P:", | 305 | c = getopt_long (argc, argv, "Vvht:c:w:p:s:u:C:a:z:r:m:P:", |
306 | long_options, &option_index); | 306 | longopts, &option); |
307 | 307 | ||
308 | if (c == -1 || c == EOF) | 308 | if (c == -1 || c == EOF) |
309 | break; | 309 | break; |
@@ -362,7 +362,7 @@ process_arguments (int argc, char **argv) | |||
362 | if (statopts) | 362 | if (statopts) |
363 | break; | 363 | break; |
364 | else | 364 | else |
365 | statopts = strdup(optarg); | 365 | statopts = optarg; |
366 | asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts); | 366 | asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts); |
367 | options |= STAT; | 367 | options |= STAT; |
368 | break; | 368 | break; |
@@ -397,7 +397,7 @@ process_arguments (int argc, char **argv) | |||
397 | if (prog) | 397 | if (prog) |
398 | break; | 398 | break; |
399 | else | 399 | else |
400 | prog = strdup(optarg); | 400 | prog = optarg; |
401 | asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""), | 401 | asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""), |
402 | prog); | 402 | prog); |
403 | options |= PROG; | 403 | options |= PROG; |
@@ -406,7 +406,7 @@ process_arguments (int argc, char **argv) | |||
406 | if (args) | 406 | if (args) |
407 | break; | 407 | break; |
408 | else | 408 | else |
409 | args = strdup(optarg); | 409 | args = optarg; |
410 | asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args); | 410 | asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args); |
411 | options |= ARGS; | 411 | options |= ARGS; |
412 | break; | 412 | break; |
diff --git a/plugins/check_radius.c b/plugins/check_radius.c index 714de58..1e4fff7 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c | |||
@@ -21,79 +21,21 @@ const char *revision = "$Revision$"; | |||
21 | const char *copyright = "2000-2003"; | 21 | const char *copyright = "2000-2003"; |
22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
23 | 23 | ||
24 | #include "config.h" | ||
25 | #include "common.h" | 24 | #include "common.h" |
26 | #include "utils.h" | 25 | #include "utils.h" |
26 | #include "netutils.h" | ||
27 | #include <radiusclient.h> | 27 | #include <radiusclient.h> |
28 | 28 | ||
29 | void | ||
30 | print_usage (void) | ||
31 | { | ||
32 | printf ("\ | ||
33 | Usage: %s -H host -F config_file -u username -p password [-P port]\n\ | ||
34 | [-t timeout] [-r retries] [-e expect]\n", progname); | ||
35 | printf (_(UT_HLP_VRS), progname, progname); | ||
36 | } | ||
37 | |||
38 | void | ||
39 | print_help (void) | ||
40 | { | ||
41 | char *myport; | ||
42 | asprintf (&myport, "%d", PW_AUTH_UDP_PORT); | ||
43 | |||
44 | print_revision (progname, revision); | ||
45 | |||
46 | printf (_("Copyright (c) 1999 Robert August Vincent II\n")); | ||
47 | printf (_(COPYRIGHT), copyright, email); | ||
48 | |||
49 | printf(_("Tests to see if a radius server is accepting connections.\n\n")); | ||
50 | |||
51 | print_usage (); | ||
52 | |||
53 | printf (_(UT_HELP_VRSN)); | ||
54 | |||
55 | printf (_(UT_HOST_PORT), 'P', myport); | ||
56 | |||
57 | printf (_("\ | ||
58 | -u, --username=STRING\n\ | ||
59 | The user to authenticate\n\ | ||
60 | -p, --password=STRING\n\ | ||
61 | Password for autentication (SECURITY RISK)\n\ | ||
62 | -F, --filename=STRING\n\ | ||
63 | Configuration file\n\ | ||
64 | -e, --expect=STRING\n\ | ||
65 | Response string to expect from the server\n\ | ||
66 | -r, --retries=INTEGER\n\ | ||
67 | Number of times to retry a failed connection\n")); | ||
68 | |||
69 | printf (_(UT_TIMEOUT), timeout_interval); | ||
70 | |||
71 | printf (_("\n\ | ||
72 | This plugin tests a radius server to see if it is accepting connections.\n\ | ||
73 | \n\ | ||
74 | The server to test must be specified in the invocation, as well as a user\n\ | ||
75 | name and password. A configuration file may also be present. The format of\n\ | ||
76 | the configuration file is described in the radiusclient library sources.\n\n")); | ||
77 | |||
78 | printf (_("\ | ||
79 | The password option presents a substantial security issue because the\n\ | ||
80 | password can be determined by careful watching of the command line in\n\ | ||
81 | a process listing. This risk is exacerbated because nagios will\n\ | ||
82 | run the plugin at regular prdictable intervals. Please be sure that\n\ | ||
83 | the password used does not allow access to sensitive system resources,\n\ | ||
84 | otherwise compormise could occur.\n")); | ||
85 | |||
86 | printf (_(UT_SUPPORT)); | ||
87 | } | ||
88 | |||
89 | int process_arguments (int, char **); | 29 | int process_arguments (int, char **); |
30 | void print_help (void); | ||
31 | void print_usage (void); | ||
90 | 32 | ||
91 | char *server = NULL; | 33 | char *server = NULL; |
92 | char *username = NULL; | 34 | char *username = NULL; |
93 | char *password = NULL; | 35 | char *password = NULL; |
94 | char *expect = NULL; | 36 | char *expect = NULL; |
95 | char *config_file = NULL; | 37 | char *config_file = NULL; |
96 | int port = PW_AUTH_UDP_PORT; | 38 | unsigned short port = PW_AUTH_UDP_PORT; |
97 | int retries = 1; | 39 | int retries = 1; |
98 | int verbose = FALSE; | 40 | int verbose = FALSE; |
99 | ENV *env = NULL; | 41 | ENV *env = NULL; |
@@ -159,12 +101,14 @@ main (int argc, char **argv) | |||
159 | SEND_DATA data; | 101 | SEND_DATA data; |
160 | int result; | 102 | int result; |
161 | UINT4 client_id; | 103 | UINT4 client_id; |
104 | char *str; | ||
162 | 105 | ||
163 | if (process_arguments (argc, argv) == ERROR) | 106 | if (process_arguments (argc, argv) == ERROR) |
164 | usage (_("Could not parse arguments\n")); | 107 | usage (_("Could not parse arguments\n")); |
165 | 108 | ||
109 | str = strdup ("dictionary"); | ||
166 | if ((config_file && rc_read_config (config_file)) || | 110 | if ((config_file && rc_read_config (config_file)) || |
167 | rc_read_dictionary (rc_conf_str ("dictionary"))) | 111 | rc_read_dictionary (rc_conf_str (str))) |
168 | die (STATE_UNKNOWN, _("Config file error")); | 112 | die (STATE_UNKNOWN, _("Config file error")); |
169 | 113 | ||
170 | service = PW_AUTHENTICATE_ONLY; | 114 | service = PW_AUTHENTICATE_ONLY; |
@@ -184,8 +128,8 @@ main (int argc, char **argv) | |||
184 | if (rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == | 128 | if (rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == |
185 | NULL) return (ERROR_RC); | 129 | NULL) return (ERROR_RC); |
186 | 130 | ||
187 | rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, timeout_interval, | 131 | rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, (int)timeout_interval, |
188 | retries); | 132 | retries); |
189 | 133 | ||
190 | result = rc_send_server (&data, msg); | 134 | result = rc_send_server (&data, msg); |
191 | rc_avpair_free (data.send_pairs); | 135 | rc_avpair_free (data.send_pairs); |
@@ -199,7 +143,7 @@ main (int argc, char **argv) | |||
199 | if (result == BADRESP_RC) | 143 | if (result == BADRESP_RC) |
200 | die (STATE_WARNING, _("Auth Failed")); | 144 | die (STATE_WARNING, _("Auth Failed")); |
201 | if (expect && !strstr (msg, expect)) | 145 | if (expect && !strstr (msg, expect)) |
202 | die (STATE_WARNING, msg); | 146 | die (STATE_WARNING, "%s", msg); |
203 | if (result == OK_RC) | 147 | if (result == OK_RC) |
204 | die (STATE_OK, _("Auth OK")); | 148 | die (STATE_OK, _("Auth OK")); |
205 | return (0); | 149 | return (0); |
@@ -213,8 +157,8 @@ process_arguments (int argc, char **argv) | |||
213 | { | 157 | { |
214 | int c; | 158 | int c; |
215 | 159 | ||
216 | int option_index = 0; | 160 | int option = 0; |
217 | static struct option long_options[] = { | 161 | static struct option longopts[] = { |
218 | {"hostname", required_argument, 0, 'H'}, | 162 | {"hostname", required_argument, 0, 'H'}, |
219 | {"port", required_argument, 0, 'P'}, | 163 | {"port", required_argument, 0, 'P'}, |
220 | {"username", required_argument, 0, 'u'}, | 164 | {"username", required_argument, 0, 'u'}, |
@@ -254,8 +198,8 @@ process_arguments (int argc, char **argv) | |||
254 | } | 198 | } |
255 | 199 | ||
256 | while (1) { | 200 | while (1) { |
257 | c = getopt_long (argc, argv, "+hVvH:P:F:u:p:t:r:e:", long_options, | 201 | c = getopt_long (argc, argv, "+hVvH:P:F:u:p:t:r:e:", longopts, |
258 | &option_index); | 202 | &option); |
259 | 203 | ||
260 | if (c == -1 || c == EOF || c == 1) | 204 | if (c == -1 || c == EOF || c == 1) |
261 | break; | 205 | break; |
@@ -316,3 +260,71 @@ process_arguments (int argc, char **argv) | |||
316 | } | 260 | } |
317 | return OK; | 261 | return OK; |
318 | } | 262 | } |
263 | |||
264 | |||
265 | |||
266 | |||
267 | |||
268 | |||
269 | void | ||
270 | print_help (void) | ||
271 | { | ||
272 | char *myport; | ||
273 | asprintf (&myport, "%d", PW_AUTH_UDP_PORT); | ||
274 | |||
275 | print_revision (progname, revision); | ||
276 | |||
277 | printf (_("Copyright (c) 1999 Robert August Vincent II\n")); | ||
278 | printf (_(COPYRIGHT), copyright, email); | ||
279 | |||
280 | printf(_("Tests to see if a radius server is accepting connections.\n\n")); | ||
281 | |||
282 | print_usage (); | ||
283 | |||
284 | printf (_(UT_HELP_VRSN)); | ||
285 | |||
286 | printf (_(UT_HOST_PORT), 'P', myport); | ||
287 | |||
288 | printf (_("\ | ||
289 | -u, --username=STRING\n\ | ||
290 | The user to authenticate\n\ | ||
291 | -p, --password=STRING\n\ | ||
292 | Password for autentication (SECURITY RISK)\n\ | ||
293 | -F, --filename=STRING\n\ | ||
294 | Configuration file\n\ | ||
295 | -e, --expect=STRING\n\ | ||
296 | Response string to expect from the server\n\ | ||
297 | -r, --retries=INTEGER\n\ | ||
298 | Number of times to retry a failed connection\n")); | ||
299 | |||
300 | printf (_(UT_TIMEOUT), timeout_interval); | ||
301 | |||
302 | printf (_("\n\ | ||
303 | This plugin tests a radius server to see if it is accepting connections.\n\ | ||
304 | \n\ | ||
305 | The server to test must be specified in the invocation, as well as a user\n\ | ||
306 | name and password. A configuration file may also be present. The format of\n\ | ||
307 | the configuration file is described in the radiusclient library sources.\n\n")); | ||
308 | |||
309 | printf (_("\ | ||
310 | The password option presents a substantial security issue because the\n\ | ||
311 | password can be determined by careful watching of the command line in\n\ | ||
312 | a process listing. This risk is exacerbated because nagios will\n\ | ||
313 | run the plugin at regular prdictable intervals. Please be sure that\n\ | ||
314 | the password used does not allow access to sensitive system resources,\n\ | ||
315 | otherwise compormise could occur.\n")); | ||
316 | |||
317 | printf (_(UT_SUPPORT)); | ||
318 | } | ||
319 | |||
320 | |||
321 | |||
322 | |||
323 | void | ||
324 | print_usage (void) | ||
325 | { | ||
326 | printf ("\ | ||
327 | Usage: %s -H host -F config_file -u username -p password [-P port]\n\ | ||
328 | [-t timeout] [-r retries] [-e expect]\n", progname); | ||
329 | printf (_(UT_HLP_VRS), progname, progname); | ||
330 | } | ||
diff --git a/plugins/check_real.c b/plugins/check_real.c index 9c9c3e0..3e8475a 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
@@ -256,8 +256,8 @@ process_arguments (int argc, char **argv) | |||
256 | { | 256 | { |
257 | int c; | 257 | int c; |
258 | 258 | ||
259 | int option_index = 0; | 259 | int option = 0; |
260 | static struct option long_options[] = { | 260 | static struct option longopts[] = { |
261 | {"hostname", required_argument, 0, 'H'}, | 261 | {"hostname", required_argument, 0, 'H'}, |
262 | {"IPaddress", required_argument, 0, 'I'}, | 262 | {"IPaddress", required_argument, 0, 'I'}, |
263 | {"expect", required_argument, 0, 'e'}, | 263 | {"expect", required_argument, 0, 'e'}, |
@@ -285,8 +285,8 @@ process_arguments (int argc, char **argv) | |||
285 | } | 285 | } |
286 | 286 | ||
287 | while (1) { | 287 | while (1) { |
288 | c = getopt_long (argc, argv, "+hVI:H:e:u:p:w:c:t:", long_options, | 288 | c = getopt_long (argc, argv, "+hVI:H:e:u:p:w:c:t:", longopts, |
289 | &option_index); | 289 | &option); |
290 | 290 | ||
291 | if (c == -1 || c == EOF) | 291 | if (c == -1 || c == EOF) |
292 | break; | 292 | break; |
@@ -297,15 +297,15 @@ process_arguments (int argc, char **argv) | |||
297 | if (server_address) | 297 | if (server_address) |
298 | break; | 298 | break; |
299 | else if (is_host (optarg)) | 299 | else if (is_host (optarg)) |
300 | server_address = strdup(optarg); | 300 | server_address = optarg; |
301 | else | 301 | else |
302 | usage (_("Invalid host name\n")); | 302 | usage (_("Invalid host name\n")); |
303 | break; | 303 | break; |
304 | case 'e': /* string to expect in response header */ | 304 | case 'e': /* string to expect in response header */ |
305 | server_expect = strdup(optarg); | 305 | server_expect = optarg; |
306 | break; | 306 | break; |
307 | case 'u': /* server URL */ | 307 | case 'u': /* server URL */ |
308 | server_url = strdup(optarg); | 308 | server_url = optarg; |
309 | break; | 309 | break; |
310 | case 'p': /* port */ | 310 | case 'p': /* port */ |
311 | if (is_intpos (optarg)) { | 311 | if (is_intpos (optarg)) { |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index c4e427a..41ed5f3 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -183,8 +183,8 @@ process_arguments (int argc, char **argv) | |||
183 | { | 183 | { |
184 | int c; | 184 | int c; |
185 | 185 | ||
186 | int option_index = 0; | 186 | int option = 0; |
187 | static struct option long_options[] = { | 187 | static struct option longopts[] = { |
188 | {"hostname", required_argument, 0, 'H'}, | 188 | {"hostname", required_argument, 0, 'H'}, |
189 | {"expect", required_argument, 0, 'e'}, | 189 | {"expect", required_argument, 0, 'e'}, |
190 | {"critical", required_argument, 0, 'c'}, | 190 | {"critical", required_argument, 0, 'c'}, |
@@ -216,7 +216,7 @@ process_arguments (int argc, char **argv) | |||
216 | 216 | ||
217 | while (1) { | 217 | while (1) { |
218 | c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:", | 218 | c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:", |
219 | long_options, &option_index); | 219 | longopts, &option); |
220 | 220 | ||
221 | if (c == -1 || c == EOF) | 221 | if (c == -1 || c == EOF) |
222 | break; | 222 | break; |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index e22d8a0..af8f119 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -84,7 +84,7 @@ int errcode, excode; | |||
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | char *server_address = NULL; | 86 | char *server_address = NULL; |
87 | char *community = DEFAULT_COMMUNITY; | 87 | char *community = NULL; |
88 | char *authpriv = NULL; | 88 | char *authpriv = NULL; |
89 | char *proto = NULL; | 89 | char *proto = NULL; |
90 | char *seclevel = NULL; | 90 | char *seclevel = NULL; |
@@ -92,17 +92,17 @@ char *secname = NULL; | |||
92 | char *authproto = NULL; | 92 | char *authproto = NULL; |
93 | char *authpasswd = NULL; | 93 | char *authpasswd = NULL; |
94 | char *privpasswd = NULL; | 94 | char *privpasswd = NULL; |
95 | char *oid = ""; | 95 | char *oid; |
96 | char *label = "SNMP"; | 96 | char *label; |
97 | char *units = ""; | 97 | char *units; |
98 | char *port = DEFAULT_PORT; | 98 | char *port; |
99 | char string_value[MAX_INPUT_BUFFER] = ""; | 99 | char string_value[MAX_INPUT_BUFFER] = ""; |
100 | char **labels = NULL; | 100 | char **labels = NULL; |
101 | char **unitv = NULL; | 101 | char **unitv = NULL; |
102 | int nlabels = 0; | 102 | size_t nlabels = 0; |
103 | int labels_size = 8; | 103 | size_t labels_size = 8; |
104 | int nunits = 0; | 104 | size_t nunits = 0; |
105 | int unitv_size = 8; | 105 | size_t unitv_size = 8; |
106 | int verbose = FALSE; | 106 | int verbose = FALSE; |
107 | unsigned long lower_warn_lim[MAX_OIDS]; | 107 | unsigned long lower_warn_lim[MAX_OIDS]; |
108 | unsigned long upper_warn_lim[MAX_OIDS]; | 108 | unsigned long upper_warn_lim[MAX_OIDS]; |
@@ -112,9 +112,9 @@ unsigned long response_value[MAX_OIDS]; | |||
112 | int check_warning_value = FALSE; | 112 | int check_warning_value = FALSE; |
113 | int check_critical_value = FALSE; | 113 | int check_critical_value = FALSE; |
114 | int eval_method[MAX_OIDS]; | 114 | int eval_method[MAX_OIDS]; |
115 | char *delimiter = DEFAULT_DELIMITER; | 115 | char *delimiter; |
116 | char *output_delim = DEFAULT_OUTPUT_DELIMITER; | 116 | char *output_delim; |
117 | char *miblist = DEFAULT_MIBLIST; | 117 | char *miblist; |
118 | 118 | ||
119 | 119 | ||
120 | 120 | ||
@@ -131,8 +131,8 @@ main (int argc, char **argv) | |||
131 | char input_buffer[MAX_INPUT_BUFFER]; | 131 | char input_buffer[MAX_INPUT_BUFFER]; |
132 | char *command_line = NULL; | 132 | char *command_line = NULL; |
133 | char *response = NULL; | 133 | char *response = NULL; |
134 | char *outbuff = ""; | 134 | char *outbuff; |
135 | char *output = ""; | 135 | char *output; |
136 | char *ptr = NULL; | 136 | char *ptr = NULL; |
137 | char *p2 = NULL; | 137 | char *p2 = NULL; |
138 | char *show = NULL; | 138 | char *show = NULL; |
@@ -143,6 +143,16 @@ main (int argc, char **argv) | |||
143 | eval_method[i] = CHECK_UNDEF; | 143 | eval_method[i] = CHECK_UNDEF; |
144 | i = 0; | 144 | i = 0; |
145 | 145 | ||
146 | oid = strdup (""); | ||
147 | label = strdup ("SNMP"); | ||
148 | units = strdup (""); | ||
149 | port = strdup (DEFAULT_PORT); | ||
150 | outbuff = strdup (""); | ||
151 | output = strdup (""); | ||
152 | delimiter = strdup (DEFAULT_DELIMITER); | ||
153 | output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); | ||
154 | miblist = strdup (DEFAULT_MIBLIST); | ||
155 | |||
146 | if (process_arguments (argc, argv) == ERROR) | 156 | if (process_arguments (argc, argv) == ERROR) |
147 | usage (_("Incorrect arguments supplied\n")); | 157 | usage (_("Incorrect arguments supplied\n")); |
148 | 158 | ||
@@ -287,7 +297,7 @@ main (int argc, char **argv) | |||
287 | result = max_state (result, iresult); | 297 | result = max_state (result, iresult); |
288 | 298 | ||
289 | /* Prepend a label for this OID if there is one */ | 299 | /* Prepend a label for this OID if there is one */ |
290 | if (nlabels > 1 && i < nlabels && labels[i] != NULL) | 300 | if (nlabels > (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) |
291 | asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, | 301 | asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, |
292 | (i == 0) ? " " : output_delim, | 302 | (i == 0) ? " " : output_delim, |
293 | labels[i], mark (iresult), show, mark (iresult)); | 303 | labels[i], mark (iresult), show, mark (iresult)); |
@@ -296,7 +306,7 @@ main (int argc, char **argv) | |||
296 | mark (iresult), show, mark (iresult)); | 306 | mark (iresult), show, mark (iresult)); |
297 | 307 | ||
298 | /* Append a unit string for this OID if there is one */ | 308 | /* Append a unit string for this OID if there is one */ |
299 | if (nunits > 0 && i < nunits && unitv[i] != NULL) | 309 | if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) |
300 | asprintf (&outbuff, "%s %s", outbuff, unitv[i]); | 310 | asprintf (&outbuff, "%s %s", outbuff, unitv[i]); |
301 | 311 | ||
302 | i++; | 312 | i++; |
@@ -341,8 +351,8 @@ process_arguments (int argc, char **argv) | |||
341 | int c = 1; | 351 | int c = 1; |
342 | int j = 0, jj = 0, ii = 0; | 352 | int j = 0, jj = 0, ii = 0; |
343 | 353 | ||
344 | int option_index = 0; | 354 | int option = 0; |
345 | static struct option long_options[] = { | 355 | static struct option longopts[] = { |
346 | STD_LONG_OPTS, | 356 | STD_LONG_OPTS, |
347 | {"community", required_argument, 0, 'C'}, | 357 | {"community", required_argument, 0, 'C'}, |
348 | {"oid", required_argument, 0, 'o'}, | 358 | {"oid", required_argument, 0, 'o'}, |
@@ -381,7 +391,7 @@ process_arguments (int argc, char **argv) | |||
381 | 391 | ||
382 | while (1) { | 392 | while (1) { |
383 | c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:", | 393 | c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:", |
384 | long_options, &option_index); | 394 | longopts, &option); |
385 | 395 | ||
386 | if (c == -1 || c == EOF) | 396 | if (c == -1 || c == EOF) |
387 | break; | 397 | break; |
@@ -401,34 +411,34 @@ process_arguments (int argc, char **argv) | |||
401 | 411 | ||
402 | /* Connection info */ | 412 | /* Connection info */ |
403 | case 'C': /* group or community */ | 413 | case 'C': /* group or community */ |
404 | community = strscpy (community, optarg); | 414 | community = optarg; |
405 | break; | 415 | break; |
406 | case 'H': /* Host or server */ | 416 | case 'H': /* Host or server */ |
407 | server_address = strscpy (server_address, optarg); | 417 | server_address = optarg; |
408 | break; | 418 | break; |
409 | case 'p': /* TCP port number */ | 419 | case 'p': /* TCP port number */ |
410 | port = strscpy(port, optarg); | 420 | port = optarg; |
411 | break; | 421 | break; |
412 | case 'm': /* List of MIBS */ | 422 | case 'm': /* List of MIBS */ |
413 | miblist = strscpy(miblist, optarg); | 423 | miblist = optarg; |
414 | break; | 424 | break; |
415 | case 'P': /* SNMP protocol version */ | 425 | case 'P': /* SNMP protocol version */ |
416 | proto = strscpy(proto, optarg); | 426 | proto = optarg; |
417 | break; | 427 | break; |
418 | case 'L': /* security level */ | 428 | case 'L': /* security level */ |
419 | seclevel = strscpy(seclevel,optarg); | 429 | seclevel = optarg; |
420 | break; | 430 | break; |
421 | case 'U': /* security username */ | 431 | case 'U': /* security username */ |
422 | secname = strscpy(secname, optarg); | 432 | secname = optarg; |
423 | break; | 433 | break; |
424 | case 'a': /* auth protocol */ | 434 | case 'a': /* auth protocol */ |
425 | asprintf (&authproto, optarg); | 435 | authproto = optarg; |
426 | break; | 436 | break; |
427 | case 'A': /* auth passwd */ | 437 | case 'A': /* auth passwd */ |
428 | authpasswd = strscpy(authpasswd, optarg); | 438 | authpasswd = optarg; |
429 | break; | 439 | break; |
430 | case 'X': /* priv passwd */ | 440 | case 'X': /* priv passwd */ |
431 | privpasswd = strscpy(privpasswd, optarg); | 441 | privpasswd = optarg; |
432 | break; | 442 | break; |
433 | case 't': /* timeout period */ | 443 | case 't': /* timeout period */ |
434 | if (!is_integer (optarg)) | 444 | if (!is_integer (optarg)) |
@@ -585,7 +595,10 @@ process_arguments (int argc, char **argv) | |||
585 | } | 595 | } |
586 | 596 | ||
587 | if (server_address == NULL) | 597 | if (server_address == NULL) |
588 | asprintf (&server_address, argv[optind]); | 598 | server_address = argv[optind]; |
599 | |||
600 | if (community == NULL) | ||
601 | community = strdup (DEFAULT_COMMUNITY); | ||
589 | 602 | ||
590 | return validate_arguments (); | 603 | return validate_arguments (); |
591 | } | 604 | } |
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index fdded58..26709a7 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c | |||
@@ -70,8 +70,8 @@ process_arguments (int argc, char **argv) | |||
70 | { | 70 | { |
71 | int c; | 71 | int c; |
72 | 72 | ||
73 | int option_index = 0; | 73 | int option = 0; |
74 | static struct option long_options[] = { | 74 | static struct option longopts[] = { |
75 | {"help", no_argument, 0, 'h'}, | 75 | {"help", no_argument, 0, 'h'}, |
76 | {"version", no_argument, 0, 'V'}, | 76 | {"version", no_argument, 0, 'V'}, |
77 | {"host", required_argument, 0, 'H'}, | 77 | {"host", required_argument, 0, 'H'}, |
@@ -91,7 +91,7 @@ process_arguments (int argc, char **argv) | |||
91 | strcpy (argv[c], "-t"); | 91 | strcpy (argv[c], "-t"); |
92 | 92 | ||
93 | while (1) { | 93 | while (1) { |
94 | c = getopt_long (argc, argv, "+Vhv46t:H:p:", long_options, &option_index); | 94 | c = getopt_long (argc, argv, "+Vhv46t:H:p:", longopts, &option); |
95 | 95 | ||
96 | if (c == -1 || c == EOF) | 96 | if (c == -1 || c == EOF) |
97 | break; | 97 | break; |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index b92694d..a4e7e81 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -34,7 +34,7 @@ const char *revision = "$Revision$"; | |||
34 | const char *copyright = "2000-2003"; | 34 | const char *copyright = "2000-2003"; |
35 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 35 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
36 | 36 | ||
37 | int check_swap (int usp, int free_swap); | 37 | int check_swap (int usp, long unsigned int free_swap); |
38 | int process_arguments (int argc, char **argv); | 38 | int process_arguments (int argc, char **argv); |
39 | int validate_arguments (void); | 39 | int validate_arguments (void); |
40 | void print_usage (void); | 40 | void print_usage (void); |
@@ -51,58 +51,6 @@ int allswaps; | |||
51 | int sun = 0; /* defined by compiler if it is a sun solaris system */ | 51 | int sun = 0; /* defined by compiler if it is a sun solaris system */ |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | void | ||
55 | print_usage (void) | ||
56 | { | ||
57 | printf (_("Usage:\n\ | ||
58 | %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\ | ||
59 | %s [-a] -w <bytes_free> -c <bytes_free>\n\ | ||
60 | %s (-h | --help) for detailed help\n\ | ||
61 | %s (-V | --version) for version information\n"), | ||
62 | progname, progname, progname, progname); | ||
63 | } | ||
64 | |||
65 | |||
66 | |||
67 | |||
68 | |||
69 | void | ||
70 | print_help (void) | ||
71 | { | ||
72 | print_revision (progname, revision); | ||
73 | |||
74 | printf (_(COPYRIGHT), copyright, email); | ||
75 | |||
76 | printf (_("Check swap space on local server.\n\n")); | ||
77 | |||
78 | print_usage (); | ||
79 | |||
80 | printf (_(UT_HELP_VRSN)); | ||
81 | |||
82 | printf (_("\n\ | ||
83 | -w, --warning=INTEGER\n\ | ||
84 | Exit with WARNING status if less than INTEGER bytes of swap space are free\n\ | ||
85 | -w, --warning=PERCENT%%\n\ | ||
86 | Exit with WARNING status if less than PERCENT of swap space has been used\n\ | ||
87 | -c, --critical=INTEGER\n\ | ||
88 | Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\ | ||
89 | -c, --critical=PERCENT%%\n\ | ||
90 | Exit with CRITCAL status if less than PERCENT of swap space has been used\n\ | ||
91 | -a, --allswaps\n\ | ||
92 | Conduct comparisons for all swap partitions, one by one\n")); | ||
93 | |||
94 | #ifdef sun | ||
95 | printf (_("\n\ | ||
96 | On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\ | ||
97 | Will be discrepencies because swap -s counts allocated swap and includes\n\ | ||
98 | real memory\n")); | ||
99 | #endif | ||
100 | |||
101 | support (); | ||
102 | } | ||
103 | |||
104 | |||
105 | |||
106 | int | 54 | int |
107 | main (int argc, char **argv) | 55 | main (int argc, char **argv) |
108 | { | 56 | { |
@@ -121,7 +69,9 @@ main (int argc, char **argv) | |||
121 | FILE *fp; | 69 | FILE *fp; |
122 | #endif | 70 | #endif |
123 | char str[32]; | 71 | char str[32]; |
124 | char *status = ""; | 72 | char *status; |
73 | |||
74 | status = strdup(""); | ||
125 | 75 | ||
126 | if (process_arguments (argc, argv) != OK) | 76 | if (process_arguments (argc, argv) != OK) |
127 | usage (_("Invalid command arguments supplied\n")); | 77 | usage (_("Invalid command arguments supplied\n")); |
@@ -233,16 +183,16 @@ main (int argc, char **argv) | |||
233 | 183 | ||
234 | 184 | ||
235 | int | 185 | int |
236 | check_swap (int usp, int free_swap) | 186 | check_swap (int usp, long unsigned int free_swap) |
237 | { | 187 | { |
238 | int result = STATE_UNKNOWN; | 188 | int result = STATE_UNKNOWN; |
239 | if (usp >= 0 && usp >= (100.0 - crit_percent)) | 189 | if (usp >= 0 && usp >= (100.0 - crit_percent)) |
240 | result = STATE_CRITICAL; | 190 | result = STATE_CRITICAL; |
241 | else if (crit_size > 0 && (unsigned)free_swap <= crit_size) | 191 | else if (crit_size > 0 && free_swap <= crit_size) |
242 | result = STATE_CRITICAL; | 192 | result = STATE_CRITICAL; |
243 | else if (usp >= 0 && usp >= (100.0 - warn_percent)) | 193 | else if (usp >= 0 && usp >= (100.0 - warn_percent)) |
244 | result = STATE_WARNING; | 194 | result = STATE_WARNING; |
245 | else if (warn_size > 0 && (unsigned)free_swap <= warn_size) | 195 | else if (warn_size > 0 && free_swap <= warn_size) |
246 | result = STATE_WARNING; | 196 | result = STATE_WARNING; |
247 | else if (usp >= 0.0) | 197 | else if (usp >= 0.0) |
248 | result = STATE_OK; | 198 | result = STATE_OK; |
@@ -258,8 +208,8 @@ process_arguments (int argc, char **argv) | |||
258 | int wc = 0; /* warning counter */ | 208 | int wc = 0; /* warning counter */ |
259 | int cc = 0; /* critical counter */ | 209 | int cc = 0; /* critical counter */ |
260 | 210 | ||
261 | int option_index = 0; | 211 | int option = 0; |
262 | static struct option long_options[] = { | 212 | static struct option longopts[] = { |
263 | {"warning", required_argument, 0, 'w'}, | 213 | {"warning", required_argument, 0, 'w'}, |
264 | {"critical", required_argument, 0, 'c'}, | 214 | {"critical", required_argument, 0, 'c'}, |
265 | {"allswaps", no_argument, 0, 'a'}, | 215 | {"allswaps", no_argument, 0, 'a'}, |
@@ -273,7 +223,7 @@ process_arguments (int argc, char **argv) | |||
273 | return ERROR; | 223 | return ERROR; |
274 | 224 | ||
275 | while (1) { | 225 | while (1) { |
276 | c = getopt_long (argc, argv, "+?Vvhac:w:", long_options, &option_index); | 226 | c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option); |
277 | 227 | ||
278 | if (c == -1 || c == EOF) | 228 | if (c == -1 || c == EOF) |
279 | break; | 229 | break; |
@@ -296,7 +246,6 @@ process_arguments (int argc, char **argv) | |||
296 | else { | 246 | else { |
297 | usage (_("Warning threshold must be integer or percentage!\n")); | 247 | usage (_("Warning threshold must be integer or percentage!\n")); |
298 | } | 248 | } |
299 | wc++; | ||
300 | case 'c': /* critical time threshold */ | 249 | case 'c': /* critical time threshold */ |
301 | if (is_intnonneg (optarg)) { | 250 | if (is_intnonneg (optarg)) { |
302 | crit_size = atoi (optarg); | 251 | crit_size = atoi (optarg); |
@@ -314,7 +263,6 @@ process_arguments (int argc, char **argv) | |||
314 | else { | 263 | else { |
315 | usage (_("Critical threshold must be integer or percentage!\n")); | 264 | usage (_("Critical threshold must be integer or percentage!\n")); |
316 | } | 265 | } |
317 | cc++; | ||
318 | case 'a': /* all swap */ | 266 | case 'a': /* all swap */ |
319 | allswaps = TRUE; | 267 | allswaps = TRUE; |
320 | break; | 268 | break; |
@@ -377,3 +325,57 @@ validate_arguments (void) | |||
377 | } | 325 | } |
378 | return OK; | 326 | return OK; |
379 | } | 327 | } |
328 | |||
329 | |||
330 | |||
331 | |||
332 | |||
333 | |||
334 | void | ||
335 | print_help (void) | ||
336 | { | ||
337 | print_revision (progname, revision); | ||
338 | |||
339 | printf (_(COPYRIGHT), copyright, email); | ||
340 | |||
341 | printf (_("Check swap space on local server.\n\n")); | ||
342 | |||
343 | print_usage (); | ||
344 | |||
345 | printf (_(UT_HELP_VRSN)); | ||
346 | |||
347 | printf (_("\n\ | ||
348 | -w, --warning=INTEGER\n\ | ||
349 | Exit with WARNING status if less than INTEGER bytes of swap space are free\n\ | ||
350 | -w, --warning=PERCENT%%\n\ | ||
351 | Exit with WARNING status if less than PERCENT of swap space has been used\n\ | ||
352 | -c, --critical=INTEGER\n\ | ||
353 | Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\ | ||
354 | -c, --critical=PERCENT%%\n\ | ||
355 | Exit with CRITCAL status if less than PERCENT of swap space has been used\n\ | ||
356 | -a, --allswaps\n\ | ||
357 | Conduct comparisons for all swap partitions, one by one\n")); | ||
358 | |||
359 | #ifdef sun | ||
360 | printf (_("\n\ | ||
361 | On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\ | ||
362 | Will be discrepencies because swap -s counts allocated swap and includes\n\ | ||
363 | real memory\n")); | ||
364 | #endif | ||
365 | |||
366 | printf (_(UT_SUPPORT)); | ||
367 | } | ||
368 | |||
369 | |||
370 | |||
371 | |||
372 | void | ||
373 | print_usage (void) | ||
374 | { | ||
375 | printf (_("Usage:\n\ | ||
376 | %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\ | ||
377 | %s [-a] -w <bytes_free> -c <bytes_free>\n\ | ||
378 | %s (-h | --help) for detailed help\n\ | ||
379 | %s (-V | --version) for version information\n"), | ||
380 | progname, progname, progname, progname); | ||
381 | } | ||
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index fc0572c..bf8ed8c 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -345,8 +345,8 @@ process_arguments (int argc, char **argv) | |||
345 | { | 345 | { |
346 | int c; | 346 | int c; |
347 | 347 | ||
348 | int option_index = 0; | 348 | int option = 0; |
349 | static struct option long_options[] = { | 349 | static struct option longopts[] = { |
350 | {"hostname", required_argument, 0, 'H'}, | 350 | {"hostname", required_argument, 0, 'H'}, |
351 | {"critical-time", required_argument, 0, 'c'}, | 351 | {"critical-time", required_argument, 0, 'c'}, |
352 | {"warning-time", required_argument, 0, 'w'}, | 352 | {"warning-time", required_argument, 0, 'w'}, |
@@ -391,7 +391,7 @@ process_arguments (int argc, char **argv) | |||
391 | 391 | ||
392 | while (1) { | 392 | while (1) { |
393 | c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:", | 393 | c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:", |
394 | long_options, &option_index); | 394 | longopts, &option); |
395 | 395 | ||
396 | if (c == -1 || c == EOF || c == 1) | 396 | if (c == -1 || c == EOF || c == 1) |
397 | break; | 397 | break; |
diff --git a/plugins/check_time.c b/plugins/check_time.c index 36b622f..49e7c87 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c | |||
@@ -138,8 +138,8 @@ process_arguments (int argc, char **argv) | |||
138 | { | 138 | { |
139 | int c; | 139 | int c; |
140 | 140 | ||
141 | int option_index = 0; | 141 | int option = 0; |
142 | static struct option long_options[] = { | 142 | static struct option longopts[] = { |
143 | {"hostname", required_argument, 0, 'H'}, | 143 | {"hostname", required_argument, 0, 'H'}, |
144 | {"warning-variance", required_argument, 0, 'w'}, | 144 | {"warning-variance", required_argument, 0, 'w'}, |
145 | {"critical-variance", required_argument, 0, 'c'}, | 145 | {"critical-variance", required_argument, 0, 'c'}, |
@@ -169,8 +169,8 @@ process_arguments (int argc, char **argv) | |||
169 | } | 169 | } |
170 | 170 | ||
171 | while (1) { | 171 | while (1) { |
172 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", long_options, | 172 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", longopts, |
173 | &option_index); | 173 | &option); |
174 | 174 | ||
175 | if (c == -1 || c == EOF) | 175 | if (c == -1 || c == EOF) |
176 | break; | 176 | break; |
@@ -307,7 +307,7 @@ This plugin will check the time on the specified host.\n\n")); | |||
307 | 307 | ||
308 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | 308 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); |
309 | 309 | ||
310 | support (); | 310 | printf (_(UT_SUPPORT)); |
311 | } | 311 | } |
312 | 312 | ||
313 | 313 | ||
diff --git a/plugins/check_udp.c b/plugins/check_udp.c index bd5de58..5aaf3a7 100644 --- a/plugins/check_udp.c +++ b/plugins/check_udp.c | |||
@@ -105,8 +105,8 @@ process_arguments (int argc, char **argv) | |||
105 | { | 105 | { |
106 | int c; | 106 | int c; |
107 | 107 | ||
108 | int option_index = 0; | 108 | int option = 0; |
109 | static struct option long_options[] = { | 109 | static struct option longopts[] = { |
110 | {"hostname", required_argument, 0, 'H'}, | 110 | {"hostname", required_argument, 0, 'H'}, |
111 | {"critical", required_argument, 0, 'c'}, | 111 | {"critical", required_argument, 0, 'c'}, |
112 | {"warning", required_argument, 0, 'w'}, | 112 | {"warning", required_argument, 0, 'w'}, |
@@ -133,7 +133,7 @@ process_arguments (int argc, char **argv) | |||
133 | } | 133 | } |
134 | 134 | ||
135 | while (1) { | 135 | while (1) { |
136 | c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", long_options, &option_index); | 136 | c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", longopts, &option); |
137 | 137 | ||
138 | if (c == -1 || c == EOF || c == 1) | 138 | if (c == -1 || c == EOF || c == 1) |
139 | break; | 139 | break; |
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index fcee747..7e7b36a 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -400,8 +400,8 @@ process_arguments (int argc, char **argv) | |||
400 | { | 400 | { |
401 | int c; | 401 | int c; |
402 | 402 | ||
403 | int option_index = 0; | 403 | int option = 0; |
404 | static struct option long_options[] = { | 404 | static struct option longopts[] = { |
405 | {"hostname", required_argument, 0, 'H'}, | 405 | {"hostname", required_argument, 0, 'H'}, |
406 | {"ups", required_argument, 0, 'u'}, | 406 | {"ups", required_argument, 0, 'u'}, |
407 | {"port", required_argument, 0, 'p'}, | 407 | {"port", required_argument, 0, 'p'}, |
@@ -427,8 +427,8 @@ process_arguments (int argc, char **argv) | |||
427 | } | 427 | } |
428 | 428 | ||
429 | while (1) { | 429 | while (1) { |
430 | c = getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", long_options, | 430 | c = getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", longopts, |
431 | &option_index); | 431 | &option); |
432 | 432 | ||
433 | if (c == -1 || c == EOF) | 433 | if (c == -1 || c == EOF) |
434 | break; | 434 | break; |
diff --git a/plugins/check_users.c b/plugins/check_users.c index 9e18201..9f308bc 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
@@ -107,8 +107,8 @@ process_arguments (int argc, char **argv) | |||
107 | { | 107 | { |
108 | int c; | 108 | int c; |
109 | 109 | ||
110 | int option_index = 0; | 110 | int option = 0; |
111 | static struct option long_options[] = { | 111 | static struct option longopts[] = { |
112 | {"critical", required_argument, 0, 'c'}, | 112 | {"critical", required_argument, 0, 'c'}, |
113 | {"warning", required_argument, 0, 'w'}, | 113 | {"warning", required_argument, 0, 'w'}, |
114 | {"version", no_argument, 0, 'V'}, | 114 | {"version", no_argument, 0, 'V'}, |
@@ -120,7 +120,7 @@ process_arguments (int argc, char **argv) | |||
120 | usage ("\n"); | 120 | usage ("\n"); |
121 | 121 | ||
122 | while (1) { | 122 | while (1) { |
123 | c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index); | 123 | c = getopt_long (argc, argv, "+hVvc:w:", longopts, &option); |
124 | 124 | ||
125 | if (c == -1 || c == EOF || c == 1) | 125 | if (c == -1 || c == EOF || c == 1) |
126 | break; | 126 | break; |
diff --git a/plugins/negate.c b/plugins/negate.c index 3ef5ee7..c24658a 100644 --- a/plugins/negate.c +++ b/plugins/negate.c | |||
@@ -14,84 +14,12 @@ | |||
14 | along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | 16 | ||
17 | ******************************************************************************/ | ||
18 | |||
19 | const char *progname = "negate"; | ||
20 | const char *revision = "$Revision$"; | ||
21 | const char *copyright = "2002-2003"; | ||
22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
23 | |||
24 | #define DEFAULT_TIMEOUT 9 | ||
25 | |||
26 | #include "common.h" | ||
27 | #include "utils.h" | ||
28 | #include "popen.h" | ||
29 | |||
30 | void | ||
31 | print_usage (void) | ||
32 | { | ||
33 | printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"), | ||
34 | progname); | ||
35 | printf (_(UT_HLP_VRS), progname, progname); | ||
36 | } | ||
37 | |||
38 | void | ||
39 | print_help (void) | ||
40 | { | ||
41 | print_revision (progname, revision); | ||
42 | |||
43 | printf (_(COPYRIGHT), copyright, email); | ||
44 | |||
45 | printf (_("\ | ||
46 | Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\ | ||
47 | \n")); | ||
48 | |||
49 | print_usage (); | ||
50 | |||
51 | printf (_(UT_HELP_VRSN)); | ||
52 | |||
53 | printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT); | ||
54 | |||
55 | printf (_("\ | ||
56 | [keep timeout than the plugin timeout to retain CRITICAL status]\n")); | ||
57 | |||
58 | printf (_("\ | ||
59 | negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\ | ||
60 | Run check_ping and invert result. Must use full path to plugin\n\ | ||
61 | negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\ | ||
62 | Use single quotes if you need to retain spaces\n")); | ||
63 | |||
64 | printf (_("\ | ||
65 | This plugin is a wrapper to take the output of another plugin and invert it.\n\ | ||
66 | If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\ | ||
67 | If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\ | ||
68 | Otherwise, the output state of the wrapped plugin is unchanged.\n")); | ||
69 | |||
70 | printf (_(UT_SUPPORT)); | ||
71 | } | ||
72 | |||
73 | char *command_line; | ||
74 | |||
75 | int process_arguments (int, char **); | ||
76 | int validate_arguments (void); | ||
77 | /****************************************************************************** | ||
78 | |||
79 | The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | ||
80 | tags in the comments. With in the tags, the XML is assembled sequentially. | ||
81 | You can define entities in tags. You also have all the #defines available as | ||
82 | entities. | ||
83 | |||
84 | Please note that all tags must be lowercase to use the DocBook XML DTD. | ||
85 | |||
86 | @@-<article> | 17 | @@-<article> |
87 | 18 | ||
88 | <sect1> | 19 | <sect1> |
89 | <title>Quick Reference</title> | 20 | <title>Quick Reference</title> |
90 | <!-- The refentry forms a manpage --> | ||
91 | <refentry> | 21 | <refentry> |
92 | <refmeta> | 22 | <refmeta><manvolnum>5<manvolnum></refmeta> |
93 | <manvolnum>5<manvolnum> | ||
94 | </refmeta> | ||
95 | <refnamdiv> | 23 | <refnamdiv> |
96 | <refname>&progname;</refname> | 24 | <refname>&progname;</refname> |
97 | <refpurpose>&SUMMARY;</refpurpose> | 25 | <refpurpose>&SUMMARY;</refpurpose> |
@@ -119,19 +47,33 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. | |||
119 | <itemizedlist> | 47 | <itemizedlist> |
120 | <listitem>Add option to do regex substitution in output text</listitem> | 48 | <listitem>Add option to do regex substitution in output text</listitem> |
121 | </itemizedlist> | 49 | </itemizedlist> |
122 | </sect2> | 50 | </sect2>-@@ |
123 | |||
124 | 51 | ||
125 | <sect2> | ||
126 | <title>Functions</title> | ||
127 | -@@ | ||
128 | ******************************************************************************/ | 52 | ******************************************************************************/ |
129 | 53 | ||
54 | const char *progname = "negate"; | ||
55 | const char *revision = "$Revision$"; | ||
56 | const char *copyright = "2002-2003"; | ||
57 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
58 | |||
59 | #define DEFAULT_TIMEOUT 9 | ||
60 | |||
61 | #include "common.h" | ||
62 | #include "utils.h" | ||
63 | #include "popen.h" | ||
64 | |||
65 | char *command_line; | ||
66 | |||
67 | int process_arguments (int, char **); | ||
68 | int validate_arguments (void); | ||
69 | void print_help (void); | ||
70 | void print_usage (void); | ||
71 | |||
130 | int | 72 | int |
131 | main (int argc, char **argv) | 73 | main (int argc, char **argv) |
132 | { | 74 | { |
133 | int found = 0, result = STATE_UNKNOWN; | 75 | int found = 0, result = STATE_UNKNOWN; |
134 | char input_buffer[MAX_INPUT_BUFFER]; | 76 | char *buf; |
135 | 77 | ||
136 | if (process_arguments (argc, argv) == ERROR) | 78 | if (process_arguments (argc, argv) == ERROR) |
137 | usage (_("Could not parse arguments\n")); | 79 | usage (_("Could not parse arguments\n")); |
@@ -151,27 +93,22 @@ main (int argc, char **argv) | |||
151 | printf (_("Could not open stderr for %s\n"), command_line); | 93 | printf (_("Could not open stderr for %s\n"), command_line); |
152 | } | 94 | } |
153 | 95 | ||
154 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 96 | buf = malloc(MAX_INPUT_BUFFER); |
97 | while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { | ||
155 | found++; | 98 | found++; |
156 | if (strchr (input_buffer, '\n')) { | 99 | printf ("%s", buf); |
157 | input_buffer[strcspn (input_buffer, "\n")] = 0; | ||
158 | printf ("%s\n", input_buffer); | ||
159 | } | ||
160 | else { | ||
161 | printf ("%s\n", input_buffer); | ||
162 | } | ||
163 | } | 100 | } |
164 | 101 | ||
165 | if (!found) | 102 | if (!found) |
166 | die (STATE_UNKNOWN,\ | 103 | die (STATE_UNKNOWN, |
167 | _("%s problem - No data recieved from host\nCMD: %s\n"),\ | 104 | _("%s problem - No data recieved from host\nCMD: %s\n"),\ |
168 | argv[0], command_line); | 105 | argv[0], command_line); |
169 | 106 | ||
170 | /* close the pipe */ | 107 | /* close the pipe */ |
171 | result = spclose (child_process); | 108 | result = spclose (child_process); |
172 | 109 | ||
173 | /* WARNING if output found on stderr */ | 110 | /* WARNING if output found on stderr */ |
174 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 111 | if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) |
175 | result = max_state (result, STATE_WARNING); | 112 | result = max_state (result, STATE_WARNING); |
176 | 113 | ||
177 | /* close stderr */ | 114 | /* close stderr */ |
@@ -189,6 +126,9 @@ main (int argc, char **argv) | |||
189 | 126 | ||
190 | /****************************************************************************** | 127 | /****************************************************************************** |
191 | @@- | 128 | @@- |
129 | <sect2> | ||
130 | <title>Functions</title> | ||
131 | |||
192 | <sect3> | 132 | <sect3> |
193 | <title>process_arguments</title> | 133 | <title>process_arguments</title> |
194 | 134 | ||
@@ -196,7 +136,7 @@ main (int argc, char **argv) | |||
196 | variables.</para> | 136 | variables.</para> |
197 | 137 | ||
198 | <para>Aside from the standard 'help' and 'version' options, there | 138 | <para>Aside from the standard 'help' and 'version' options, there |
199 | is a only a 'timeout' option.No validation is currently done.</para> | 139 | is a only a 'timeout' option.</para> |
200 | 140 | ||
201 | </sect3> | 141 | </sect3> |
202 | -@@ | 142 | -@@ |
@@ -208,8 +148,8 @@ process_arguments (int argc, char **argv) | |||
208 | { | 148 | { |
209 | int c; | 149 | int c; |
210 | 150 | ||
211 | int option_index = 0; | 151 | int option = 0; |
212 | static struct option long_options[] = { | 152 | static struct option longopts[] = { |
213 | {"help", no_argument, 0, 'h'}, | 153 | {"help", no_argument, 0, 'h'}, |
214 | {"version", no_argument, 0, 'V'}, | 154 | {"version", no_argument, 0, 'V'}, |
215 | {"timeout", required_argument, 0, 't'}, | 155 | {"timeout", required_argument, 0, 't'}, |
@@ -218,7 +158,7 @@ process_arguments (int argc, char **argv) | |||
218 | 158 | ||
219 | while (1) { | 159 | while (1) { |
220 | c = getopt_long (argc, argv, "+hVt:", | 160 | c = getopt_long (argc, argv, "+hVt:", |
221 | long_options, &option_index); | 161 | longopts, &option); |
222 | 162 | ||
223 | if (c == -1 || c == EOF) | 163 | if (c == -1 || c == EOF) |
224 | break; | 164 | break; |
@@ -226,16 +166,19 @@ process_arguments (int argc, char **argv) | |||
226 | switch (c) { | 166 | switch (c) { |
227 | case '?': /* help */ | 167 | case '?': /* help */ |
228 | usage3 (_("Unknown argument"), optopt); | 168 | usage3 (_("Unknown argument"), optopt); |
169 | break; | ||
229 | case 'h': /* help */ | 170 | case 'h': /* help */ |
230 | print_help (); | 171 | print_help (); |
231 | exit (EXIT_SUCCESS); | 172 | exit (EXIT_SUCCESS); |
173 | break; | ||
232 | case 'V': /* version */ | 174 | case 'V': /* version */ |
233 | print_revision (progname, revision); | 175 | print_revision (progname, revision); |
234 | exit (EXIT_SUCCESS); | 176 | exit (EXIT_SUCCESS); |
235 | case 't': /* timeout period */ | 177 | case 't': /* timeout period */ |
236 | if (!is_integer (optarg)) | 178 | if (!is_integer (optarg)) |
237 | usage2 (_("Timeout Interval must be an integer"), optarg); | 179 | usage2 (_("Timeout Interval must be an integer"), optarg); |
238 | timeout_interval = atoi (optarg); | 180 | else |
181 | timeout_interval = atoi (optarg); | ||
239 | break; | 182 | break; |
240 | } | 183 | } |
241 | } | 184 | } |
@@ -267,7 +210,6 @@ validate_arguments () | |||
267 | return ERROR; | 210 | return ERROR; |
268 | return STATE_OK; | 211 | return STATE_OK; |
269 | } | 212 | } |
270 | |||
271 | 213 | ||
272 | /****************************************************************************** | 214 | /****************************************************************************** |
273 | @@- | 215 | @@- |
@@ -276,3 +218,55 @@ validate_arguments () | |||
276 | </article> | 218 | </article> |
277 | -@@ | 219 | -@@ |
278 | ******************************************************************************/ | 220 | ******************************************************************************/ |
221 | |||
222 | |||
223 | |||
224 | |||
225 | |||
226 | |||
227 | void | ||
228 | print_help (void) | ||
229 | { | ||
230 | print_revision (progname, revision); | ||
231 | |||
232 | printf (_(COPYRIGHT), copyright, email); | ||
233 | |||
234 | printf (_("\ | ||
235 | Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\ | ||
236 | \n")); | ||
237 | |||
238 | print_usage (); | ||
239 | |||
240 | printf (_(UT_HELP_VRSN)); | ||
241 | |||
242 | printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT); | ||
243 | |||
244 | printf (_("\ | ||
245 | [keep timeout than the plugin timeout to retain CRITICAL status]\n")); | ||
246 | |||
247 | printf (_("\ | ||
248 | negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\ | ||
249 | Run check_ping and invert result. Must use full path to plugin\n\ | ||
250 | negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\ | ||
251 | Use single quotes if you need to retain spaces\n")); | ||
252 | |||
253 | printf (_("\ | ||
254 | This plugin is a wrapper to take the output of another plugin and invert it.\n\ | ||
255 | If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\ | ||
256 | If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\ | ||
257 | Otherwise, the output state of the wrapped plugin is unchanged.\n")); | ||
258 | |||
259 | printf (_(UT_SUPPORT)); | ||
260 | } | ||
261 | |||
262 | |||
263 | |||
264 | |||
265 | |||
266 | void | ||
267 | print_usage (void) | ||
268 | { | ||
269 | printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"), | ||
270 | progname); | ||
271 | printf (_(UT_HLP_VRS), progname, progname); | ||
272 | } | ||
diff --git a/plugins/popen.c b/plugins/popen.c index 98ba085..05fd0ab 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
@@ -18,8 +18,7 @@ int spclose(FILE *); | |||
18 | * | 18 | * |
19 | ******************************************************************************/ | 19 | ******************************************************************************/ |
20 | 20 | ||
21 | #include <config.h> | 21 | #include "common.h" |
22 | #include <common.h> | ||
23 | 22 | ||
24 | /* extern so plugin has pid to kill exec'd process on timeouts */ | 23 | /* extern so plugin has pid to kill exec'd process on timeouts */ |
25 | extern int timeout_interval; | 24 | extern int timeout_interval; |
diff --git a/plugins/urlize.c b/plugins/urlize.c index 12fb3ec..f4bc67b 100644 --- a/plugins/urlize.c +++ b/plugins/urlize.c | |||
@@ -1,41 +1,20 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | |
3 | * urlize.c | 3 | This program is free software; you can redistribute it and/or modify |
4 | * | 4 | it under the terms of the GNU General Public License as published by |
5 | * Program: plugin wrapper for Nagios | 5 | the Free Software Foundation; either version 2 of the License, or |
6 | * License: GPL | 6 | (at your option) any later version. |
7 | * Copyright (c) 2000 Karl DeBisschop (kdebiss@alum.mit.edu) | 7 | |
8 | * | 8 | This program is distributed in the hope that it will be useful, |
9 | * Last Modified: $Date$ | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * 2000-06-01 Karl DeBisschop <karl@debisschop.net> | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * Written based of concept in urlize.pl | 11 | GNU General Public License for more details. |
12 | * | 12 | |
13 | * Usage: urlize <url> <plugin> <arg1> ... <argN> | 13 | You should have received a copy of the GNU General Public License |
14 | * | 14 | along with this program; if not, write to the Free Software |
15 | * Description: | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | * | 16 | |
17 | * This plugin wraps the text output of another command (plugin) in HTML | 17 | ******************************************************************************/ |
18 | * <A> tags, thus displaying the plugin output in as a clickable link in | ||
19 | * the Nagios status screen. The return status is the same as the plugin | ||
20 | * invoked by urlize | ||
21 | * | ||
22 | * License Information: | ||
23 | * | ||
24 | * This program is free software; you can redistribute it and/or modify | ||
25 | * it under the terms of the GNU General Public License as published by | ||
26 | * the Free Software Foundation; either version 2 of the License, or | ||
27 | * (at your option) any later version. | ||
28 | * | ||
29 | * This program is distributed in the hope that it will be useful, | ||
30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
32 | * GNU General Public License for more details. | ||
33 | * | ||
34 | * You should have received a copy of the GNU General Public License | ||
35 | * along with this program; if not, write to the Free Software | ||
36 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
37 | * | ||
38 | *****************************************************************************/ | ||
39 | 18 | ||
40 | const char *progname = "urlize"; | 19 | const char *progname = "urlize"; |
41 | const char *revision = "$Revision$"; | 20 | const char *revision = "$Revision$"; |
@@ -46,12 +25,101 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
46 | #include "utils.h" | 25 | #include "utils.h" |
47 | #include "popen.h" | 26 | #include "popen.h" |
48 | 27 | ||
49 | void | 28 | void print_help (void); |
50 | print_usage (void) | 29 | void print_usage (void); |
30 | |||
31 | int | ||
32 | main (int argc, char **argv) | ||
51 | { | 33 | { |
52 | printf (_("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n"), progname); | 34 | int found = 0, result = STATE_UNKNOWN; |
35 | char *url = NULL; | ||
36 | char *cmd; | ||
37 | char *buf; | ||
38 | |||
39 | int c; | ||
40 | int option = 0; | ||
41 | static struct option longopts[] = { | ||
42 | {"help", no_argument, 0, 'h'}, | ||
43 | {"version", no_argument, 0, 'V'}, | ||
44 | {"url", required_argument, 0, 'u'}, | ||
45 | {0, 0, 0, 0} | ||
46 | }; | ||
47 | |||
48 | while (1) { | ||
49 | c = getopt_long (argc, argv, "+hVu:", longopts, &option); | ||
50 | |||
51 | if (c == -1 || c == EOF) | ||
52 | break; | ||
53 | |||
54 | switch (c) { | ||
55 | case 'h': /* help */ | ||
56 | print_help (); | ||
57 | exit (EXIT_SUCCESS); | ||
58 | break; | ||
59 | case 'V': /* version */ | ||
60 | print_revision (progname, revision); | ||
61 | exit (EXIT_SUCCESS); | ||
62 | break; | ||
63 | case 'u': | ||
64 | url = strdup (argv[optind]); | ||
65 | break; | ||
66 | case '?': | ||
67 | default: | ||
68 | usage3 (_("Unknown argument"), optopt); | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | if (url == NULL) | ||
74 | url = strdup (argv[optind++]); | ||
75 | |||
76 | cmd = strdup (argv[optind++]); | ||
77 | for (c = optind; c < argc; c++) { | ||
78 | asprintf (&cmd, "%s %s", cmd, argv[c]); | ||
79 | } | ||
80 | |||
81 | child_process = spopen (cmd); | ||
82 | if (child_process == NULL) { | ||
83 | printf (_("Could not open pipe: %s\n"), cmd); | ||
84 | exit (STATE_UNKNOWN); | ||
85 | } | ||
86 | |||
87 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | ||
88 | if (child_stderr == NULL) { | ||
89 | printf (_("Could not open stderr for %s\n"), cmd); | ||
90 | } | ||
91 | |||
92 | buf = malloc(MAX_INPUT_BUFFER); | ||
93 | printf ("<A href=\"%s\">", argv[1]); | ||
94 | while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { | ||
95 | found++; | ||
96 | printf ("%s", buf); | ||
97 | } | ||
98 | |||
99 | if (!found) | ||
100 | die (STATE_UNKNOWN, | ||
101 | _("%s problem - No data recieved from host\nCMD: %s</A>\n"), | ||
102 | argv[0], cmd); | ||
103 | |||
104 | /* close the pipe */ | ||
105 | result = spclose (child_process); | ||
106 | |||
107 | /* WARNING if output found on stderr */ | ||
108 | if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) | ||
109 | result = max_state (result, STATE_WARNING); | ||
110 | |||
111 | /* close stderr */ | ||
112 | (void) fclose (child_stderr); | ||
113 | |||
114 | printf ("</A>\n"); | ||
115 | return result; | ||
53 | } | 116 | } |
54 | 117 | ||
118 | |||
119 | |||
120 | |||
121 | |||
122 | |||
55 | void | 123 | void |
56 | print_help (void) | 124 | print_help (void) |
57 | { | 125 | { |
@@ -81,80 +149,15 @@ the shell will remove the single quotes and urlize will see:\n\ | |||
81 | You probably want:\n\ | 149 | You probably want:\n\ |
82 | \n\ | 150 | \n\ |
83 | urlize http://example.com/ \"check_http -H example.com -r 'two words'\"\n")); | 151 | urlize http://example.com/ \"check_http -H example.com -r 'two words'\"\n")); |
84 | exit (STATE_OK); | ||
85 | } | ||
86 | |||
87 | int | ||
88 | main (int argc, char **argv) | ||
89 | { | ||
90 | int i = 0, found = 0, result = STATE_UNKNOWN; | ||
91 | char *cmd = NULL; | ||
92 | char input_buffer[MAX_INPUT_BUFFER]; | ||
93 | |||
94 | if (argc < 2) { | ||
95 | print_usage (); | ||
96 | exit (STATE_UNKNOWN); | ||
97 | } | ||
98 | |||
99 | if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) { | ||
100 | print_help (); | ||
101 | exit (STATE_OK); | ||
102 | } | ||
103 | |||
104 | if (!strcmp (argv[1], "-V") || !strcmp (argv[1], "--version")) { | ||
105 | print_revision (progname, revision); | ||
106 | exit (STATE_OK); | ||
107 | } | ||
108 | |||
109 | if (argc < 2) { | ||
110 | print_usage (); | ||
111 | exit (STATE_UNKNOWN); | ||
112 | } | ||
113 | |||
114 | asprintf (&cmd, "%s", argv[2]); | ||
115 | for (i = 3; i < argc; i++) { | ||
116 | asprintf (&cmd, "%s %s", cmd, argv[i]); | ||
117 | } | ||
118 | |||
119 | child_process = spopen (cmd); | ||
120 | if (child_process == NULL) { | ||
121 | printf (_("Could not open pipe: %s\n"), cmd); | ||
122 | exit (STATE_UNKNOWN); | ||
123 | } | ||
124 | |||
125 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | ||
126 | if (child_stderr == NULL) { | ||
127 | printf (_("Could not open stderr for %s\n"), cmd); | ||
128 | } | ||
129 | |||
130 | printf ("<A href=\"%s\">", argv[1]); | ||
131 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | ||
132 | found++; | ||
133 | if (index (input_buffer, '\n')) { | ||
134 | input_buffer[strcspn (input_buffer, "\n")] = 0; | ||
135 | printf ("%s", input_buffer); | ||
136 | } | ||
137 | else { | ||
138 | printf ("%s", input_buffer); | ||
139 | } | ||
140 | } | ||
141 | 152 | ||
142 | if (!found) { | 153 | printf (_(UT_SUPPORT)); |
143 | printf (_("%s problem - No data recieved from host\nCMD: %s</A>\n"), argv[0], | 154 | } |
144 | cmd); | ||
145 | exit (STATE_UNKNOWN); | ||
146 | } | ||
147 | 155 | ||
148 | /* close the pipe */ | ||
149 | result = spclose (child_process); | ||
150 | 156 | ||
151 | /* WARNING if output found on stderr */ | ||
152 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | ||
153 | result = max_state (result, STATE_WARNING); | ||
154 | 157 | ||
155 | /* close stderr */ | ||
156 | (void) fclose (child_stderr); | ||
157 | 158 | ||
158 | printf ("</A>\n"); | 159 | void |
159 | return result; | 160 | print_usage (void) |
161 | { | ||
162 | printf (_("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n"), progname); | ||
160 | } | 163 | } |