summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_by_ssh.c1
-rw-r--r--plugins/check_dig.c115
-rw-r--r--plugins/check_ping.c1
-rw-r--r--plugins/check_time.c124
4 files changed, 102 insertions, 139 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 97c8672f..93f1ead5 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -37,7 +37,6 @@
37#define PROGNAME "check_by_ssh" 37#define PROGNAME "check_by_ssh"
38 38
39int process_arguments (int, char **); 39int process_arguments (int, char **);
40int call_getopt (int, char **);
41int validate_arguments (void); 40int validate_arguments (void);
42void print_help (char *command_name); 41void print_help (char *command_name);
43void print_usage (void); 42void print_usage (void);
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 384b380b..fcd5d0dd 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -1,14 +1,24 @@
1/****************************************************************************** 1/******************************************************************************
2* 2 *
3* check_dig.c 3 * Program: SNMP plugin for Nagios
4* 4 * License: GPL
5* Program: dig plugin for Nagios 5 *
6* License: GPL 6 * License Information:
7* Copyright (c) 2000 7 *
8* 8 * This program is free software; you can redistribute it and/or modify
9* $Id$ 9 * it under the terms of the GNU General Public License as published by
10* 10 * the Free Software Foundation; either version 2 of the License, or
11*****************************************************************************/ 11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
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 *****************************************************************************/
12 22
13#include "config.h" 23#include "config.h"
14#include "common.h" 24#include "common.h"
@@ -16,6 +26,11 @@
16#include "popen.h" 26#include "popen.h"
17 27
18#define PROGNAME "check_dig" 28#define PROGNAME "check_dig"
29#define REVISION "$Revision$"
30#define COPYRIGHT "2000-2002"
31#define AUTHOR "Karl DeBisschop"
32#define EMAIL "karl@debisschop.net"
33#define SUMMARY "Test the DNS service on the specified host using dig\n"
19 34
20int process_arguments (int, char **); 35int process_arguments (int, char **);
21int call_getopt (int, char **); 36int call_getopt (int, char **);
@@ -140,42 +155,6 @@ process_arguments (int argc, char **argv)
140{ 155{
141 int c; 156 int c;
142 157
143 if (argc < 2)
144 return ERROR;
145
146
147 c = 0;
148 while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
149
150 if (is_option (argv[c]))
151 continue;
152
153 if (dns_server == NULL) {
154 if (is_host (argv[c])) {
155 dns_server = argv[c];
156 }
157 else {
158 usage ("Invalid host name");
159 }
160 }
161 }
162
163 if (dns_server == NULL)
164 dns_server = strscpy (NULL, "127.0.0.1");
165
166 return validate_arguments ();
167}
168
169
170
171
172
173
174int
175call_getopt (int argc, char **argv)
176{
177 int c, i = 0;
178
179#ifdef HAVE_GETOPT_H 158#ifdef HAVE_GETOPT_H
180 int option_index = 0; 159 int option_index = 0;
181 static struct option long_options[] = { 160 static struct option long_options[] = {
@@ -188,26 +167,22 @@ call_getopt (int argc, char **argv)
188 }; 167 };
189#endif 168#endif
190 169
170 if (argc < 2)
171 return ERROR;
172
191 while (1) { 173 while (1) {
192#ifdef HAVE_GETOPT_H 174#ifdef HAVE_GETOPT_H
193 c = getopt_long (argc, argv, "+hVvt:l:H:", long_options, &option_index); 175 c = getopt_long (argc, argv, "hVvt:l:H:", long_options, &option_index);
194#else 176#else
195 c = getopt (argc, argv, "+?hVvt:l:H:"); 177 c = getopt (argc, argv, "hVvt:l:H:");
196#endif 178#endif
197 179
198 i++; 180 if (c == -1 || c == EOF)
199
200 if (c == -1 || c == EOF || c == 1)
201 break; 181 break;
202 182
203 switch (c) { 183 switch (c) {
204 case 't': 184 case '?': /* help */
205 case 'l': 185 usage3 ("Unknown argument", optopt);
206 case 'H':
207 i++;
208 }
209
210 switch (c) {
211 case 'H': /* hostname */ 186 case 'H': /* hostname */
212 if (is_host (optarg)) { 187 if (is_host (optarg)) {
213 dns_server = optarg; 188 dns_server = optarg;
@@ -236,11 +211,25 @@ call_getopt (int argc, char **argv)
236 case 'h': /* help */ 211 case 'h': /* help */
237 print_help (); 212 print_help ();
238 exit (STATE_OK); 213 exit (STATE_OK);
239 case '?': /* help */
240 usage ("Invalid argument\n");
241 } 214 }
242 } 215 }
243 return i; 216
217 c = optind;
218 if (dns_server == NULL) {
219 if (c < argc) {
220 if (is_host (argv[c])) {
221 dns_server = argv[c];
222 }
223 else {
224 usage ("Invalid host name");
225 }
226 }
227 else {
228 dns_server = strscpy (NULL, "127.0.0.1");
229 }
230 }
231
232 return validate_arguments ();
244} 233}
245 234
246 235
@@ -262,8 +251,8 @@ print_help (void)
262{ 251{
263 print_revision (PROGNAME, "$Revision$"); 252 print_revision (PROGNAME, "$Revision$");
264 printf 253 printf
265 ("Copyright (c) 2000 Karl DeBisschop\n\n" 254 ("Copyright (c) %s %s <%s>\n\n%s\n",
266 "This plugin use dig to test the DNS service on the specified host.\n\n"); 255 COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
267 print_usage (); 256 print_usage ();
268 printf 257 printf
269 ("\nOptions:\n" 258 ("\nOptions:\n"
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 74aa3b7c..df1d9eb2 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -56,7 +56,6 @@ the contrib area of the downloads section at http://www.nagios.org\n\n"
56#define WARN_DUPLICATES "DUPLICATES FOUND! " 56#define WARN_DUPLICATES "DUPLICATES FOUND! "
57 57
58int process_arguments (int, char **); 58int process_arguments (int, char **);
59int call_getopt (int, char **);
60int get_threshold (char *, float *, int *); 59int get_threshold (char *, float *, int *);
61int validate_arguments (void); 60int validate_arguments (void);
62int run_ping (char *); 61int run_ping (char *);
diff --git a/plugins/check_time.c b/plugins/check_time.c
index 86c414e2..c3817805 100644
--- a/plugins/check_time.c
+++ b/plugins/check_time.c
@@ -40,6 +40,11 @@
40#include "utils.h" 40#include "utils.h"
41 41
42#define PROGNAME "check_time" 42#define PROGNAME "check_time"
43#define REVISION "$Revision$"
44#define COPYRIGHT "1999-2002"
45#define AUTHOR "Ethan Galstad"
46#define EMAIL "nagios@nagios.org"
47#define SUMMARY "Check time on the specified host.\n"
43 48
44#define TIME_PORT 37 49#define TIME_PORT 37
45#define UNIX_EPOCH 2208988800UL 50#define UNIX_EPOCH 2208988800UL
@@ -59,7 +64,6 @@ char *server_address = NULL;
59 64
60 65
61int process_arguments (int, char **); 66int process_arguments (int, char **);
62int call_getopt (int, char **);
63void print_usage (void); 67void print_usage (void);
64void print_help (void); 68void print_help (void);
65 69
@@ -93,7 +97,7 @@ main (int argc, char **argv)
93 server_address, server_port); 97 server_address, server_port);
94 } 98 }
95 99
96 /* watch for the FTP connection string */ 100 /* watch for the connection string */
97 result = recv (sd, &raw_server_time, sizeof (raw_server_time), 0); 101 result = recv (sd, &raw_server_time, sizeof (raw_server_time), 0);
98 102
99 /* close the connection */ 103 /* close the connection */
@@ -154,52 +158,6 @@ process_arguments (int argc, char **argv)
154{ 158{
155 int c; 159 int c;
156 160
157 if (argc < 2)
158 usage ("\n");
159
160 for (c = 1; c < argc; c++) {
161 if (strcmp ("-to", argv[c]) == 0)
162 strcpy (argv[c], "-t");
163 else if (strcmp ("-wd", argv[c]) == 0)
164 strcpy (argv[c], "-w");
165 else if (strcmp ("-cd", argv[c]) == 0)
166 strcpy (argv[c], "-c");
167 else if (strcmp ("-wt", argv[c]) == 0)
168 strcpy (argv[c], "-W");
169 else if (strcmp ("-ct", argv[c]) == 0)
170 strcpy (argv[c], "-C");
171 }
172
173 c = 0;
174 while ((c += call_getopt (argc - c, &argv[c])) < argc) {
175
176 if (is_option (argv[c]))
177 continue;
178
179 if (server_address == NULL) {
180 if (argc > c) {
181 if (is_host (argv[c]) == FALSE)
182 usage ("Invalid host name/address\n");
183 server_address = argv[c];
184 }
185 else {
186 usage ("Host name was not supplied\n");
187 }
188 }
189 }
190
191 return OK;
192}
193
194
195
196
197
198int
199call_getopt (int argc, char **argv)
200{
201 int c, i = 0;
202
203#ifdef HAVE_GETOPT_H 161#ifdef HAVE_GETOPT_H
204 int option_index = 0; 162 int option_index = 0;
205 static struct option long_options[] = { 163 static struct option long_options[] = {
@@ -216,41 +174,42 @@ call_getopt (int argc, char **argv)
216 }; 174 };
217#endif 175#endif
218 176
177 if (argc < 2)
178 usage ("\n");
179
180 for (c = 1; c < argc; c++) {
181 if (strcmp ("-to", argv[c]) == 0)
182 strcpy (argv[c], "-t");
183 else if (strcmp ("-wd", argv[c]) == 0)
184 strcpy (argv[c], "-w");
185 else if (strcmp ("-cd", argv[c]) == 0)
186 strcpy (argv[c], "-c");
187 else if (strcmp ("-wt", argv[c]) == 0)
188 strcpy (argv[c], "-W");
189 else if (strcmp ("-ct", argv[c]) == 0)
190 strcpy (argv[c], "-C");
191 }
192
219 while (1) { 193 while (1) {
220#ifdef HAVE_GETOPT_H 194#ifdef HAVE_GETOPT_H
221 c = 195 c =
222 getopt_long (argc, argv, "+hVH:w:c:W:C:p:t:", long_options, 196 getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", long_options,
223 &option_index); 197 &option_index);
224#else 198#else
225 c = getopt (argc, argv, "+hVH:w:c:W:C:p:t:"); 199 c = getopt (argc, argv, "hVH:w:c:W:C:p:t:");
226#endif 200#endif
227 201
228 i++; 202 if (c == -1 || c == EOF)
229
230 if (c == -1 || c == EOF || c == 1)
231 break; 203 break;
232 204
233 switch (c) { 205 switch (c) {
234 case 'H':
235 case 'w':
236 case 'c':
237 case 'W':
238 case 'C':
239 case 'p':
240 case 't':
241 i++;
242 }
243
244 switch (c) {
245 case '?': /* print short usage statement if args not parsable */ 206 case '?': /* print short usage statement if args not parsable */
246 printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); 207 usage3 ("Unknown argument", optopt);
247 print_usage ();
248 exit (STATE_UNKNOWN);
249 case 'h': /* help */ 208 case 'h': /* help */
250 print_help (); 209 print_help ();
251 exit (STATE_OK); 210 exit (STATE_OK);
252 case 'V': /* version */ 211 case 'V': /* version */
253 print_revision (my_basename (argv[0]), "$Revision$"); 212 print_revision (PROGNAME, REVISION);
254 exit (STATE_OK); 213 exit (STATE_OK);
255 case 'H': /* hostname */ 214 case 'H': /* hostname */
256 if (is_host (optarg) == FALSE) 215 if (is_host (optarg) == FALSE)
@@ -318,7 +277,20 @@ call_getopt (int argc, char **argv)
318 break; 277 break;
319 } 278 }
320 } 279 }
321 return i; 280
281 c = optind;
282 if (server_address == NULL) {
283 if (argc > c) {
284 if (is_host (argv[c]) == FALSE)
285 usage ("Invalid host name/address\n");
286 server_address = argv[c];
287 }
288 else {
289 usage ("Host name was not supplied\n");
290 }
291 }
292
293 return OK;
322} 294}
323 295
324 296
@@ -329,8 +301,12 @@ void
329print_usage (void) 301print_usage (void)
330{ 302{
331 printf 303 printf
332 ("Usage: check_time -H <host_address> [-p port] [-w variance] [-c variance]\n" 304 ("Usage:\n"
333 " [-W connect_time] [-C connect_time] [-t timeout]\n"); 305 " %s -H <host_address> [-p port] [-w variance] [-c variance]\n"
306 " [-W connect_time] [-C connect_time] [-t timeout]\n"
307 " %s (-h | --help) for detailed help\n"
308 " %s (-V | --version) for version information\n",
309 PROGNAME, PROGNAME, PROGNAME);
334} 310}
335 311
336 312
@@ -340,10 +316,10 @@ print_usage (void)
340void 316void
341print_help (void) 317print_help (void)
342{ 318{
343 print_revision (PROGNAME, "$Revision$"); 319 print_revision (PROGNAME, REVISION);
344 printf 320 printf
345 ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" 321 ("Copyright (c) %s %s <%s>\n\n%s\n",
346 "This plugin connects to a time port on the specified host.\n\n"); 322 COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
347 print_usage (); 323 print_usage ();
348 printf 324 printf
349 ("Options:\n" 325 ("Options:\n"