summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_by_ssh.c2
-rw-r--r--plugins/check_dig.c141
-rw-r--r--plugins/check_disk.c49
-rw-r--r--plugins/check_snmp.c2
-rw-r--r--plugins/utils.c38
-rw-r--r--plugins/utils.h10
6 files changed, 113 insertions, 129 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 8527b72..59e8ea0 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -291,7 +291,7 @@ process_arguments (int argc, char **argv)
291 } 291 }
292 292
293 if (commands > 1) 293 if (commands > 1)
294 remotecmd = strscat (remotecmd, ";echo STATUS CODE: $?;"); 294 asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
295 295
296 if (remotecmd == NULL || strlen (remotecmd) <= 1) 296 if (remotecmd == NULL || strlen (remotecmd) <= 1)
297 usage (_("No remotecmd\n")); 297 usage (_("No remotecmd\n"));
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 3d82298..7c39a24 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -1,22 +1,21 @@
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 18
19#include "config.h"
20#include "common.h" 19#include "common.h"
21#include "netutils.h" 20#include "netutils.h"
22#include "utils.h" 21#include "utils.h"
@@ -36,50 +35,6 @@ enum {
36 DEFAULT_PORT = 53 35 DEFAULT_PORT = 53
37}; 36};
38 37
39void
40print_usage (void)
41{
42 printf (_("\
43Usage: %s -H host -l lookup [-p <server port>] [-w <warning interval>]\n\
44 [-c <critical interval>] [-t <timeout>] [-v]\n"),
45 progname);
46 printf (" %s (-h|--help)\n", progname);
47 printf (" %s (-V|--version)\n", progname);
48}
49
50void
51print_help (void)
52{
53 char *myport;
54
55 asprintf (&myport, "%d", DEFAULT_PORT);
56
57 print_revision (progname, revision);
58
59 printf (_(COPYRIGHT), copyright, email);
60
61 printf (_("Test the DNS service on the specified host using dig\n\n"));
62
63 print_usage ();
64
65 printf (_(UT_HELP_VRSN));
66
67 printf (_(UT_HOST_PORT), 'P', myport);
68
69 printf (_("\
70 -l, --lookup=STRING\n\
71 machine name to lookup\n"));
72
73 printf (_(UT_WARN_CRIT));
74
75 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
76
77 printf (_(UT_VERBOSE));
78
79 support ();
80}
81
82
83char *query_address = NULL; 38char *query_address = NULL;
84char *dns_server = NULL; 39char *dns_server = NULL;
85int verbose = FALSE; 40int verbose = FALSE;
@@ -88,14 +43,20 @@ int warning_interval = -1;
88int critical_interval = -1; 43int critical_interval = -1;
89 44
90 45
46
47
48
49
91int 50int
92main (int argc, char **argv) 51main (int argc, char **argv)
93{ 52{
94 char input_buffer[MAX_INPUT_BUFFER]; 53 char input_buffer[MAX_INPUT_BUFFER];
95 char *command_line = NULL; 54 char *command_line;
96 char *output = ""; 55 char *output;
97 int result = STATE_UNKNOWN; 56 int result = STATE_UNKNOWN;
98 57
58 output = strdup ("");
59
99 /* Set signal handling and alarm */ 60 /* Set signal handling and alarm */
100 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) 61 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR)
101 usage (_("Cannot catch SIGALRM\n")); 62 usage (_("Cannot catch SIGALRM\n"));
@@ -188,6 +149,11 @@ main (int argc, char **argv)
188 return result; 149 return result;
189} 150}
190 151
152
153
154
155
156
191/* process command-line arguments */ 157/* process command-line arguments */
192int 158int
193process_arguments (int argc, char **argv) 159process_arguments (int argc, char **argv)
@@ -298,4 +264,55 @@ validate_arguments (void)
298{ 264{
299 return OK; 265 return OK;
300} 266}
267
268
269
270
271
272
301 273
274void
275print_help (void)
276{
277 char *myport;
278
279 asprintf (&myport, "%d", DEFAULT_PORT);
280
281 print_revision (progname, revision);
282
283 printf (_(COPYRIGHT), copyright, email);
284
285 printf (_("Test the DNS service on the specified host using dig\n\n"));
286
287 print_usage ();
288
289 printf (_(UT_HELP_VRSN));
290
291 printf (_(UT_HOST_PORT), 'P', myport);
292
293 printf (_("\
294 -l, --lookup=STRING\n\
295 machine name to lookup\n"));
296
297 printf (_(UT_WARN_CRIT));
298
299 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
300
301 printf (_(UT_VERBOSE));
302
303 support ();
304}
305
306
307
308
309void
310print_usage (void)
311{
312 printf (_("\
313Usage: %s -H host -l lookup [-p <server port>] [-w <warning interval>]\n\
314 [-c <critical interval>] [-t <timeout>] [-v]\n"),
315 progname);
316 printf (" %s (-h|--help)\n", progname);
317 printf (" %s (-V|--version)\n", progname);
318}
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 7feb5a5..7bed4d4 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -1,19 +1,19 @@
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 18
19const char *progname = "check_disk"; 19const char *progname = "check_disk";
@@ -111,7 +111,7 @@ enum
111int process_arguments (int, char **); 111int process_arguments (int, char **);
112void print_path (char *mypath); 112void print_path (char *mypath);
113int validate_arguments (uintmax_t, uintmax_t, double, double, char *); 113int validate_arguments (uintmax_t, uintmax_t, double, double, char *);
114int check_disk (int usp, uintmax_t free_disk); 114int check_disk (double usp, uintmax_t free_disk);
115int walk_name_list (struct name_list *list, const char *name); 115int walk_name_list (struct name_list *list, const char *name);
116void print_help (void); 116void print_help (void);
117void print_usage (void); 117void print_usage (void);
@@ -120,9 +120,9 @@ uintmax_t w_df = 0;
120uintmax_t c_df = 0; 120uintmax_t c_df = 0;
121double w_dfp = -1.0; 121double w_dfp = -1.0;
122double c_dfp = -1.0; 122double c_dfp = -1.0;
123char *path = ""; 123char *path;
124char *exclude_device = ""; 124char *exclude_device;
125char *units = NULL; 125char *units;
126uintmax_t mult = 1024 * 1024; 126uintmax_t mult = 1024 * 1024;
127int verbose = 0; 127int verbose = 0;
128int erronly = FALSE; 128int erronly = FALSE;
@@ -140,14 +140,17 @@ main (int argc, char **argv)
140 int result = STATE_UNKNOWN; 140 int result = STATE_UNKNOWN;
141 int disk_result = STATE_UNKNOWN; 141 int disk_result = STATE_UNKNOWN;
142 char file_system[MAX_INPUT_BUFFER]; 142 char file_system[MAX_INPUT_BUFFER];
143 char *output = ""; 143 char *output;
144 char *details = ""; 144 char *details;
145 float free_space, free_space_pct, total_space; 145 float free_space, free_space_pct, total_space;
146 146
147 struct mount_entry *me; 147 struct mount_entry *me;
148 struct fs_usage fsp; 148 struct fs_usage fsp;
149 struct name_list *temp_list; 149 struct name_list *temp_list;
150 150
151 output = strdup ("");
152 details = strdup ("");
153
151 mount_list = read_filesystem_list (0); 154 mount_list = read_filesystem_list (0);
152 155
153 if (process_arguments (argc, argv) != OK) 156 if (process_arguments (argc, argv) != OK)
@@ -414,7 +417,7 @@ process_arguments (int argc, char **argv)
414 if (c_dfp < 0 && argc > c && is_intnonneg (argv[c])) 417 if (c_dfp < 0 && argc > c && is_intnonneg (argv[c]))
415 c_dfp = (100.0 - atof (argv[c++])); 418 c_dfp = (100.0 - atof (argv[c++]));
416 419
417 if (argc > c && strlen (path) == 0) { 420 if (argc > c && path == NULL) {
418 se = (struct name_list *) malloc (sizeof (struct name_list)); 421 se = (struct name_list *) malloc (sizeof (struct name_list));
419 se->name = strdup (argv[c++]); 422 se->name = strdup (argv[c++]);
420 se->name_next = NULL; 423 se->name_next = NULL;
@@ -482,7 +485,7 @@ INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greate
482 485
483 486
484int 487int
485check_disk (int usp, uintmax_t free_disk) 488check_disk (double usp, uintmax_t free_disk)
486{ 489{
487 int result = STATE_UNKNOWN; 490 int result = STATE_UNKNOWN;
488 /* check the percent used space against thresholds */ 491 /* check the percent used space against thresholds */
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index dcb6e68..e22d8a0 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -201,7 +201,7 @@ main (int argc, char **argv)
201 ptr = strpbrk (ptr, "\n"); 201 ptr = strpbrk (ptr, "\n");
202 } 202 }
203 if (ptr && strstr (ptr, delimiter) == NULL) { 203 if (ptr && strstr (ptr, delimiter) == NULL) {
204 response = strscat (response, ptr); 204 asprintf (&response, "%s%s", response, ptr);
205 ptr = NULL; 205 ptr = NULL;
206 } 206 }
207 } 207 }
diff --git a/plugins/utils.c b/plugins/utils.c
index 959541b..aed03c4 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -67,7 +67,7 @@ void usage2(char *msg, char *arg)
67} 67}
68 68
69void 69void
70usage3 (char *msg, char arg) 70usage3 (char *msg, int arg)
71{ 71{
72 printf ("%s: %s - %c\n", progname, msg, arg); 72 printf ("%s: %s - %c\n", progname, msg, arg);
73 print_usage(); 73 print_usage();
@@ -111,7 +111,7 @@ For more information about these matters, see the file named COPYING.\n"));
111 111
112} 112}
113 113
114char * 114const char *
115state_text (int result) 115state_text (int result)
116{ 116{
117 switch (result) { 117 switch (result) {
@@ -338,40 +338,6 @@ strscpy (char *dest, const char *src)
338 338
339/****************************************************************************** 339/******************************************************************************
340 * 340 *
341 * Concatenates one string to the end of another
342 *
343 * Given a pointer destination string, which may or may not already
344 * hold some text, and a source string with additional text (possibly
345 * NULL or empty), returns a pointer to a string that is the first
346 * string with the second concatenated to it. Uses realloc to free
347 * memory held by the dest argument if new storage space is required.
348 *
349 * Example:
350 *
351 * char *str=NULL;
352 * str = strscpy("This is a line of text with no trailing newline");
353 * str = strscat(str,"\n");
354 *
355 *****************************************************************************/
356
357char *
358strscat (char *dest, const char *src)
359{
360
361 if (dest == NULL)
362 return src;
363 if (src != NULL)
364 asprintf (&dest, "%s%s", dest, src);
365
366 return dest;
367}
368
369
370
371
372
373/******************************************************************************
374 *
375 * Returns a pointer to the next line of a multiline string buffer 341 * Returns a pointer to the next line of a multiline string buffer
376 * 342 *
377 * Given a pointer string, find the text following the next sequence 343 * Given a pointer string, find the text following the next sequence
diff --git a/plugins/utils.h b/plugins/utils.h
index 9dc2654..a852e86 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -22,10 +22,10 @@ void die (int result, const char *fmt, ...) __attribute__((noreturn));
22 22
23#ifdef LOCAL_TIMEOUT_ALARM_HANDLER 23#ifdef LOCAL_TIMEOUT_ALARM_HANDLER
24extern unsigned int timeout_interval; 24extern unsigned int timeout_interval;
25RETSIGTYPE timeout_alarm_handler (int) __attribute__((noreturn)); 25RETSIGTYPE timeout_alarm_handler (int);
26#else 26#else
27unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; 27unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
28extern RETSIGTYPE timeout_alarm_handler (int) __attribute__((noreturn)); 28extern RETSIGTYPE timeout_alarm_handler (int);
29#endif 29#endif
30 30
31time_t start_time, end_time; 31time_t start_time, end_time;
@@ -64,9 +64,7 @@ double delta_time (struct timeval tv);
64 64
65void strip (char *buffer); 65void strip (char *buffer);
66char *strscpy (char *dest, const char *src); 66char *strscpy (char *dest, const char *src);
67char *strscat (char *dest, const char *src);
68char *strnl (char *str); 67char *strnl (char *str);
69char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */
70char *strpcpy (char *dest, const char *src, const char *str); 68char *strpcpy (char *dest, const char *src, const char *str);
71char *strpcat (char *dest, const char *src, const char *str); 69char *strpcat (char *dest, const char *src, const char *str);
72 70
@@ -74,9 +72,9 @@ int max_state (int a, int b);
74 72
75void usage (char *msg) __attribute__((noreturn)); 73void usage (char *msg) __attribute__((noreturn));
76void usage2(char *msg, char *arg) __attribute__((noreturn)); 74void usage2(char *msg, char *arg) __attribute__((noreturn));
77void usage3(char *msg, char arg) __attribute__((noreturn)); 75void usage3(char *msg, int arg) __attribute__((noreturn));
78 76
79char *state_text (int result); 77const char *state_text (int result);
80 78
81#define max(a,b) (((a)>(b))?(a):(b)) 79#define max(a,b) (((a)>(b))?(a):(b))
82 80