summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_ldap.c4
-rw-r--r--plugins/check_nagios.c162
-rw-r--r--plugins/check_radius.c189
-rw-r--r--plugins/check_udp.c182
-rw-r--r--plugins/check_ups.c209
-rw-r--r--plugins/negate.c147
6 files changed, 401 insertions, 492 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index f6e0fca0..2064dd3b 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -88,6 +88,10 @@ print_help ()
88 88
89 printf (_(UT_WARN_CRIT)); 89 printf (_(UT_WARN_CRIT));
90 90
91 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
92
93 printf (_(UT_VERBOSE));
94
91 printf (_(UT_SUPPORT)); 95 printf (_(UT_SUPPORT));
92} 96}
93 97
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index 64a828b9..7ae0ff85 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -1,40 +1,72 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2
3 * CHECK_NAGIOS.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: Nagios process plugin 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) 1999 Ethan Galstad (nagios@nagios.org) 7
8 * 8 This program is distributed in the hope that it will be useful,
9 * $Id$ 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * License Information: 11 GNU General Public License for more details.
12 * 12
13 * This program is free software; you can redistribute it and/or modify 13 You should have received a copy of the GNU General Public License
14 * it under the terms of the GNU General Public License as published by 14 along with this program; if not, write to the Free Software
15 * the Free Software Foundation; either version 2 of the License, or 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 * (at your option) any later version. 16
17 * 17******************************************************************************/
18 * This program is distributed in the hope that it will be useful, 18
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19const char *progname = "check_nagios";
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20const char *revision = "$Revision$";
21 * GNU General Public License for more details. 21const char *copyright = "1999-2003";
22 * 22const char *email = "nagiosplug-devel@lists.sourceforge.net";
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *****************************************************************************/
28 23
29#include "common.h" 24#include "common.h"
30#include "popen.h" 25#include "popen.h"
31#include "utils.h" 26#include "utils.h"
32 27
33const char *progname = "check_nagios"; 28void
29print_usage (void)
30{
31 printf (_("\
32Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"),
33 progname);
34}
34 35
36void
37print_help (void)
38{
39 print_revision (progname, revision);
40
41 printf (_(COPYRIGHT), copyright, email);
42
43 printf (_("\
44This plugin attempts to check the status of the Nagios process on the local\n\
45machine. The plugin will check to make sure the Nagios status log is no older\n\
46than the number of minutes specified by the <expire_minutes> option. It also\n\
47uses the /bin/ps command to check for a process matching whatever you specify\n\
48by 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 (_("\
63Example:\n\
64 ./check_nagios -e 5 \\\
65 -F /usr/local/nagios/var/status.log \\\
66 -C /usr/local/nagios/bin/nagios\n"));
67}
68
35int process_arguments (int, char **); 69int process_arguments (int, char **);
36void print_usage (void);
37void print_help (void);
38 70
39char *status_log = NULL; 71char *status_log = NULL;
40char *process_string = NULL; 72char *process_string = NULL;
@@ -64,11 +96,11 @@ main (int argc, char **argv)
64 int pos, cols; 96 int pos, cols;
65 97
66 if (process_arguments (argc, argv) == ERROR) 98 if (process_arguments (argc, argv) == ERROR)
67 usage ("Could not parse arguments\n"); 99 usage (_("Could not parse arguments\n"));
68 100
69 /* Set signal handling and alarm */ 101 /* Set signal handling and alarm */
70 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { 102 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) {
71 printf ("Cannot catch SIGALRM"); 103 printf (_("Cannot catch SIGALRM"));
72 return STATE_UNKNOWN; 104 return STATE_UNKNOWN;
73 } 105 }
74 106
@@ -78,7 +110,7 @@ main (int argc, char **argv)
78 /* open the status log */ 110 /* open the status log */
79 fp = fopen (status_log, "r"); 111 fp = fopen (status_log, "r");
80 if (fp == NULL) { 112 if (fp == NULL) {
81 printf ("Error: Cannot open status log for reading!\n"); 113 printf (_("Error: Cannot open status log for reading!\n"));
82 return STATE_CRITICAL; 114 return STATE_CRITICAL;
83 } 115 }
84 116
@@ -95,13 +127,13 @@ main (int argc, char **argv)
95 /* run the command to check for the Nagios process.. */ 127 /* run the command to check for the Nagios process.. */
96 child_process = spopen (PS_COMMAND); 128 child_process = spopen (PS_COMMAND);
97 if (child_process == NULL) { 129 if (child_process == NULL) {
98 printf ("Could not open pipe: %s\n", PS_COMMAND); 130 printf (_("Could not open pipe: %s\n"), PS_COMMAND);
99 return STATE_UNKNOWN; 131 return STATE_UNKNOWN;
100 } 132 }
101 133
102 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 134 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
103 if (child_stderr == NULL) { 135 if (child_stderr == NULL) {
104 printf ("Could not open stderr for %s\n", PS_COMMAND); 136 printf (_("Could not open stderr for %s\n"), PS_COMMAND);
105 } 137 }
106 138
107 fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); 139 fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
@@ -116,7 +148,7 @@ main (int argc, char **argv)
116 if (!strstr(procargs, argv[0]) && strstr(procargs, process_string)) { 148 if (!strstr(procargs, argv[0]) && strstr(procargs, process_string)) {
117 proc_entries++; 149 proc_entries++;
118 if (verbose) 150 if (verbose)
119 printf ("Found process: %s\n", procargs); 151 printf (_("Found process: %s\n"), procargs);
120 } 152 }
121 } 153 }
122 } 154 }
@@ -136,18 +168,18 @@ main (int argc, char **argv)
136 alarm (0); 168 alarm (0);
137 169
138 if (proc_entries == 0) { 170 if (proc_entries == 0) {
139 printf ("Could not locate a running Nagios process!\n"); 171 printf (_("Could not locate a running Nagios process!\n"));
140 return STATE_CRITICAL; 172 return STATE_CRITICAL;
141 } 173 }
142 174
143 result = STATE_OK; 175 result = STATE_OK;
144 176
145 time (&current_time); 177 time (&current_time);
146 if ((current_time - latest_entry_time) > (expire_minutes * 60)) 178 if ((int)(current_time - latest_entry_time) > (expire_minutes * 60))
147 result = STATE_WARNING; 179 result = STATE_WARNING;
148 180
149 printf 181 printf
150 ("Nagios %s: located %d process%s, status log updated %d second%s ago\n", 182 (_("Nagios %s: located %d process%s, status log updated %d second%s ago\n"),
151 (result == STATE_OK) ? "ok" : "problem", proc_entries, 183 (result == STATE_OK) ? "ok" : "problem", proc_entries,
152 (proc_entries == 1) ? "" : "es", 184 (proc_entries == 1) ? "" : "es",
153 (int) (current_time - latest_entry_time), 185 (int) (current_time - latest_entry_time),
@@ -186,7 +218,7 @@ process_arguments (int argc, char **argv)
186 expire_minutes = atoi (argv[2]); 218 expire_minutes = atoi (argv[2]);
187 else 219 else
188 terminate (STATE_UNKNOWN, 220 terminate (STATE_UNKNOWN,
189 "Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n", 221 _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
190 progname); 222 progname);
191 process_string = argv[3]; 223 process_string = argv[3];
192 return OK; 224 return OK;
@@ -200,7 +232,7 @@ process_arguments (int argc, char **argv)
200 232
201 switch (c) { 233 switch (c) {
202 case '?': /* print short usage statement if args not parsable */ 234 case '?': /* print short usage statement if args not parsable */
203 printf ("%s: Unknown argument: %c\n\n", progname, optopt); 235 printf (_("%s: Unknown argument: %c\n\n"), progname, optopt);
204 print_usage (); 236 print_usage ();
205 exit (STATE_UNKNOWN); 237 exit (STATE_UNKNOWN);
206 case 'h': /* help */ 238 case 'h': /* help */
@@ -220,7 +252,7 @@ process_arguments (int argc, char **argv)
220 expire_minutes = atoi (optarg); 252 expire_minutes = atoi (optarg);
221 else 253 else
222 terminate (STATE_UNKNOWN, 254 terminate (STATE_UNKNOWN,
223 "Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n", 255 _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
224 progname); 256 progname);
225 break; 257 break;
226 case 'v': 258 case 'v':
@@ -232,56 +264,12 @@ process_arguments (int argc, char **argv)
232 264
233 if (status_log == NULL) 265 if (status_log == NULL)
234 terminate (STATE_UNKNOWN, 266 terminate (STATE_UNKNOWN,
235 "You must provide the status_log\nType '%s -h' for additional help\n", 267 _("You must provide the status_log\nType '%s -h' for additional help\n"),
236 progname); 268 progname);
237 else if (process_string == NULL) 269 else if (process_string == NULL)
238 terminate (STATE_UNKNOWN, 270 terminate (STATE_UNKNOWN,
239 "You must provide a process string\nType '%s -h' for additional help\n", 271 _("You must provide a process string\nType '%s -h' for additional help\n"),
240 progname); 272 progname);
241 273
242 return OK; 274 return OK;
243} 275}
244
245
246
247
248
249void
250print_usage (void)
251{
252 printf
253 ("Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n",
254 progname);
255}
256
257
258
259
260
261void
262print_help (void)
263{
264 print_revision (progname, "$Revision$");
265 printf
266 ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n"
267 "This plugin attempts to check the status of the Nagios process on the local\n"
268 "machine. The plugin will check to make sure the Nagios status log is no older\n"
269 "than the number of minutes specified by the <expire_minutes> option. It also\n"
270 "uses the /bin/ps command to check for a process matching whatever you specify\n"
271 "by the <process_string> argument.\n");
272 print_usage ();
273 printf
274 ("\nOptions:\n"
275 "-F, --filename=FILE\n"
276 " Name of the log file to check\n"
277 "-e, --expires=INTEGER\n"
278 " Seconds aging afterwhich logfile is condsidered stale\n"
279 "-C, --command=STRING\n"
280 " Command to search for in process table\n"
281 "-h, --help\n"
282 " Print this help screen\n"
283 "-V, --version\n"
284 " Print version information\n\n"
285 "Example:\n"
286 " ./check_nagios -F /usr/local/nagios/var/status.log -e 5 -C /usr/local/nagios/bin/nagios\n");
287}
diff --git a/plugins/check_radius.c b/plugins/check_radius.c
index c71f3b4c..3aa5ae71 100644
--- a/plugins/check_radius.c
+++ b/plugins/check_radius.c
@@ -1,45 +1,60 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2
3 * Program: radius server check 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 * 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 *****************************************************************************/
25 18
26const char *progname = "check_radius"; 19const char *progname = "check_radius";
27#define REVISION "$Revision$" 20const char *revision = "$Revision$";
28#define COPYRIGHT "1999-2001" 21const char *copyright = "2000-2003";
29#define AUTHORS "Robert August Vincent II/Karl DeBisschop" 22const char *email = "nagiosplug-devel@lists.sourceforge.net";
30#define EMAIL "kdebisschop@users.sourceforge.net" 23
31#define SUMMARY "Tests to see if a radius server is accepting connections.\n" 24#include "config.h"
32 25#include "common.h"
33#define OPTIONS "\ 26#include "utils.h"
34-H host -F config_file -u username -p password\'\ 27#include <radiusclient.h>
35 [-P port] [-t timeout] [-r retries] [-e expect]" 28
36 29void
37#define LONGOPTIONS "\ 30print_usage (void)
38 -H, --hostname=HOST\n\ 31{
39 Host name argument for servers using host headers (use numeric\n\ 32 printf ("\
40 address if possible to bypass DNS lookup).\n\ 33Usage: %s -H host -F config_file -u username -p password [-P port]\n\
41 -P, --port=INTEGER\n\ 34 [-t timeout] [-r retries] [-e expect]\n", progname);
42 Port number (default: %d)\n\ 35 printf (_(UT_HLP_VRS), progname, progname);
36}
37
38void
39print_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 (_("\
43 -u, --username=STRING\n\ 58 -u, --username=STRING\n\
44 The user to authenticate\n\ 59 The user to authenticate\n\
45 -p, --password=STRING\n\ 60 -p, --password=STRING\n\
@@ -49,48 +64,38 @@ const char *progname = "check_radius";
49 -e, --expect=STRING\n\ 64 -e, --expect=STRING\n\
50 Response string to expect from the server\n\ 65 Response string to expect from the server\n\
51 -r, --retries=INTEGER\n\ 66 -r, --retries=INTEGER\n\
52 Number of times to retry a failed connection\n\ 67 Number of times to retry a failed connection\n"));
53 -t, --timeout=INTEGER\n\ 68
54 Seconds before connection times out (default: %d)\n\ 69 printf (_(UT_TIMEOUT), timeout_interval);
55 -v, --verbose\n\ 70
56 Show details for command-line debugging (do not use with nagios server)\n\ 71 printf (_("\n\
57 -h, --help\n\
58 Print detailed help screen\n\
59 -V, --version\n\
60 Print version information\n"
61
62#define DESCRIPTION "\
63This plugin tests a radius server to see if it is accepting connections.\n\ 72This plugin tests a radius server to see if it is accepting connections.\n\
64\n\ 73\n\
65The server to test must be specified in the invocation, as well as a user\n\ 74The server to test must be specified in the invocation, as well as a user\n\
66name and password. A configuration file may also be present. The format of\n\ 75name and password. A configuration file may also be present. The format of\n\
67the configuration file is described in the radiusclient library sources.\n\ 76the configuration file is described in the radiusclient library sources.\n\n"));
68\n\ 77
78 printf (_("\
69The password option presents a substantial security issue because the\n\ 79The password option presents a substantial security issue because the\n\
70password can be determined by careful watching of the command line in\n\ 80password can be determined by careful watching of the command line in\n\
71a process listing. This risk is exacerbated because nagios will\n\ 81a process listing. This risk is exacerbated because nagios will\n\
72run the plugin at regular prdictable intervals. Please be sure that\n\ 82run the plugin at regular prdictable intervals. Please be sure that\n\
73the password used does not allow access to sensitive system resources,\n\ 83the password used does not allow access to sensitive system resources,\n\
74otherwise compormise could occur.\n" 84otherwise compormise could occur.\n"));
75
76#include "config.h"
77#include "common.h"
78#include "utils.h"
79#include <radiusclient.h>
80 85
86 printf (_(UT_SUPPORT));
87}
88
81int process_arguments (int, char **); 89int process_arguments (int, char **);
82void print_usage (void);
83void print_help (void);
84 90
85char *server = NULL; 91char *server = NULL;
86int port = PW_AUTH_UDP_PORT;
87char *username = NULL; 92char *username = NULL;
88char *password = NULL; 93char *password = NULL;
89char *expect = NULL; 94char *expect = NULL;
90char *config_file = NULL; 95char *config_file = NULL;
96int port = PW_AUTH_UDP_PORT;
91int retries = 1; 97int retries = 1;
92int verbose = FALSE; 98int verbose = FALSE;
93
94ENV *env = NULL; 99ENV *env = NULL;
95 100
96/****************************************************************************** 101/******************************************************************************
@@ -151,23 +156,23 @@ main (int argc, char **argv)
151{ 156{
152 UINT4 service; 157 UINT4 service;
153 char msg[BUFFER_LEN]; 158 char msg[BUFFER_LEN];
154 SEND_DATA data = { 0 }; 159 SEND_DATA data;
155 int result; 160 int result;
156 UINT4 client_id; 161 UINT4 client_id;
157 162
158 if (process_arguments (argc, argv) == ERROR) 163 if (process_arguments (argc, argv) == ERROR)
159 usage ("Could not parse arguments\n"); 164 usage (_("Could not parse arguments\n"));
160 165
161 if ((config_file && rc_read_config (config_file)) || 166 if ((config_file && rc_read_config (config_file)) ||
162 rc_read_dictionary (rc_conf_str ("dictionary"))) 167 rc_read_dictionary (rc_conf_str ("dictionary")))
163 terminate (STATE_UNKNOWN, "Config file error"); 168 terminate (STATE_UNKNOWN, _("Config file error"));
164 169
165 service = PW_AUTHENTICATE_ONLY; 170 service = PW_AUTHENTICATE_ONLY;
166 171
167 if (!(rc_avpair_add (&data.send_pairs, PW_SERVICE_TYPE, &service, 0) && 172 if (!(rc_avpair_add (&data.send_pairs, PW_SERVICE_TYPE, &service, 0) &&
168 rc_avpair_add (&data.send_pairs, PW_USER_NAME, username, 0) && 173 rc_avpair_add (&data.send_pairs, PW_USER_NAME, username, 0) &&
169 rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0))) 174 rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0)))
170 terminate (STATE_UNKNOWN, "Out of Memory?"); 175 terminate (STATE_UNKNOWN, _("Out of Memory?"));
171 176
172 /* 177 /*
173 * Fill in NAS-IP-Address 178 * Fill in NAS-IP-Address
@@ -188,15 +193,15 @@ main (int argc, char **argv)
188 rc_avpair_free (data.receive_pairs); 193 rc_avpair_free (data.receive_pairs);
189 194
190 if (result == TIMEOUT_RC) 195 if (result == TIMEOUT_RC)
191 terminate (STATE_CRITICAL, "Timeout"); 196 terminate (STATE_CRITICAL, _("Timeout"));
192 if (result == ERROR_RC) 197 if (result == ERROR_RC)
193 terminate (STATE_CRITICAL, "Auth Error"); 198 terminate (STATE_CRITICAL, _("Auth Error"));
194 if (result == BADRESP_RC) 199 if (result == BADRESP_RC)
195 terminate (STATE_WARNING, "Auth Failed"); 200 terminate (STATE_WARNING, _("Auth Failed"));
196 if (expect && !strstr (msg, expect)) 201 if (expect && !strstr (msg, expect))
197 terminate (STATE_WARNING, msg); 202 terminate (STATE_WARNING, msg);
198 if (result == OK_RC) 203 if (result == OK_RC)
199 terminate (STATE_OK, "Auth OK"); 204 terminate (STATE_OK, _("Auth OK"));
200 return (0); 205 return (0);
201} 206}
202 207
@@ -234,16 +239,16 @@ process_arguments (int argc, char **argv)
234 if (is_intpos (argv[4])) 239 if (is_intpos (argv[4]))
235 timeout_interval = atoi (argv[4]); 240 timeout_interval = atoi (argv[4]);
236 else 241 else
237 usage ("Timeout interval must be a positive integer"); 242 usage (_("Timeout interval must be a positive integer"));
238 if (is_intpos (argv[5])) 243 if (is_intpos (argv[5]))
239 retries = atoi (argv[5]); 244 retries = atoi (argv[5]);
240 else 245 else
241 usage ("Number of retries must be a positive integer"); 246 usage (_("Number of retries must be a positive integer"));
242 server = argv[6]; 247 server = argv[6];
243 if (is_intpos (argv[7])) 248 if (is_intpos (argv[7]))
244 port = atoi (argv[7]); 249 port = atoi (argv[7]);
245 else 250 else
246 usage ("Server port must be a positive integer"); 251 usage (_("Server port must be a positive integer"));
247 expect = argv[8]; 252 expect = argv[8];
248 return OK; 253 return OK;
249 } 254 }
@@ -257,21 +262,21 @@ process_arguments (int argc, char **argv)
257 262
258 switch (c) { 263 switch (c) {
259 case '?': /* print short usage statement if args not parsable */ 264 case '?': /* print short usage statement if args not parsable */
260 printf ("%s: Unknown argument: %s\n\n", progname, optarg); 265 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
261 print_usage (); 266 print_usage ();
262 exit (STATE_UNKNOWN); 267 exit (STATE_UNKNOWN);
263 case 'h': /* help */ 268 case 'h': /* help */
264 print_help (); 269 print_help ();
265 exit (OK); 270 exit (OK);
266 case 'V': /* version */ 271 case 'V': /* version */
267 print_revision (progname, "$Revision$"); 272 print_revision (progname, revision);
268 exit (OK); 273 exit (OK);
269 case 'v': /* verbose mode */ 274 case 'v': /* verbose mode */
270 verbose = TRUE; 275 verbose = TRUE;
271 break; 276 break;
272 case 'H': /* hostname */ 277 case 'H': /* hostname */
273 if (is_host (optarg) == FALSE) { 278 if (is_host (optarg) == FALSE) {
274 printf ("Invalid host name/address\n\n"); 279 printf (_("Invalid host name/address\n\n"));
275 print_usage (); 280 print_usage ();
276 exit (STATE_UNKNOWN); 281 exit (STATE_UNKNOWN);
277 } 282 }
@@ -281,7 +286,7 @@ process_arguments (int argc, char **argv)
281 if (is_intnonneg (optarg)) 286 if (is_intnonneg (optarg))
282 port = atoi (optarg); 287 port = atoi (optarg);
283 else 288 else
284 usage ("Server port must be a positive integer"); 289 usage (_("Server port must be a positive integer"));
285 break; 290 break;
286 case 'u': /* username */ 291 case 'u': /* username */
287 username = optarg; 292 username = optarg;
@@ -299,41 +304,15 @@ process_arguments (int argc, char **argv)
299 if (is_intpos (optarg)) 304 if (is_intpos (optarg))
300 retries = atoi (optarg); 305 retries = atoi (optarg);
301 else 306 else
302 usage ("Number of retries must be a positive integer"); 307 usage (_("Number of retries must be a positive integer"));
303 break; 308 break;
304 case 't': /* timeout */ 309 case 't': /* timeout */
305 if (is_intpos (optarg)) 310 if (is_intpos (optarg))
306 timeout_interval = atoi (optarg); 311 timeout_interval = atoi (optarg);
307 else 312 else
308 usage ("Timeout interval must be a positive integer"); 313 usage (_("Timeout interval must be a positive integer"));
309 break; 314 break;
310 } 315 }
311 } 316 }
312 return OK; 317 return OK;
313} 318}
314
315
316
317void
318print_help (void)
319{
320 print_revision (progname, REVISION);
321 printf
322 ("Copyright (c) %s %s <%s>\n\n%s\n",
323 COPYRIGHT, AUTHORS, EMAIL, SUMMARY);
324 print_usage ();
325 printf
326 ("\nOptions:\n" LONGOPTIONS "\n" DESCRIPTION "\n",
327 port, timeout_interval);
328 support ();
329}
330
331
332void
333print_usage (void)
334{
335 printf ("Usage:\n" " %s %s\n"
336 " %s (-h | --help) for detailed help\n"
337 " %s (-V | --version) for version information\n",
338 progname, OPTIONS, progname, progname);
339}
diff --git a/plugins/check_udp.c b/plugins/check_udp.c
index da9a1420..3e903dfc 100644
--- a/plugins/check_udp.c
+++ b/plugins/check_udp.c
@@ -1,57 +1,84 @@
1/****************************************************************************** 1/******************************************************************************
2* 2
3* CHECK_UDP.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: UDP port plugin 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) 1999 Ethan Galstad (nagios@nagios.org) 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* 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* Command line: CHECK_UDP <host_address> [-p port] [-s send] [-e expect] \ 11 GNU General Public License for more details.
12* [-wt warn_time] [-ct crit_time] [-to to_sec] 12
13* 13 You should have received a copy of the GNU General Public License
14* Description: 14 along with this program; if not, write to the Free Software
15* 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16* This plugin will attempt to connect to the specified port 16
17* on the host. Successul connects return STATE_OK, refusals
18* and timeouts return STATE_CRITICAL, other errors return
19* STATE_UNKNOWN.
20*
21* License Information:
22*
23* This program is free software; you can redistribute it and/or modify
24* it under the terms of the GNU General Public License as published by
25* the Free Software Foundation; either version 2 of the License, or
26* (at your option) any later version.
27*
28* This program is distributed in the hope that it will be useful,
29* but WITHOUT ANY WARRANTY; without even the implied warranty of
30* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31* GNU General Public License for more details.
32*
33* You should have received a copy of the GNU General Public License
34* along with this program; if not, write to the Free Software
35* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36*
37*****************************************************************************/ 17*****************************************************************************/
38 18
39#include "config.h" 19const char *progname = "check_udp";
20const char *revision = "$Revision$";
21const char *copyright = "1999-2002";
22const char *email = "nagiosplug-devel@lists.sourceforge.net";
23
40#include "common.h" 24#include "common.h"
41#include "netutils.h" 25#include "netutils.h"
42#include "utils.h" 26#include "utils.h"
43 27
44const char *progname = "check_udp"; 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}
38
39void
40print_help (void)
41{
42 print_revision (progname, revision);
43
44 printf (_("Copyright (c) 1999 Ethan Galstad\n"));
45 printf (_(COPYRIGHT), copyright, email);
46
47 printf (_("\
48This plugin tests an UDP connection with the specified host.\n\n"));
49
50 print_usage ();
51
52 printf (_(UT_HELP_VRSN));
53
54 printf (_(UT_HOST_PORT), 'p', "none");
55
56 printf (_("\
57 -e, --expect=STRING <optional>\n\
58 String to expect in first line of server response\n\
59 -s, --send=STRING <optional>\n\
60 String to send to the server when initiating the connection\n"));
61
62 printf (_(UT_WARN_CRIT));
63
64 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
65
66 printf (_(UT_VERBOSE));
67
68 printf (_("\
69This plugin will attempt to connect to the specified port on the host.\n\
70Successful connects return STATE_OK, refusals and timeouts return\n\
71STATE_CRITICAL, other errors return STATE_UNKNOWN.\n\n"));
72
73 printf(_(UT_SUPPORT));
74}
75
76int process_arguments (int, char **);
45 77
46int warning_time = 0; 78int warning_time = 0;
47int check_warning_time = FALSE; 79int check_warning_time = FALSE;
48int critical_time = 0; 80int critical_time = 0;
49int check_critical_time = FALSE; 81int check_critical_time = FALSE;
50
51int process_arguments (int, char **);
52void print_usage (void);
53void print_help (void);
54
55int verbose = FALSE; 82int verbose = FALSE;
56int server_port = 0; 83int server_port = 0;
57char *server_address = NULL; 84char *server_address = NULL;
@@ -104,8 +131,8 @@ main (int argc, char **argv)
104 && (end_time - start_time) > warning_time) result = 131 && (end_time - start_time) > warning_time) result =
105 STATE_WARNING; 132 STATE_WARNING;
106 133
107 printf ("Connection %s on port %d - %d second response time\n", 134 printf (_("Connection %s on port %d - %d second response time\n"),
108 (result == STATE_OK) ? "accepted" : "problem", server_port, 135 (result == STATE_OK) ? _("accepted") : _("problem"), server_port,
109 (int) (end_time - start_time)); 136 (int) (end_time - start_time));
110 } 137 }
111 138
@@ -159,43 +186,43 @@ process_arguments (int argc, char **argv)
159 186
160 switch (c) { 187 switch (c) {
161 case '?': /* print short usage statement if args not parsable */ 188 case '?': /* print short usage statement if args not parsable */
162 printf ("%s: Unknown argument: %s\n\n", progname, optarg); 189 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
163 print_usage (); 190 print_usage ();
164 exit (STATE_UNKNOWN); 191 exit (STATE_UNKNOWN);
165 case 'h': /* help */ 192 case 'h': /* help */
166 print_help (); 193 print_help ();
167 exit (STATE_OK); 194 exit (STATE_OK);
168 case 'V': /* version */ 195 case 'V': /* version */
169 print_revision (progname, "$Revision$"); 196 print_revision (progname, revision);
170 exit (STATE_OK); 197 exit (STATE_OK);
171 case 'v': /* verbose mode */ 198 case 'v': /* verbose mode */
172 verbose = TRUE; 199 verbose = TRUE;
173 break; 200 break;
174 case 'H': /* hostname */ 201 case 'H': /* hostname */
175 if (is_host (optarg) == FALSE) 202 if (is_host (optarg) == FALSE)
176 usage ("Invalid host name/address\n"); 203 usage (_("Invalid host name/address\n"));
177 server_address = optarg; 204 server_address = optarg;
178 break; 205 break;
179 case 'c': /* critical */ 206 case 'c': /* critical */
180 if (!is_intnonneg (optarg)) 207 if (!is_intnonneg (optarg))
181 usage ("Critical threshold must be a nonnegative integer\n"); 208 usage (_("Critical threshold must be a nonnegative integer\n"));
182 critical_time = atoi (optarg); 209 critical_time = atoi (optarg);
183 check_critical_time = TRUE; 210 check_critical_time = TRUE;
184 break; 211 break;
185 case 'w': /* warning */ 212 case 'w': /* warning */
186 if (!is_intnonneg (optarg)) 213 if (!is_intnonneg (optarg))
187 usage ("Warning threshold must be a nonnegative integer\n"); 214 usage (_("Warning threshold must be a nonnegative integer\n"));
188 warning_time = atoi (optarg); 215 warning_time = atoi (optarg);
189 check_warning_time = TRUE; 216 check_warning_time = TRUE;
190 break; 217 break;
191 case 't': /* timeout */ 218 case 't': /* timeout */
192 if (!is_intnonneg (optarg)) 219 if (!is_intnonneg (optarg))
193 usage ("Timeout interval must be a nonnegative integer\n"); 220 usage (_("Timeout interval must be a nonnegative integer\n"));
194 socket_timeout = atoi (optarg); 221 socket_timeout = atoi (optarg);
195 break; 222 break;
196 case 'p': /* port */ 223 case 'p': /* port */
197 if (!is_intnonneg (optarg)) 224 if (!is_intnonneg (optarg))
198 usage ("Serevr port must be a nonnegative integer\n"); 225 usage (_("Server port must be a nonnegative integer\n"));
199 server_port = atoi (optarg); 226 server_port = atoi (optarg);
200 break; 227 break;
201 case 'e': /* expect */ 228 case 'e': /* expect */
@@ -210,61 +237,12 @@ process_arguments (int argc, char **argv)
210 c = optind; 237 c = optind;
211 if (server_address == NULL && c < argc && argv[c]) { 238 if (server_address == NULL && c < argc && argv[c]) {
212 if (is_host (argv[c]) == FALSE) 239 if (is_host (argv[c]) == FALSE)
213 usage ("Invalid host name/address\n"); 240 usage (_("Invalid host name/address\n"));
214 server_address = argv[c++]; 241 server_address = argv[c++];
215 } 242 }
216 243
217 if (server_address == NULL) 244 if (server_address == NULL)
218 usage ("Host name was not supplied\n"); 245 usage (_("Host name was not supplied\n"));
219 246
220 return c; 247 return c;
221} 248}
222
223
224
225
226
227void
228print_usage (void)
229{
230 printf
231 ("Usage: %s -H <host_address> [-p port] [-w warn_time] [-c crit_time]\n"
232 " [-e expect] [-s send] [-t to_sec] [-v]\n", progname);
233}
234
235
236
237
238
239void
240print_help (void)
241{
242 print_revision (progname, "$Revision$");
243 printf
244 ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n"
245 "This plugin tests an UDP connection with the specified host.\n\n");
246 print_usage ();
247 printf
248 ("Options:\n"
249 " -H, --hostname=ADDRESS\n"
250 " Host name argument for servers using host headers (use numeric\n"
251 " address if possible to bypass DNS lookup).\n"
252 " -p, --port=INTEGER\n"
253 " Port number\n"
254 " -e, --expect=STRING <optional>\n"
255 " String to expect in first line of server response\n"
256 " -s, --send=STRING <optional>\n"
257 " String to send to the server when initiating the connection\n"
258 " -w, --warning=INTEGER <optional>\n"
259 " Response time to result in warning status (seconds)\n"
260 " -c, --critical=INTEGER <optional>\n"
261 " Response time to result in critical status (seconds)\n"
262 " -t, --timeout=INTEGER <optional>\n"
263 " Seconds before connection times out (default: %d)\n"
264 " -v, --verbose <optional>\n"
265 " Show details for command-line debugging (do not use with nagios server)\n"
266 " -h, --help\n"
267 " Print detailed help screen and exit\n"
268 " -V, --version\n"
269 " Print version information and exit\n", DEFAULT_SOCKET_TIMEOUT);
270}
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index b077d31f..499b9222 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -1,70 +1,97 @@
1/****************************************************************************** 1/******************************************************************************
2* 2
3* CHECK_UPS.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: UPS monitor plugin for Nagios 5 the Free Software Foundation; either version 2 of the License, or (at
6* License: GPL 6 your option) any later version.
7* Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) 7
8* 8 This program is distributed in the hope that it will be useful, but
9* Last Modified: $Date$ 9 WITHOUT ANY WARRANTY; without even the implied warranty of
10* 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11* Command line: CHECK_UPS <host_address> [-u ups] [-p port] [-v variable] \ 11 General Public License for more details.
12* [-wv warn_value] [-cv crit_value] [-to to_sec] 12
13* 13 You should have received a copy of the GNU General Public License
14* Description: 14 along with this program; if not, write to the Free Software
15* 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 16
17* This plugin attempts to determine the status of an UPS
18* (Uninterruptible Power Supply) on a remote host (or the local host)
19* that is being monitored with Russel Kroll's "Smarty UPS Tools"
20* package. If the UPS is online or calibrating, the plugin will
21* return an OK state. If the battery is on it will return a WARNING
22* state. If the UPS is off or has a low battery the plugin will
23* return a CRITICAL state. You may also specify a variable to check
24* (such as temperature, utility voltage, battery load, etc.) as well
25* as warning and critical thresholds for the value of that variable.
26* If the remote host has multiple UPS that are being monitored you
27* will have to use the [ups] option to specify which UPS to check.
28*
29* Notes:
30*
31* This plugin requires that the UPSD daemon distributed with Russel
32* Kroll's "Smart UPS Tools" be installed on the remote host. If you
33* don't have the package installed on your system, you can download
34* it from http://www.exploits.org/nut
35*
36* License Information:
37*
38* This program is free software; you can redistribute it and/or modify
39* it under the terms of the GNU General Public License as published by
40* the Free Software Foundation; either version 2 of the License, or
41* (at your option) any later version.
42*
43* This program is distributed in the hope that it will be useful,
44* but WITHOUT ANY WARRANTY; without even the implied warranty of
45* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46* GNU General Public License for more details.
47*
48* You should have received a copy of the GNU General Public License
49* along with this program; if not, write to the Free Software
50* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
51*
52******************************************************************************/ 17******************************************************************************/
53 18
54#include "config.h" 19const char *progname = "check_ups";
20const char *revision = "$Revision$";
21const char *copyright = "2000-2002";
22const char *email = "nagiosplug-devel@lists.sourceforge.net";
23
55#include "common.h" 24#include "common.h"
56#include "netutils.h" 25#include "netutils.h"
57#include "utils.h" 26#include "utils.h"
58 27
59const char *progname = "check_ups"; 28enum {
60#define REVISION "$Revision$" 29 PORT = 3493
61#define COPYRIGHT "1999-2002" 30};
62#define AUTHOR "Ethan Galstad" 31
63#define EMAIL "nagios@nagios.org" 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));
64 67
65#define CHECK_NONE 0 68 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
66 69
67#define PORT 3493 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
68 95
69#define UPS_NONE 0 /* no supported options */ 96#define UPS_NONE 0 /* no supported options */
70#define UPS_UTILITY 1 /* supports utility line voltage */ 97#define UPS_UTILITY 1 /* supports utility line voltage */
@@ -85,18 +112,18 @@ const char *progname = "check_ups";
85int server_port = PORT; 112int server_port = PORT;
86char *server_address = "127.0.0.1"; 113char *server_address = "127.0.0.1";
87char *ups_name = NULL; 114char *ups_name = NULL;
88double warning_value = 0.0L; 115double warning_value = 0.0;
89double critical_value = 0.0L; 116double critical_value = 0.0;
90int check_warning_value = FALSE; 117int check_warning_value = FALSE;
91int check_critical_value = FALSE; 118int check_critical_value = FALSE;
92int check_variable = UPS_NONE; 119int check_variable = UPS_NONE;
93int supported_options = UPS_NONE; 120int supported_options = UPS_NONE;
94int status = UPSSTATUS_NONE; 121int status = UPSSTATUS_NONE;
95 122
96double ups_utility_voltage = 0.0L; 123double ups_utility_voltage = 0.0;
97double ups_battery_percent = 0.0L; 124double ups_battery_percent = 0.0;
98double ups_load_percent = 0.0L; 125double ups_load_percent = 0.0;
99double ups_temperature = 0.0L; 126double ups_temperature = 0.0;
100char *ups_status = "N/A"; 127char *ups_status = "N/A";
101 128
102int determine_status (void); 129int determine_status (void);
@@ -105,8 +132,6 @@ int get_ups_variable (const char *, char *, int);
105 132
106int process_arguments (int, char **); 133int process_arguments (int, char **);
107int validate_arguments (void); 134int validate_arguments (void);
108void print_help (void);
109void print_usage (void);
110 135
111int 136int
112main (int argc, char **argv) 137main (int argc, char **argv)
@@ -115,7 +140,7 @@ main (int argc, char **argv)
115 char *message; 140 char *message;
116 char temp_buffer[MAX_INPUT_BUFFER]; 141 char temp_buffer[MAX_INPUT_BUFFER];
117 142
118 double ups_utility_deviation = 0.0L; 143 double ups_utility_deviation = 0.0;
119 144
120 if (process_arguments (argc, argv) != OK) 145 if (process_arguments (argc, argv) != OK)
121 usage ("Invalid command arguments supplied\n"); 146 usage ("Invalid command arguments supplied\n");
@@ -556,53 +581,3 @@ validate_arguments (void)
556{ 581{
557 return OK; 582 return OK;
558} 583}
559
560
561
562
563
564void
565print_help (void)
566{
567 print_revision (progname, "$Revision$");
568 printf
569 ("Copyright (c) 2000 Tom Shields/Karl DeBisschop\n\n"
570 "This plugin tests the UPS service on the specified host.\n"
571 "Newtork UPS Tools for www.exploits.org must be running for this plugin to work.\n\n");
572 print_usage ();
573 printf
574 ("\nOptions:\n"
575 " -H, --hostname=STRING or IPADDRESS\n"
576 " Check server on the indicated host\n"
577 " -p, --port=INTEGER\n"
578 " Make connection on the indicated port (default: %d)\n"
579 " -u, --ups=STRING\n"
580 " Name of UPS\n"
581 " -w, --warning=INTEGER\n"
582 " Seconds necessary to result in a warning status\n"
583 " -c, --critical=INTEGER\n"
584 " Seconds necessary to result in a critical status\n"
585 " -t, --timeout=INTEGER\n"
586 " Seconds before connection attempt times out (default: %d)\n"
587 " -v, --verbose\n"
588 " Print extra information (command-line use only)\n"
589 " -h, --help\n"
590 " Print detailed help screen\n"
591 " -V, --version\n"
592 " Print version information\n\n", PORT, DEFAULT_SOCKET_TIMEOUT);
593 support ();
594}
595
596
597
598
599
600void
601print_usage (void)
602{
603 printf
604 ("Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n"
605 " [-t timeout] [-v]\n"
606 " %s --help\n"
607 " %s --version\n", progname, progname, progname);
608}
diff --git a/plugins/negate.c b/plugins/negate.c
index d1fcb5dd..faf81b34 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -1,68 +1,79 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2
3 * Program: Inverting plugin wrapper 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 * 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 *****************************************************************************/
25 18
26const char *progname = "negate"; 19const char *progname = "negate";
27#define REVISION "$Revision$" 20const char *revision = "$Revision$";
28#define COPYRIGHT "2002" 21const char *copyright = "2002-2003";
29#define AUTHOR "Karl DeBisschop" 22const char *email = "nagiosplug-devel@lists.sourceforge.net";
30#define EMAIL "kdebisschop@users.sourceforge.net" 23
31#define SUMMARY "Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n" 24#define DEFAULT_TIMEOUT 9
25
26#include "common.h"
27#include "utils.h"
28#include "popen.h"
29
30void
31print_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
38void
39print_help (void)
40{
41 print_revision (progname, revision);
42
43 printf (_(COPYRIGHT), copyright, email);
44
45 printf (_("\
46Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\
47\n"));
48
49 print_usage ();
32 50
33#define OPTIONS "\ 51 printf (_(UT_HELP_VRSN));
34[-t timeout] <definition of wrapped plugin>"
35 52
36#define LONGOPTIONS "\ 53 printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
37 -t, --timeout=INTEGER\n\
38 Terminate test if timeout limit is exceeded (default: %d)\n\
39 [keep this less than the plugin timeout to retain CRITICAL status]\n"
40 54
41#define EXAMPLES "\ 55 printf (_("\
56 [keep timeout than the plugin timeout to retain CRITICAL status]\n"));
57
58 printf (_("\
42 negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\ 59 negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\
43 Run check_ping and invert result. Must use full path to plugin\n\ 60 Run check_ping and invert result. Must use full path to plugin\n\
44 negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\ 61 negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\
45 Use single quotes if you need to retain spaces\n" 62 Use single quotes if you need to retain spaces\n"));
46 63
47#define DESCRIPTION "\ 64 printf (_("\
48This plugin is a wrapper to take the output of another plugin and invert it.\n\ 65This plugin is a wrapper to take the output of another plugin and invert it.\n\
49If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\ 66If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\
50If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\ 67If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\
51Otherwise, the output state of the wrapped plugin is unchanged.\n" 68Otherwise, the output state of the wrapped plugin is unchanged.\n"));
52
53#define DEFAULT_TIMEOUT 9
54
55#include "common.h"
56#include "utils.h"
57#include "popen.h"
58 69
70 printf (_(UT_SUPPORT));
71}
72
59char *command_line; 73char *command_line;
60 74
61int process_arguments (int, char **); 75int process_arguments (int, char **);
62int validate_arguments (void); 76int validate_arguments (void);
63void print_usage (void);
64void print_help (void);
65
66/****************************************************************************** 77/******************************************************************************
67 78
68The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ 79The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
@@ -123,21 +134,21 @@ main (int argc, char **argv)
123 char input_buffer[MAX_INPUT_BUFFER]; 134 char input_buffer[MAX_INPUT_BUFFER];
124 135
125 if (process_arguments (argc, argv) == ERROR) 136 if (process_arguments (argc, argv) == ERROR)
126 usage ("Could not parse arguments\n"); 137 usage (_("Could not parse arguments\n"));
127 138
128 /* Set signal handling and alarm */ 139 /* Set signal handling and alarm */
129 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) 140 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR)
130 terminate (STATE_UNKNOWN, "Cannot catch SIGALRM"); 141 terminate (STATE_UNKNOWN, _("Cannot catch SIGALRM"));
131 142
132 (void) alarm ((unsigned) timeout_interval); 143 (void) alarm ((unsigned) timeout_interval);
133 144
134 child_process = spopen (command_line); 145 child_process = spopen (command_line);
135 if (child_process == NULL) 146 if (child_process == NULL)
136 terminate (STATE_UNKNOWN, "Could not open pipe: %s\n", command_line); 147 terminate (STATE_UNKNOWN, _("Could not open pipe: %s\n"), command_line);
137 148
138 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 149 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
139 if (child_stderr == NULL) { 150 if (child_stderr == NULL) {
140 printf ("Could not open stderr for %s\n", command_line); 151 printf (_("Could not open stderr for %s\n"), command_line);
141 } 152 }
142 153
143 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 154 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
@@ -153,7 +164,7 @@ main (int argc, char **argv)
153 164
154 if (!found) 165 if (!found)
155 terminate (STATE_UNKNOWN,\ 166 terminate (STATE_UNKNOWN,\
156 "%s problem - No data recieved from host\nCMD: %s\n",\ 167 _("%s problem - No data recieved from host\nCMD: %s\n"),\
157 argv[0], command_line); 168 argv[0], command_line);
158 169
159 /* close the pipe */ 170 /* close the pipe */
@@ -176,32 +187,6 @@ main (int argc, char **argv)
176 187
177 188
178 189
179
180void
181print_help (void)
182{
183 print_revision (progname, REVISION);
184 printf
185 ("Copyright (c) %s %s <%s>\n\n%s\n",
186 COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
187 print_usage ();
188 printf
189 ("\nOptions:\n" LONGOPTIONS "\n" "Examples:\n" EXAMPLES "\n"
190 DESCRIPTION "\n", DEFAULT_TIMEOUT);
191 support ();
192}
193
194void
195print_usage (void)
196{
197 printf ("Usage:\n" " %s %s\n"
198 " %s (-h | --help) for detailed help\n"
199 " %s (-V | --version) for version information\n",
200 progname, OPTIONS, progname, progname);
201}
202
203
204
205/****************************************************************************** 190/******************************************************************************
206@@- 191@@-
207<sect3> 192<sect3>
@@ -240,16 +225,16 @@ process_arguments (int argc, char **argv)
240 225
241 switch (c) { 226 switch (c) {
242 case '?': /* help */ 227 case '?': /* help */
243 usage3 ("Unknown argument", optopt); 228 usage3 (_("Unknown argument"), optopt);
244 case 'h': /* help */ 229 case 'h': /* help */
245 print_help (); 230 print_help ();
246 exit (EXIT_SUCCESS); 231 exit (EXIT_SUCCESS);
247 case 'V': /* version */ 232 case 'V': /* version */
248 print_revision (progname, REVISION); 233 print_revision (progname, revision);
249 exit (EXIT_SUCCESS); 234 exit (EXIT_SUCCESS);
250 case 't': /* timeout period */ 235 case 't': /* timeout period */
251 if (!is_integer (optarg)) 236 if (!is_integer (optarg))
252 usage2 ("Timeout Interval must be an integer", optarg); 237 usage2 (_("Timeout Interval must be an integer"), optarg);
253 timeout_interval = atoi (optarg); 238 timeout_interval = atoi (optarg);
254 break; 239 break;
255 } 240 }