summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_smtp.c14
-rw-r--r--plugins/check_ssh.c9
-rw-r--r--plugins/check_tcp.c209
-rw-r--r--plugins/check_time.c113
-rw-r--r--plugins/check_udp.c125
-rw-r--r--plugins/check_ups.c148
-rw-r--r--plugins/check_users.c86
7 files changed, 390 insertions, 314 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index f7c826b..c4e427a 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -41,8 +41,8 @@ int server_port = SMTP_PORT;
41char *server_address = NULL; 41char *server_address = NULL;
42char *server_expect = NULL; 42char *server_expect = NULL;
43int smtp_use_dummycmd = 1; 43int smtp_use_dummycmd = 1;
44char *mail_command = "MAIL "; 44char *mail_command;
45char *from_arg = " "; 45char *from_arg;
46int warning_time = 0; 46int warning_time = 0;
47int check_warning_time = FALSE; 47int check_warning_time = FALSE;
48int critical_time = 0; 48int critical_time = 0;
@@ -60,7 +60,7 @@ main (int argc, char **argv)
60 int sd; 60 int sd;
61 double elapsed_time; 61 double elapsed_time;
62 int result = STATE_UNKNOWN; 62 int result = STATE_UNKNOWN;
63 char buffer[MAX_INPUT_BUFFER] = ""; 63 char buffer[MAX_INPUT_BUFFER];
64 char *from_str = NULL; 64 char *from_str = NULL;
65 char *helocmd = NULL; 65 char *helocmd = NULL;
66 struct timeval tv; 66 struct timeval tv;
@@ -313,7 +313,13 @@ process_arguments (int argc, char **argv)
313 } 313 }
314 314
315 if (server_expect == NULL) 315 if (server_expect == NULL)
316 asprintf (&server_expect, SMTP_EXPECT); 316 server_expect = strdup (SMTP_EXPECT);
317
318 if (mail_command == NULL)
319 mail_command = strdup("MAIL ");
320
321 if (from_arg==NULL)
322 from_arg = strdup(" ");
317 323
318 return validate_arguments (); 324 return validate_arguments ();
319} 325}
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index 7fcb811..fdded58 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -32,7 +32,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
32#define SSH_DFL_PORT 22 32#define SSH_DFL_PORT 22
33#define BUFF_SZ 256 33#define BUFF_SZ 256
34 34
35short port = -1; 35int port = -1;
36char *server_name = NULL; 36char *server_name = NULL;
37int verbose = FALSE; 37int verbose = FALSE;
38 38
@@ -41,7 +41,7 @@ int validate_arguments (void);
41void print_help (void); 41void print_help (void);
42void print_usage (void); 42void print_usage (void);
43 43
44int ssh_connect (char *haddr, short hport); 44int ssh_connect (char *haddr, int hport);
45 45
46int 46int
47main (int argc, char **argv) 47main (int argc, char **argv)
@@ -111,7 +111,8 @@ process_arguments (int argc, char **argv)
111 case 't': /* timeout period */ 111 case 't': /* timeout period */
112 if (!is_integer (optarg)) 112 if (!is_integer (optarg))
113 usage (_("Timeout Interval must be an integer!\n\n")); 113 usage (_("Timeout Interval must be an integer!\n\n"));
114 socket_timeout = atoi (optarg); 114 else
115 socket_timeout = atoi (optarg);
115 break; 116 break;
116 case '4': 117 case '4':
117 address_family = AF_INET; 118 address_family = AF_INET;
@@ -178,7 +179,7 @@ validate_arguments (void)
178*-----------------------------------------------------------------------*/ 179*-----------------------------------------------------------------------*/
179 180
180int 181int
181ssh_connect (char *haddr, short hport) 182ssh_connect (char *haddr, int hport)
182{ 183{
183 int sd; 184 int sd;
184 int result; 185 int result;
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index a897d8e..fc0572c 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -1,21 +1,27 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2
3* This program is free software; you can redistribute it and/or modify 3 This program is free software; you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4 it under the terms of the GNU General Public License as published by
5* the Free Software Foundation; either version 2 of the License, or 5 the Free Software Foundation; either version 2 of the License, or
6* (at your option) any later version. 6 (at your option) any later version.
7* 7
8* This program is distributed in the hope that it will be useful, 8 This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11 GNU General Public License for more details.
12* 12
13* You should have received a copy of the GNU General Public License 13 You should have received a copy of the GNU General Public License
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*****************************************************************************/ 17*****************************************************************************/
18#include "config.h" 18
19/* progname changes depending on symlink called */
20char *progname = "check_tcp";
21const char *revision = "$Revision$";
22const char *copyright = "1999-2003";
23const char *email = "nagiosplug-devel@lists.sourceforge.net";
24
19#include "common.h" 25#include "common.h"
20#include "netutils.h" 26#include "netutils.h"
21#include "utils.h" 27#include "utils.h"
@@ -51,9 +57,9 @@ enum {
51}; 57};
52 58
53int process_arguments (int, char **); 59int process_arguments (int, char **);
54void print_usage (void);
55void print_help (void);
56int my_recv (void); 60int my_recv (void);
61void print_help (void);
62void print_usage (void);
57 63
58char *SERVICE = NULL; 64char *SERVICE = NULL;
59char *SEND = NULL; 65char *SEND = NULL;
@@ -67,94 +73,35 @@ char *server_address = NULL;
67char *server_send = NULL; 73char *server_send = NULL;
68char *server_quit = NULL; 74char *server_quit = NULL;
69char **server_expect = NULL; 75char **server_expect = NULL;
70int server_expect_count = 0; 76size_t server_expect_count = 0;
71int maxbytes = 0; 77int maxbytes = 0;
72char **warn_codes = NULL; 78char **warn_codes = NULL;
73int warn_codes_count = 0; 79size_t warn_codes_count = 0;
74char **crit_codes = NULL; 80char **crit_codes = NULL;
75int crit_codes_count = 0; 81size_t crit_codes_count = 0;
76int delay = 0; 82unsigned int delay = 0;
77double warning_time = 0; 83double warning_time = 0;
78int check_warning_time = FALSE; 84int check_warning_time = FALSE;
79double critical_time = 0; 85double critical_time = 0;
80int check_critical_time = FALSE; 86int check_critical_time = FALSE;
81double elapsed_time = 0; 87double elapsed_time = 0;
88long microsec;
82int verbose = FALSE; 89int verbose = FALSE;
83int use_ssl = FALSE; 90int use_ssl = FALSE;
84int sd = 0; 91int sd = 0;
85char *buffer = ""; 92char *buffer;
86
87/* progname changes depending on symlink called */
88char *progname = "check_tcp";
89const char *revision = "$Revision$";
90const char *copyright = "1999-2003";
91const char *email = "nagiosplug-devel@lists.sourceforge.net";
92
93
94
95
96void
97print_usage (void)
98{
99 printf (_("\
100Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
101 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
102 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
103 [-r <refuse state>] [-v] [-4|-6]\n"), progname);
104 printf (" %s (-h|--help)\n", progname);
105 printf (" %s (-V|--version)\n", progname);
106}
107void
108print_help (void)
109{
110 print_revision (progname, revision);
111
112 printf (_(COPYRIGHT), copyright, email);
113
114 printf (_("This plugin tests %s connections with the specified host.\n\n"),
115 SERVICE);
116
117 print_usage ();
118
119 printf (_(UT_HELP_VRSN));
120
121 printf (_(UT_HOST_PORT), 'p', "none");
122
123 printf (_(UT_IPv46));
124
125 printf (_("\
126 -s, --send=STRING\n\
127 String to send to the server\n\
128 -e, --expect=STRING\n\
129 String to expect in server response\n\
130 -q, --quit=STRING\n\
131 String to send server to initiate a clean close of the connection\n"));
132 93
133 printf (_("\
134 -r, --refuse=ok|warn|crit\n\
135 Accept tcp refusals with states ok, warn, crit (default: crit)\n\
136 -m, --maxbytes=INTEGER\n\
137 Close connection once more than this number of bytes are received\n\
138 -d, --delay=INTEGER\n\
139 Seconds to wait between sending string and polling for response\n"));
140 94
141 printf (_(UT_WARN_CRIT));
142 95
143 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
144 96
145 printf (_(UT_VERBOSE));
146 97
147 printf (_(UT_SUPPORT));
148}
149 98
150
151
152int 99int
153main (int argc, char **argv) 100main (int argc, char **argv)
154{ 101{
155 int result; 102 int result;
156 int i; 103 int i;
157 char *status = ""; 104 char *status;
158 struct timeval tv; 105 struct timeval tv;
159 106
160 setlocale (LC_ALL, ""); 107 setlocale (LC_ALL, "");
@@ -296,10 +243,10 @@ main (int argc, char **argv)
296 asprintf (&server_send, "%s\r\n", server_send); 243 asprintf (&server_send, "%s\r\n", server_send);
297#ifdef HAVE_SSL 244#ifdef HAVE_SSL
298 if (use_ssl) 245 if (use_ssl)
299 SSL_write(ssl, server_send, strlen (server_send)); 246 SSL_write(ssl, server_send, (int)strlen(server_send));
300 else 247 else
301#endif 248#endif
302 send (sd, server_send, strlen (server_send), 0); 249 send (sd, server_send, strlen(server_send), 0);
303 } 250 }
304 251
305 if (delay > 0) { 252 if (delay > 0) {
@@ -311,6 +258,7 @@ main (int argc, char **argv)
311 258
312 buffer = malloc (MAXBUF); 259 buffer = malloc (MAXBUF);
313 memset (buffer, '\0', MAXBUF); 260 memset (buffer, '\0', MAXBUF);
261 status = strdup ("");
314 /* watch for the expect string */ 262 /* watch for the expect string */
315 while ((i = my_recv ()) > 0) { 263 while ((i = my_recv ()) > 0) {
316 buffer[i] = '\0'; 264 buffer[i] = '\0';
@@ -333,8 +281,8 @@ main (int argc, char **argv)
333 if (server_expect_count > 0) { 281 if (server_expect_count > 0) {
334 for (i = 0;; i++) { 282 for (i = 0;; i++) {
335 if (verbose) 283 if (verbose)
336 printf ("%d %d\n", i, server_expect_count); 284 printf ("%d %d\n", i, (int)server_expect_count);
337 if (i >= server_expect_count) 285 if (i >= (int)server_expect_count)
338 die (STATE_WARNING, _("Invalid response from host\n")); 286 die (STATE_WARNING, _("Invalid response from host\n"));
339 if (strstr (status, server_expect[i])) 287 if (strstr (status, server_expect[i]))
340 break; 288 break;
@@ -345,7 +293,7 @@ main (int argc, char **argv)
345 if (server_quit != NULL) { 293 if (server_quit != NULL) {
346#ifdef HAVE_SSL 294#ifdef HAVE_SSL
347 if (use_ssl) { 295 if (use_ssl) {
348 SSL_write (ssl, server_quit, strlen (server_quit)); 296 SSL_write (ssl, server_quit, (int)strlen(server_quit));
349 SSL_shutdown (ssl); 297 SSL_shutdown (ssl);
350 SSL_free (ssl); 298 SSL_free (ssl);
351 SSL_CTX_free (ctx); 299 SSL_CTX_free (ctx);
@@ -362,7 +310,8 @@ main (int argc, char **argv)
362 if (sd) 310 if (sd)
363 close (sd); 311 close (sd);
364 312
365 elapsed_time = delta_time (tv); 313 microsec = deltime (tv);
314 elapsed_time = (double)microsec / 1.0e6;
366 315
367 if (check_critical_time == TRUE && elapsed_time > critical_time) 316 if (check_critical_time == TRUE && elapsed_time > critical_time)
368 result = STATE_CRITICAL; 317 result = STATE_CRITICAL;
@@ -382,7 +331,7 @@ main (int argc, char **argv)
382 if (status && strlen(status) > 0) 331 if (status && strlen(status) > 0)
383 printf (" [%s]", status); 332 printf (" [%s]", status);
384 333
385 printf ("|time=%.3f\n", elapsed_time); 334 printf ("|time=%ldus\n", microsec);
386 335
387 return result; 336 return result;
388} 337}
@@ -479,13 +428,15 @@ process_arguments (int argc, char **argv)
479 case 'c': /* critical */ 428 case 'c': /* critical */
480 if (!is_intnonneg (optarg)) 429 if (!is_intnonneg (optarg))
481 usage (_("Critical threshold must be a nonnegative integer\n")); 430 usage (_("Critical threshold must be a nonnegative integer\n"));
482 critical_time = strtod (optarg, NULL); 431 else
432 critical_time = strtod (optarg, NULL);
483 check_critical_time = TRUE; 433 check_critical_time = TRUE;
484 break; 434 break;
485 case 'w': /* warning */ 435 case 'w': /* warning */
486 if (!is_intnonneg (optarg)) 436 if (!is_intnonneg (optarg))
487 usage (_("Warning threshold must be a nonnegative integer\n")); 437 usage (_("Warning threshold must be a nonnegative integer\n"));
488 warning_time = strtod (optarg, NULL); 438 else
439 warning_time = strtod (optarg, NULL);
489 check_warning_time = TRUE; 440 check_warning_time = TRUE;
490 break; 441 break;
491 case 'C': 442 case 'C':
@@ -499,12 +450,14 @@ process_arguments (int argc, char **argv)
499 case 't': /* timeout */ 450 case 't': /* timeout */
500 if (!is_intpos (optarg)) 451 if (!is_intpos (optarg))
501 usage (_("Timeout interval must be a positive integer\n")); 452 usage (_("Timeout interval must be a positive integer\n"));
502 socket_timeout = atoi (optarg); 453 else
454 socket_timeout = atoi (optarg);
503 break; 455 break;
504 case 'p': /* port */ 456 case 'p': /* port */
505 if (!is_intpos (optarg)) 457 if (!is_intpos (optarg))
506 usage (_("Server port must be a positive integer\n")); 458 usage (_("Server port must be a positive integer\n"));
507 server_port = atoi (optarg); 459 else
460 server_port = atoi (optarg);
508 break; 461 break;
509 case 's': 462 case 's':
510 server_send = optarg; 463 server_send = optarg;
@@ -520,7 +473,8 @@ process_arguments (int argc, char **argv)
520 case 'm': 473 case 'm':
521 if (!is_intpos (optarg)) 474 if (!is_intpos (optarg))
522 usage (_("Maxbytes must be a positive integer\n")); 475 usage (_("Maxbytes must be a positive integer\n"));
523 maxbytes = atoi (optarg); 476 else
477 maxbytes = atoi (optarg);
524 case 'q': 478 case 'q':
525 server_quit = optarg; 479 server_quit = optarg;
526 break; 480 break;
@@ -627,3 +581,66 @@ my_recv (void)
627 581
628 return i; 582 return i;
629} 583}
584
585
586
587
588
589
590void
591print_help (void)
592{
593 print_revision (progname, revision);
594
595 printf (_(COPYRIGHT), copyright, email);
596
597 printf (_("This plugin tests %s connections with the specified host.\n\n"),
598 SERVICE);
599
600 print_usage ();
601
602 printf (_(UT_HELP_VRSN));
603
604 printf (_(UT_HOST_PORT), 'p', "none");
605
606 printf (_(UT_IPv46));
607
608 printf (_("\
609 -s, --send=STRING\n\
610 String to send to the server\n\
611 -e, --expect=STRING\n\
612 String to expect in server response\n\
613 -q, --quit=STRING\n\
614 String to send server to initiate a clean close of the connection\n"));
615
616 printf (_("\
617 -r, --refuse=ok|warn|crit\n\
618 Accept tcp refusals with states ok, warn, crit (default: crit)\n\
619 -m, --maxbytes=INTEGER\n\
620 Close connection once more than this number of bytes are received\n\
621 -d, --delay=INTEGER\n\
622 Seconds to wait between sending string and polling for response\n"));
623
624 printf (_(UT_WARN_CRIT));
625
626 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
627
628 printf (_(UT_VERBOSE));
629
630 printf (_(UT_SUPPORT));
631}
632
633
634
635
636void
637print_usage (void)
638{
639 printf (_("\
640Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
641 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
642 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
643 [-r <refuse state>] [-v] [-4|-6]\n"), progname);
644 printf (" %s (-h|--help)\n", progname);
645 printf (" %s (-V|--version)\n", progname);
646}
diff --git a/plugins/check_time.c b/plugins/check_time.c
index dde6eea..36b622f 100644
--- a/plugins/check_time.c
+++ b/plugins/check_time.c
@@ -29,51 +29,6 @@ enum {
29 TIME_PORT = 37 29 TIME_PORT = 37
30}; 30};
31 31
32void
33print_usage (void)
34{
35 printf (_("\
36Usage: %s -H <host_address> [-p port] [-w variance] [-c variance]\n\
37 [-W connect_time] [-C connect_time] [-t timeout]\n"), progname);
38 printf (_(UT_HLP_VRS), progname, progname);
39}
40
41void
42print_help (void)
43{
44 char *myport;
45 asprintf (&myport, "%d", TIME_PORT);
46
47 print_revision (progname, revision);
48
49 printf (_("Copyright (c) 1999 Ethan Galstad\n"));
50 printf (_(COPYRIGHT), copyright, email);
51
52 printf (_("\
53This plugin will check the time on the specified host.\n\n"));
54
55 print_usage ();
56
57 printf (_(UT_HELP_VRSN));
58
59 printf (_(UT_HOST_PORT), 'p', myport);
60
61 printf (_("\
62 -w, --warning-variance=INTEGER\n\
63 Time difference (sec.) necessary to result in a warning status\n\
64 -c, --critical-variance=INTEGER\n\
65 Time difference (sec.) necessary to result in a critical status\n\
66 -W, --warning-connect=INTEGER\n\
67 Response time (sec.) necessary to result in warning status\n\
68 -C, --critical-connect=INTEGER\n\
69 Response time (sec.) necessary to result in critical status\n"));
70
71 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
72
73 support ();
74}
75
76
77#define UNIX_EPOCH 2208988800UL 32#define UNIX_EPOCH 2208988800UL
78 33
79unsigned long server_time, raw_server_time; 34unsigned long server_time, raw_server_time;
@@ -89,11 +44,9 @@ int check_critical_diff = FALSE;
89int server_port = TIME_PORT; 44int server_port = TIME_PORT;
90char *server_address = NULL; 45char *server_address = NULL;
91 46
92
93int process_arguments (int, char **); 47int process_arguments (int, char **);
94void print_usage (void);
95void print_help (void); 48void print_help (void);
96 49void print_usage (void);
97 50
98int 51int
99main (int argc, char **argv) 52main (int argc, char **argv)
@@ -276,24 +229,28 @@ process_arguments (int argc, char **argv)
276 case 'W': /* warning-connect */ 229 case 'W': /* warning-connect */
277 if (!is_intnonneg (optarg)) 230 if (!is_intnonneg (optarg))
278 usage (_("Warning threshold must be a nonnegative integer\n")); 231 usage (_("Warning threshold must be a nonnegative integer\n"));
279 warning_time = atoi (optarg); 232 else
233 warning_time = atoi (optarg);
280 check_warning_time = TRUE; 234 check_warning_time = TRUE;
281 break; 235 break;
282 case 'C': /* critical-connect */ 236 case 'C': /* critical-connect */
283 if (!is_intnonneg (optarg)) 237 if (!is_intnonneg (optarg))
284 usage (_("Critical threshold must be a nonnegative integer\n")); 238 usage (_("Critical threshold must be a nonnegative integer\n"));
285 critical_time = atoi (optarg); 239 else
240 critical_time = atoi (optarg);
286 check_critical_time = TRUE; 241 check_critical_time = TRUE;
287 break; 242 break;
288 case 'p': /* port */ 243 case 'p': /* port */
289 if (!is_intnonneg (optarg)) 244 if (!is_intnonneg (optarg))
290 usage (_("Server port must be a nonnegative integer\n")); 245 usage (_("Server port must be a nonnegative integer\n"));
291 server_port = atoi (optarg); 246 else
247 server_port = atoi (optarg);
292 break; 248 break;
293 case 't': /* timeout */ 249 case 't': /* timeout */
294 if (!is_intnonneg (optarg)) 250 if (!is_intnonneg (optarg))
295 usage (_("Timeout interval must be a nonnegative integer\n")); 251 usage (_("Timeout interval must be a nonnegative integer\n"));
296 socket_timeout = atoi (optarg); 252 else
253 socket_timeout = atoi (optarg);
297 break; 254 break;
298 } 255 }
299 } 256 }
@@ -312,3 +269,55 @@ process_arguments (int argc, char **argv)
312 269
313 return OK; 270 return OK;
314} 271}
272
273
274
275
276
277
278void
279print_help (void)
280{
281 char *myport;
282 asprintf (&myport, "%d", TIME_PORT);
283
284 print_revision (progname, revision);
285
286 printf (_("Copyright (c) 1999 Ethan Galstad\n"));
287 printf (_(COPYRIGHT), copyright, email);
288
289 printf (_("\
290This plugin will check the time on the specified host.\n\n"));
291
292 print_usage ();
293
294 printf (_(UT_HELP_VRSN));
295
296 printf (_(UT_HOST_PORT), 'p', myport);
297
298 printf (_("\
299 -w, --warning-variance=INTEGER\n\
300 Time difference (sec.) necessary to result in a warning status\n\
301 -c, --critical-variance=INTEGER\n\
302 Time difference (sec.) necessary to result in a critical status\n\
303 -W, --warning-connect=INTEGER\n\
304 Response time (sec.) necessary to result in warning status\n\
305 -C, --critical-connect=INTEGER\n\
306 Response time (sec.) necessary to result in critical status\n"));
307
308 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
309
310 support ();
311}
312
313
314
315
316void
317print_usage (void)
318{
319 printf (_("\
320Usage: %s -H <host_address> [-p port] [-w variance] [-c variance]\n\
321 [-W connect_time] [-C connect_time] [-t timeout]\n"), progname);
322 printf (_(UT_HLP_VRS), progname, progname);
323}
diff --git a/plugins/check_udp.c b/plugins/check_udp.c
index 11b942a..bd5de58 100644
--- a/plugins/check_udp.c
+++ b/plugins/check_udp.c
@@ -25,56 +25,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
25#include "netutils.h" 25#include "netutils.h"
26#include "utils.h" 26#include "utils.h"
27 27
28/* Original Command line:
29 check_udp <host_address> [-p port] [-s send] [-e expect] \
30 [-wt warn_time] [-ct crit_time] [-to to_sec] */
31void
32print_usage (void)
33{
34 printf (_("\
35Usage: %s -H <host_address> [-p port] [-w warn_time] [-c crit_time]\n\
36 [-e expect] [-s send] [-t to_sec] [-v]\n"), progname);
37 printf (_(UT_HLP_VRS), progname, progname);
38}
39
40void
41print_help (void)
42{
43 print_revision (progname, revision);
44
45 printf (_("Copyright (c) 1999 Ethan Galstad\n"));
46 printf (_(COPYRIGHT), copyright, email);
47
48 printf (_("\
49This plugin tests an UDP connection with the specified host.\n\n"));
50
51 print_usage ();
52
53 printf (_(UT_HELP_VRSN));
54
55 printf (_(UT_HOST_PORT), 'p', "none");
56
57 printf (_("\
58 -e, --expect=STRING <optional>\n\
59 String to expect in first line of server response\n\
60 -s, --send=STRING <optional>\n\
61 String to send to the server when initiating the connection\n"));
62
63 printf (_(UT_WARN_CRIT));
64
65 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
66
67 printf (_(UT_VERBOSE));
68
69 printf (_("\
70This plugin will attempt to connect to the specified port on the host.\n\
71Successful connects return STATE_OK, refusals and timeouts return\n\
72STATE_CRITICAL, other errors return STATE_UNKNOWN.\n\n"));
73
74 printf(_(UT_SUPPORT));
75}
76
77int process_arguments (int, char **); 28int process_arguments (int, char **);
29void print_help (void);
30void print_usage (void);
78 31
79int warning_time = 0; 32int warning_time = 0;
80int check_warning_time = FALSE; 33int check_warning_time = FALSE;
@@ -84,7 +37,7 @@ int verbose = FALSE;
84int server_port = 0; 37int server_port = 0;
85char *server_address = NULL; 38char *server_address = NULL;
86char *server_expect = NULL; 39char *server_expect = NULL;
87char *server_send = ""; 40char *server_send;
88 41
89int 42int
90main (int argc, char **argv) 43main (int argc, char **argv)
@@ -207,24 +160,28 @@ process_arguments (int argc, char **argv)
207 case 'c': /* critical */ 160 case 'c': /* critical */
208 if (!is_intnonneg (optarg)) 161 if (!is_intnonneg (optarg))
209 usage (_("Critical threshold must be a nonnegative integer\n")); 162 usage (_("Critical threshold must be a nonnegative integer\n"));
210 critical_time = atoi (optarg); 163 else
164 critical_time = atoi (optarg);
211 check_critical_time = TRUE; 165 check_critical_time = TRUE;
212 break; 166 break;
213 case 'w': /* warning */ 167 case 'w': /* warning */
214 if (!is_intnonneg (optarg)) 168 if (!is_intnonneg (optarg))
215 usage (_("Warning threshold must be a nonnegative integer\n")); 169 usage (_("Warning threshold must be a nonnegative integer\n"));
216 warning_time = atoi (optarg); 170 else
171 warning_time = atoi (optarg);
217 check_warning_time = TRUE; 172 check_warning_time = TRUE;
218 break; 173 break;
219 case 't': /* timeout */ 174 case 't': /* timeout */
220 if (!is_intnonneg (optarg)) 175 if (!is_intnonneg (optarg))
221 usage (_("Timeout interval must be a nonnegative integer\n")); 176 usage (_("Timeout interval must be a nonnegative integer\n"));
222 socket_timeout = atoi (optarg); 177 else
178 socket_timeout = atoi (optarg);
223 break; 179 break;
224 case 'p': /* port */ 180 case 'p': /* port */
225 if (!is_intnonneg (optarg)) 181 if (!is_intnonneg (optarg))
226 usage (_("Server port must be a nonnegative integer\n")); 182 usage (_("Server port must be a nonnegative integer\n"));
227 server_port = atoi (optarg); 183 else
184 server_port = atoi (optarg);
228 break; 185 break;
229 case 'e': /* expect */ 186 case 'e': /* expect */
230 server_expect = optarg; 187 server_expect = optarg;
@@ -245,5 +202,65 @@ process_arguments (int argc, char **argv)
245 if (server_address == NULL) 202 if (server_address == NULL)
246 usage (_("Host name was not supplied\n")); 203 usage (_("Host name was not supplied\n"));
247 204
205 if (server_send == NULL)
206 server_send = strdup("");
207
248 return c; 208 return c;
249} 209}
210
211
212
213
214
215
216void
217print_help (void)
218{
219 print_revision (progname, revision);
220
221 printf (_("Copyright (c) 1999 Ethan Galstad\n"));
222 printf (_(COPYRIGHT), copyright, email);
223
224 printf (_("\
225This plugin tests an UDP connection with the specified host.\n\n"));
226
227 print_usage ();
228
229 printf (_(UT_HELP_VRSN));
230
231 printf (_(UT_HOST_PORT), 'p', "none");
232
233 printf (_("\
234 -e, --expect=STRING <optional>\n\
235 String to expect in first line of server response\n\
236 -s, --send=STRING <optional>\n\
237 String to send to the server when initiating the connection\n"));
238
239 printf (_(UT_WARN_CRIT));
240
241 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
242
243 printf (_(UT_VERBOSE));
244
245 printf (_("\
246This plugin will attempt to connect to the specified port on the host.\n\
247Successful connects return STATE_OK, refusals and timeouts return\n\
248STATE_CRITICAL, other errors return STATE_UNKNOWN.\n\n"));
249
250 printf(_(UT_SUPPORT));
251}
252
253
254
255
256/* Original Command line:
257 check_udp <host_address> [-p port] [-s send] [-e expect] \
258 [-wt warn_time] [-ct crit_time] [-to to_sec] */
259void
260print_usage (void)
261{
262 printf (_("\
263Usage: %s -H <host_address> [-p port] [-w warn_time] [-c crit_time]\n\
264 [-e expect] [-s send] [-t to_sec] [-v]\n"), progname);
265 printf (_(UT_HLP_VRS), progname, progname);
266}
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 499b922..fcee747 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -29,68 +29,6 @@ enum {
29 PORT = 3493 29 PORT = 3493
30}; 30};
31 31
32void
33print_usage (void)
34{
35 printf (_("\
36Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\
37 [-t timeout] [-v]\n"), progname);
38 printf (_(UT_HLP_VRS), progname, progname);
39}
40
41void
42print_help (void)
43{
44 char *myport;
45 asprintf (&myport, "%d", PORT);
46
47 print_revision (progname, revision);
48
49 printf (_("Copyright (c) 2000 Tom Shields"));
50 printf (_(COPYRIGHT), copyright, email);
51
52 printf (_("This plugin tests the UPS service on the specified host.\n\
53Network UPS Tools from www.exploits.org must be running for this plugin to\n\
54work.\n\n"));
55
56 print_usage ();
57
58 printf (_(UT_HELP_VRSN));
59
60 printf (_(UT_HOST_PORT), 'p', myport);
61
62 printf (_("\
63 -u, --ups=STRING\n\
64 Name of UPS\n"));
65
66 printf (_(UT_WARN_CRIT));
67
68 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
69
70 printf (_(UT_VERBOSE));
71
72 printf (_("\
73This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\
74Supply) on a local or remote host. If the UPS is online or calibrating, the\n\
75plugin will return an OK state. If the battery is on it will return a WARNING\n\
76state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\
77state.\n\n"));
78
79 printf (_("\
80You may also specify a variable to check [such as temperature, utility voltage,\n\
81battery load, etc.] as well as warning and critical thresholds for the value of\n\
82that variable. If the remote host has multiple UPS that are being monitored you\n\
83will have to use the [ups] option to specify which UPS to check.\n\n"));
84
85 printf (_("Notes:\n\n\
86This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\
87Smart UPS Tools be installed on the remote host. If you do not have the\n\
88package installed on your system, you can download it from\n\
89http://www.exploits.org/nut\n\n"));
90
91 printf (_(UT_SUPPORT));
92}
93
94#define CHECK_NONE 0 32#define CHECK_NONE 0
95 33
96#define UPS_NONE 0 /* no supported options */ 34#define UPS_NONE 0 /* no supported options */
@@ -110,7 +48,7 @@ http://www.exploits.org/nut\n\n"));
110#define UPSSTATUS_UNKOWN 64 48#define UPSSTATUS_UNKOWN 64
111 49
112int server_port = PORT; 50int server_port = PORT;
113char *server_address = "127.0.0.1"; 51char *server_address;
114char *ups_name = NULL; 52char *ups_name = NULL;
115double warning_value = 0.0; 53double warning_value = 0.0;
116double critical_value = 0.0; 54double critical_value = 0.0;
@@ -124,14 +62,16 @@ double ups_utility_voltage = 0.0;
124double ups_battery_percent = 0.0; 62double ups_battery_percent = 0.0;
125double ups_load_percent = 0.0; 63double ups_load_percent = 0.0;
126double ups_temperature = 0.0; 64double ups_temperature = 0.0;
127char *ups_status = "N/A"; 65char *ups_status;
128 66
129int determine_status (void); 67int determine_status (void);
130int determine_supported_vars (void); 68int determine_supported_vars (void);
131int get_ups_variable (const char *, char *, int); 69int get_ups_variable (const char *, char *, size_t);
132 70
133int process_arguments (int, char **); 71int process_arguments (int, char **);
134int validate_arguments (void); 72int validate_arguments (void);
73void print_help (void);
74void print_usage (void);
135 75
136int 76int
137main (int argc, char **argv) 77main (int argc, char **argv)
@@ -141,6 +81,7 @@ main (int argc, char **argv)
141 char temp_buffer[MAX_INPUT_BUFFER]; 81 char temp_buffer[MAX_INPUT_BUFFER];
142 82
143 double ups_utility_deviation = 0.0; 83 double ups_utility_deviation = 0.0;
84 ups_status = strdup ("N/A");
144 85
145 if (process_arguments (argc, argv) != OK) 86 if (process_arguments (argc, argv) != OK)
146 usage ("Invalid command arguments supplied\n"); 87 usage ("Invalid command arguments supplied\n");
@@ -160,7 +101,7 @@ main (int argc, char **argv)
160 101
161 if (determine_status () != OK) 102 if (determine_status () != OK)
162 return STATE_CRITICAL; 103 return STATE_CRITICAL;
163 asprintf (&ups_status, ""); 104 ups_status = strdup ("");
164 result = STATE_OK; 105 result = STATE_OK;
165 106
166 if (status & UPSSTATUS_OFF) { 107 if (status & UPSSTATUS_OFF) {
@@ -395,7 +336,7 @@ determine_supported_vars (void)
395 336
396/* gets a variable value for a specific UPS */ 337/* gets a variable value for a specific UPS */
397int 338int
398get_ups_variable (const char *varname, char *buf, int buflen) 339get_ups_variable (const char *varname, char *buf, size_t buflen)
399{ 340{
400 /* char command[MAX_INPUT_BUFFER]; */ 341 /* char command[MAX_INPUT_BUFFER]; */
401 char temp_buffer[MAX_INPUT_BUFFER]; 342 char temp_buffer[MAX_INPUT_BUFFER];
@@ -569,6 +510,9 @@ process_arguments (int argc, char **argv)
569 usage ("Invalid host name"); 510 usage ("Invalid host name");
570 } 511 }
571 512
513 if (server_address == NULL)
514 server_address = strdup("127.0.0.1");
515
572 return validate_arguments(); 516 return validate_arguments();
573} 517}
574 518
@@ -581,3 +525,73 @@ validate_arguments (void)
581{ 525{
582 return OK; 526 return OK;
583} 527}
528
529
530
531
532
533
534void
535print_help (void)
536{
537 char *myport;
538 asprintf (&myport, "%d", PORT);
539
540 print_revision (progname, revision);
541
542 printf (_("Copyright (c) 2000 Tom Shields"));
543 printf (_(COPYRIGHT), copyright, email);
544
545 printf (_("This plugin tests the UPS service on the specified host.\n\
546Network UPS Tools from www.exploits.org must be running for this plugin to\n\
547work.\n\n"));
548
549 print_usage ();
550
551 printf (_(UT_HELP_VRSN));
552
553 printf (_(UT_HOST_PORT), 'p', myport);
554
555 printf (_("\
556 -u, --ups=STRING\n\
557 Name of UPS\n"));
558
559 printf (_(UT_WARN_CRIT));
560
561 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
562
563 printf (_(UT_VERBOSE));
564
565 printf (_("\
566This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\
567Supply) on a local or remote host. If the UPS is online or calibrating, the\n\
568plugin will return an OK state. If the battery is on it will return a WARNING\n\
569state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\
570state.\n\n"));
571
572 printf (_("\
573You may also specify a variable to check [such as temperature, utility voltage,\n\
574battery load, etc.] as well as warning and critical thresholds for the value of\n\
575that variable. If the remote host has multiple UPS that are being monitored you\n\
576will have to use the [ups] option to specify which UPS to check.\n\n"));
577
578 printf (_("Notes:\n\n\
579This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\
580Smart UPS Tools be installed on the remote host. If you do not have the\n\
581package installed on your system, you can download it from\n\
582http://www.exploits.org/nut\n\n"));
583
584 printf (_(UT_SUPPORT));
585}
586
587
588
589
590void
591print_usage (void)
592{
593 printf (_("\
594Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\
595 [-t timeout] [-v]\n"), progname);
596 printf (_(UT_HLP_VRS), progname, progname);
597}
diff --git a/plugins/check_users.c b/plugins/check_users.c
index d4480e7..9e18201 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -25,43 +25,11 @@ 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
28void
29print_usage (void)
30{
31 printf ("Usage: %s -w <users> -c <users>\n", progname);
32 printf (_(UT_HLP_VRS), progname, progname);
33}
34
35void
36print_help (void)
37{
38 print_revision (progname, revision);
39
40 printf (_("Copyright (c) 1999 Ethan Galstad\n"));
41 printf (_(COPYRIGHT), copyright, email);
42
43 printf (_("\
44This plugin checks the number of users currently logged in on the local\n\
45system and generates an error if the number exceeds the thresholds specified.\n"));
46
47 print_usage ();
48
49 printf (_(UT_HELP_VRSN));
50
51 printf (_("\
52 -w, --warning=INTEGER\n\
53 Set WARNING status if more than INTEGER users are logged in\n\
54 -c, --critical=INTEGER\n\
55 Set CRITICAL status if more than INTEGER users are logged in\n"));
56
57 printf (_(UT_SUPPORT));
58}
59
60#define possibly_set(a,b) ((a) == 0 ? (b) : 0) 28#define possibly_set(a,b) ((a) == 0 ? (b) : 0)
61 29
62int process_arguments (int, char **); 30int process_arguments (int, char **);
63void print_usage (void);
64void print_help (void); 31void print_help (void);
32void print_usage (void);
65 33
66int wusers = -1; 34int wusers = -1;
67int cusers = -1; 35int cusers = -1;
@@ -171,12 +139,14 @@ process_arguments (int argc, char **argv)
171 case 'c': /* critical */ 139 case 'c': /* critical */
172 if (!is_intnonneg (optarg)) 140 if (!is_intnonneg (optarg))
173 usage (_("Critical threshold must be a nonnegative integer\n")); 141 usage (_("Critical threshold must be a nonnegative integer\n"));
174 cusers = atoi (optarg); 142 else
143 cusers = atoi (optarg);
175 break; 144 break;
176 case 'w': /* warning */ 145 case 'w': /* warning */
177 if (!is_intnonneg (optarg)) 146 if (!is_intnonneg (optarg))
178 usage (_("Warning threshold must be a nonnegative integer\n")); 147 usage (_("Warning threshold must be a nonnegative integer\n"));
179 wusers = atoi (optarg); 148 else
149 wusers = atoi (optarg);
180 break; 150 break;
181 } 151 }
182 } 152 }
@@ -185,14 +155,56 @@ process_arguments (int argc, char **argv)
185 if (wusers == -1 && argc > c) { 155 if (wusers == -1 && argc > c) {
186 if (is_intnonneg (argv[c]) == FALSE) 156 if (is_intnonneg (argv[c]) == FALSE)
187 usage (_("Warning threshold must be a nonnegative integer\n")); 157 usage (_("Warning threshold must be a nonnegative integer\n"));
188 wusers = atoi (argv[c++]); 158 else
159 wusers = atoi (argv[c++]);
189 } 160 }
190 161
191 if (cusers == -1 && argc > c) { 162 if (cusers == -1 && argc > c) {
192 if (is_intnonneg (argv[c]) == FALSE) 163 if (is_intnonneg (argv[c]) == FALSE)
193 usage (_("Warning threshold must be a nonnegative integer\n")); 164 usage (_("Warning threshold must be a nonnegative integer\n"));
194 cusers = atoi (argv[c]); 165 else
166 cusers = atoi (argv[c]);
195 } 167 }
196 168
197 return OK; 169 return OK;
198} 170}
171
172
173
174
175
176
177void
178print_help (void)
179{
180 print_revision (progname, revision);
181
182 printf (_("Copyright (c) 1999 Ethan Galstad\n"));
183 printf (_(COPYRIGHT), copyright, email);
184
185 printf (_("\
186This plugin checks the number of users currently logged in on the local\n\
187system and generates an error if the number exceeds the thresholds specified.\n"));
188
189 print_usage ();
190
191 printf (_(UT_HELP_VRSN));
192
193 printf (_("\
194 -w, --warning=INTEGER\n\
195 Set WARNING status if more than INTEGER users are logged in\n\
196 -c, --critical=INTEGER\n\
197 Set CRITICAL status if more than INTEGER users are logged in\n"));
198
199 printf (_(UT_SUPPORT));
200}
201
202
203
204
205void
206print_usage (void)
207{
208 printf ("Usage: %s -w <users> -c <users>\n", progname);
209 printf (_(UT_HLP_VRS), progname, progname);
210}