summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2004-02-21 05:37:34 +0000
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2004-02-21 05:37:34 +0000
commitb8c407e0f5df94186363ac16c610bcef85745aa5 (patch)
tree9359f233a2ec954369540547f99d133a51792bf1
parenta2ff62ca066a00c14855e8df4558044ffdd49c30 (diff)
downloadmonitoring-plugins-b8c407e0f5df94186363ac16c610bcef85745aa5.tar.gz
add option to ignore a specified number of lines on stderr
(to suppress a login banner) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@823 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/check_by_ssh.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 560ae0c6..0bce902f 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -33,6 +33,7 @@ void print_usage (void);
33 33
34int commands = 0; 34int commands = 0;
35int services = 0; 35int services = 0;
36int skip_lines = 0;
36char *remotecmd = NULL; 37char *remotecmd = NULL;
37char *comm = NULL; 38char *comm = NULL;
38char *hostname = NULL; 39char *hostname = NULL;
@@ -101,15 +102,20 @@ main (int argc, char **argv)
101 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) 102 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
102 asprintf (&result_text, "%s%s", result_text, input_buffer); 103 asprintf (&result_text, "%s%s", result_text, input_buffer);
103 104
104
105 /* WARNING if output found on stderr */ 105 /* WARNING if output found on stderr */
106 if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { 106 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
107 printf ("%s\n", input_buffer); 107 if (skip_lines > 0) {
108 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) 108 if (input_buffer[strlen(input_buffer)-1] == '\n') {
109 printf ("%s\n", input_buffer); 109 skip_lines--;
110 return STATE_WARNING; 110 }
111 } else {
112 printf ("%s", input_buffer);
113 result = STATE_WARNING;
114 }
111 } 115 }
112 (void) fclose (child_stderr); 116 (void) fclose (child_stderr);
117 if (result == STATE_WARNING)
118 return result;
113 119
114 120
115 /* close the pipe */ 121 /* close the pipe */
@@ -189,6 +195,7 @@ process_arguments (int argc, char **argv)
189 {"user", required_argument, 0, 'u'}, 195 {"user", required_argument, 0, 'u'},
190 {"logname", required_argument, 0, 'l'}, 196 {"logname", required_argument, 0, 'l'},
191 {"command", required_argument, 0, 'C'}, 197 {"command", required_argument, 0, 'C'},
198 {"skip", required_argument, 0, 'S'},
192 {"proto1", no_argument, 0, '1'}, 199 {"proto1", no_argument, 0, '1'},
193 {"proto2", no_argument, 0, '2'}, 200 {"proto2", no_argument, 0, '2'},
194 {"use-ipv4", no_argument, 0, '4'}, 201 {"use-ipv4", no_argument, 0, '4'},
@@ -204,7 +211,7 @@ process_arguments (int argc, char **argv)
204 strcpy (argv[c], "-t"); 211 strcpy (argv[c], "-t");
205 212
206 while (1) { 213 while (1) {
207 c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", longopts, 214 c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:S:n:s:", longopts,
208 &option); 215 &option);
209 216
210 if (c == -1 || c == EOF) 217 if (c == -1 || c == EOF)
@@ -275,6 +282,13 @@ process_arguments (int argc, char **argv)
275 if (commands > 1) 282 if (commands > 1)
276 asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 283 asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
277 asprintf (&remotecmd, "%s%s", remotecmd, optarg); 284 asprintf (&remotecmd, "%s%s", remotecmd, optarg);
285 break;
286 case 'S': /* Skip n lines in the output to ignore system banner */
287 if (!is_integer (optarg))
288 usage2 (_("skip lines must be an integer"), optarg);
289 else
290 skip_lines = atoi (optarg);
291 break;
278 } 292 }
279 } 293 }
280 294
@@ -353,6 +367,8 @@ print_help (void)
353 tell ssh to use Protocol 1\n\ 367 tell ssh to use Protocol 1\n\
354 -2, --proto2\n\ 368 -2, --proto2\n\
355 tell ssh to use Protocol 2\n\ 369 tell ssh to use Protocol 2\n\
370 -S, --skiplines=n\n\
371 Ignore first n lines on STDERR (to suppress a logon banner)\n\
356 -f\n\ 372 -f\n\
357 tells ssh to fork rather than create a tty\n")); 373 tells ssh to fork rather than create a tty\n"));
358 374