summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_by_ssh.c481
1 files changed, 227 insertions, 254 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 2a23b397..35aa1b8c 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -1,30 +1,30 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_by_ssh plugin 3 * Monitoring check_by_ssh plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 2000-2008 Monitoring Plugins Development Team 6 * Copyright (c) 2000-2008 Monitoring Plugins Development Team
7* 7 *
8* Description: 8 * Description:
9* 9 *
10* This file contains the check_by_ssh plugin 10 * This file contains the check_by_ssh plugin
11* 11 *
12* 12 *
13* This program is free software: you can redistribute it and/or modify 13 * This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15 * the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16 * (at your option) any later version.
17* 17 *
18* This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21 * GNU General Public License for more details.
22* 22 *
23* You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25 *
26* 26 *
27*****************************************************************************/ 27 *****************************************************************************/
28 28
29const char *progname = "check_by_ssh"; 29const char *progname = "check_by_ssh";
30const char *copyright = "2000-2008"; 30const char *copyright = "2000-2008";
@@ -36,14 +36,14 @@ const char *email = "devel@monitoring-plugins.org";
36#include "utils_cmd.h" 36#include "utils_cmd.h"
37 37
38#ifndef NP_MAXARGS 38#ifndef NP_MAXARGS
39#define NP_MAXARGS 1024 39# define NP_MAXARGS 1024
40#endif 40#endif
41 41
42int process_arguments (int, char **); 42int process_arguments(int, char **);
43int validate_arguments (void); 43int validate_arguments(void);
44void comm_append (const char *); 44void comm_append(const char *);
45void print_help (void); 45void print_help(void);
46void print_usage (void); 46void print_usage(void);
47 47
48unsigned int commands = 0; 48unsigned int commands = 0;
49unsigned int services = 0; 49unsigned int services = 0;
@@ -61,9 +61,7 @@ char **service;
61bool passive = false; 61bool passive = false;
62bool verbose = false; 62bool verbose = false;
63 63
64int 64int main(int argc, char **argv) {
65main (int argc, char **argv)
66{
67 65
68 char *status_text; 66 char *status_text;
69 int cresult; 67 int cresult;
@@ -75,43 +73,42 @@ main (int argc, char **argv)
75 remotecmd = ""; 73 remotecmd = "";
76 comm_append(SSH_COMMAND); 74 comm_append(SSH_COMMAND);
77 75
78 setlocale (LC_ALL, ""); 76 setlocale(LC_ALL, "");
79 bindtextdomain (PACKAGE, LOCALEDIR); 77 bindtextdomain(PACKAGE, LOCALEDIR);
80 textdomain (PACKAGE); 78 textdomain(PACKAGE);
81 79
82 /* Parse extra opts if any */ 80 /* Parse extra opts if any */
83 argv=np_extra_opts (&argc, argv, progname); 81 argv = np_extra_opts(&argc, argv, progname);
84 82
85 /* process arguments */ 83 /* process arguments */
86 if (process_arguments (argc, argv) == ERROR) 84 if (process_arguments(argc, argv) == ERROR)
87 usage_va(_("Could not parse arguments")); 85 usage_va(_("Could not parse arguments"));
88 86
89 /* Set signal handling and alarm timeout */ 87 /* Set signal handling and alarm timeout */
90 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { 88 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) {
91 usage_va(_("Cannot catch SIGALRM")); 89 usage_va(_("Cannot catch SIGALRM"));
92 } 90 }
93 alarm (timeout_interval); 91 alarm(timeout_interval);
94 92
95 /* run the command */ 93 /* run the command */
96 if (verbose) { 94 if (verbose) {
97 printf ("Command: %s\n", commargv[0]); 95 printf("Command: %s\n", commargv[0]);
98 for (int i = 1; i < commargc; i++) 96 for (int i = 1; i < commargc; i++)
99 printf ("Argument %i: %s\n", i, commargv[i]); 97 printf("Argument %i: %s\n", i, commargv[i]);
100 } 98 }
101 99
102 result = cmd_run_array (commargv, &chld_out, &chld_err, 0); 100 result = cmd_run_array(commargv, &chld_out, &chld_err, 0);
103 101
104 /* SSH returns 255 if connection attempt fails; include the first line of error output */ 102 /* SSH returns 255 if connection attempt fails; include the first line of error output */
105 if (result == 255 && unknown_timeout) { 103 if (result == 255 && unknown_timeout) {
106 printf (_("SSH connection failed: %s\n"), 104 printf(_("SSH connection failed: %s\n"), chld_err.lines > 0 ? chld_err.line[0] : "(no error output)");
107 chld_err.lines > 0 ? chld_err.line[0] : "(no error output)");
108 return STATE_UNKNOWN; 105 return STATE_UNKNOWN;
109 } 106 }
110 107
111 if (verbose) { 108 if (verbose) {
112 for(size_t i = 0; i < chld_out.lines; i++) 109 for (size_t i = 0; i < chld_out.lines; i++)
113 printf("stdout: %s\n", chld_out.line[i]); 110 printf("stdout: %s\n", chld_out.line[i]);
114 for(size_t i = 0; i < chld_err.lines; i++) 111 for (size_t i = 0; i < chld_err.lines; i++)
115 printf("stderr: %s\n", chld_err.line[i]); 112 printf("stderr: %s\n", chld_err.line[i]);
116 } 113 }
117 114
@@ -121,10 +118,9 @@ main (int argc, char **argv)
121 skip_stderr = chld_err.lines; 118 skip_stderr = chld_err.lines;
122 119
123 /* UNKNOWN or worse if (non-skipped) output found on stderr */ 120 /* UNKNOWN or worse if (non-skipped) output found on stderr */
124 if(chld_err.lines > (size_t)skip_stderr) { 121 if (chld_err.lines > (size_t)skip_stderr) {
125 printf (_("Remote command execution failed: %s\n"), 122 printf(_("Remote command execution failed: %s\n"), chld_err.line[skip_stderr]);
126 chld_err.line[skip_stderr]); 123 if (warn_on_stderr)
127 if ( warn_on_stderr )
128 return max_state_alt(result, STATE_WARNING); 124 return max_state_alt(result, STATE_WARNING);
129 else 125 else
130 return max_state_alt(result, STATE_UNKNOWN); 126 return max_state_alt(result, STATE_UNKNOWN);
@@ -132,144 +128,134 @@ main (int argc, char **argv)
132 128
133 /* this is simple if we're not supposed to be passive. 129 /* this is simple if we're not supposed to be passive.
134 * Wrap up quickly and keep the tricks below */ 130 * Wrap up quickly and keep the tricks below */
135 if(!passive) { 131 if (!passive) {
136 if (chld_out.lines > (size_t)skip_stdout) 132 if (chld_out.lines > (size_t)skip_stdout)
137 for (size_t i = skip_stdout; i < chld_out.lines; i++) 133 for (size_t i = skip_stdout; i < chld_out.lines; i++)
138 puts (chld_out.line[i]); 134 puts(chld_out.line[i]);
139 else 135 else
140 printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), 136 printf(_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), state_text(result), remotecmd, result);
141 state_text(result), remotecmd, result); 137 return result; /* return error status from remote command */
142 return result; /* return error status from remote command */
143 } 138 }
144 139
145
146 /* 140 /*
147 * Passive mode 141 * Passive mode
148 */ 142 */
149 143
150 /* process output */ 144 /* process output */
151 if (!(fp = fopen (outputfile, "a"))) { 145 if (!(fp = fopen(outputfile, "a"))) {
152 printf (_("SSH WARNING: could not open %s\n"), outputfile); 146 printf(_("SSH WARNING: could not open %s\n"), outputfile);
153 exit (STATE_UNKNOWN); 147 exit(STATE_UNKNOWN);
154 } 148 }
155 149
156 local_time = time (NULL); 150 local_time = time(NULL);
157 commands = 0; 151 commands = 0;
158 for(size_t i = skip_stdout; i < chld_out.lines; i++) { 152 for (size_t i = skip_stdout; i < chld_out.lines; i++) {
159 status_text = chld_out.line[i++]; 153 status_text = chld_out.line[i++];
160 if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL) 154 if (i == chld_out.lines || strstr(chld_out.line[i], "STATUS CODE: ") == NULL)
161 die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname); 155 die(STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
162 156
163 if (service[commands] && status_text 157 if (service[commands] && status_text && sscanf(chld_out.line[i], "STATUS CODE: %d", &cresult) == 1) {
164 && sscanf (chld_out.line[i], "STATUS CODE: %d", &cresult) == 1) 158 fprintf(fp, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, host_shortname, service[commands++], cresult,
165 { 159 status_text);
166 fprintf (fp, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
167 (int) local_time, host_shortname, service[commands++],
168 cresult, status_text);
169 } 160 }
170 } 161 }
171 162
172 /* Multiple commands and passive checking should always return OK */ 163 /* Multiple commands and passive checking should always return OK */
173 return result; 164 return result;
174} 165}
175 166
176/* process command-line arguments */ 167/* process command-line arguments */
177int 168int process_arguments(int argc, char **argv) {
178process_arguments (int argc, char **argv)
179{
180 int c; 169 int c;
181 char *p1, *p2; 170 char *p1, *p2;
182 171
183 int option = 0; 172 int option = 0;
184 static struct option longopts[] = { 173 static struct option longopts[] = {{"version", no_argument, 0, 'V'},
185 {"version", no_argument, 0, 'V'}, 174 {"help", no_argument, 0, 'h'},
186 {"help", no_argument, 0, 'h'}, 175 {"verbose", no_argument, 0, 'v'},
187 {"verbose", no_argument, 0, 'v'}, 176 {"fork", no_argument, 0, 'f'},
188 {"fork", no_argument, 0, 'f'}, 177 {"timeout", required_argument, 0, 't'},
189 {"timeout", required_argument, 0, 't'}, 178 {"unknown-timeout", no_argument, 0, 'U'},
190 {"unknown-timeout", no_argument, 0, 'U'}, 179 {"host", required_argument, 0, 'H'}, /* backward compatibility */
191 {"host", required_argument, 0, 'H'}, /* backward compatibility */ 180 {"hostname", required_argument, 0, 'H'},
192 {"hostname", required_argument, 0, 'H'}, 181 {"port", required_argument, 0, 'p'},
193 {"port", required_argument,0,'p'}, 182 {"output", required_argument, 0, 'O'},
194 {"output", required_argument, 0, 'O'}, 183 {"name", required_argument, 0, 'n'},
195 {"name", required_argument, 0, 'n'}, 184 {"services", required_argument, 0, 's'},
196 {"services", required_argument, 0, 's'}, 185 {"identity", required_argument, 0, 'i'},
197 {"identity", required_argument, 0, 'i'}, 186 {"user", required_argument, 0, 'u'},
198 {"user", required_argument, 0, 'u'}, 187 {"logname", required_argument, 0, 'l'},
199 {"logname", required_argument, 0, 'l'}, 188 {"command", required_argument, 0, 'C'},
200 {"command", required_argument, 0, 'C'}, 189 {"skip", optional_argument, 0, 'S'}, /* backwards compatibility */
201 {"skip", optional_argument, 0, 'S'}, /* backwards compatibility */ 190 {"skip-stdout", optional_argument, 0, 'S'},
202 {"skip-stdout", optional_argument, 0, 'S'}, 191 {"skip-stderr", optional_argument, 0, 'E'},
203 {"skip-stderr", optional_argument, 0, 'E'}, 192 {"warn-on-stderr", no_argument, 0, 'W'},
204 {"warn-on-stderr", no_argument, 0, 'W'}, 193 {"proto1", no_argument, 0, '1'},
205 {"proto1", no_argument, 0, '1'}, 194 {"proto2", no_argument, 0, '2'},
206 {"proto2", no_argument, 0, '2'}, 195 {"use-ipv4", no_argument, 0, '4'},
207 {"use-ipv4", no_argument, 0, '4'}, 196 {"use-ipv6", no_argument, 0, '6'},
208 {"use-ipv6", no_argument, 0, '6'}, 197 {"ssh-option", required_argument, 0, 'o'},
209 {"ssh-option", required_argument, 0, 'o'}, 198 {"quiet", no_argument, 0, 'q'},
210 {"quiet", no_argument, 0, 'q'}, 199 {"configfile", optional_argument, 0, 'F'},
211 {"configfile", optional_argument, 0, 'F'}, 200 {0, 0, 0, 0}};
212 {0, 0, 0, 0}
213 };
214 201
215 if (argc < 2) 202 if (argc < 2)
216 return ERROR; 203 return ERROR;
217 204
218 for (c = 1; c < argc; c++) 205 for (c = 1; c < argc; c++)
219 if (strcmp ("-to", argv[c]) == 0) 206 if (strcmp("-to", argv[c]) == 0)
220 strcpy (argv[c], "-t"); 207 strcpy(argv[c], "-t");
221 208
222 while (1) { 209 while (1) {
223 c = getopt_long (argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, 210 c = getopt_long(argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, &option);
224 &option);
225 211
226 if (c == -1 || c == EOF) 212 if (c == -1 || c == EOF)
227 break; 213 break;
228 214
229 switch (c) { 215 switch (c) {
230 case 'V': /* version */ 216 case 'V': /* version */
231 print_revision (progname, NP_VERSION); 217 print_revision(progname, NP_VERSION);
232 exit (STATE_UNKNOWN); 218 exit(STATE_UNKNOWN);
233 case 'h': /* help */ 219 case 'h': /* help */
234 print_help (); 220 print_help();
235 exit (STATE_UNKNOWN); 221 exit(STATE_UNKNOWN);
236 case 'v': /* help */ 222 case 'v': /* help */
237 verbose = true; 223 verbose = true;
238 break; 224 break;
239 case 't': /* timeout period */ 225 case 't': /* timeout period */
240 if (!is_integer (optarg)) 226 if (!is_integer(optarg))
241 usage_va(_("Timeout interval must be a positive integer")); 227 usage_va(_("Timeout interval must be a positive integer"));
242 else 228 else
243 timeout_interval = atoi (optarg); 229 timeout_interval = atoi(optarg);
244 break; 230 break;
245 case 'U': 231 case 'U':
246 unknown_timeout = true; 232 unknown_timeout = true;
247 break; 233 break;
248 case 'H': /* host */ 234 case 'H': /* host */
249 hostname = optarg; 235 hostname = optarg;
250 break; 236 break;
251 case 'p': /* port number */ 237 case 'p': /* port number */
252 if (!is_integer (optarg)) 238 if (!is_integer(optarg))
253 usage_va(_("Port must be a positive integer")); 239 usage_va(_("Port must be a positive integer"));
254 comm_append("-p"); 240 comm_append("-p");
255 comm_append(optarg); 241 comm_append(optarg);
256 break; 242 break;
257 case 'O': /* output file */ 243 case 'O': /* output file */
258 outputfile = optarg; 244 outputfile = optarg;
259 passive = true; 245 passive = true;
260 break; 246 break;
261 case 's': /* description of service to check */ 247 case 's': /* description of service to check */
262 p1 = optarg; 248 p1 = optarg;
263 service = realloc (service, (++services) * sizeof(char *)); 249 service = realloc(service, (++services) * sizeof(char *));
264 while ((p2 = index (p1, ':'))) { 250 while ((p2 = index(p1, ':'))) {
265 *p2 = '\0'; 251 *p2 = '\0';
266 service[services - 1] = p1; 252 service[services - 1] = p1;
267 service = realloc (service, (++services) * sizeof(char *)); 253 service = realloc(service, (++services) * sizeof(char *));
268 p1 = p2 + 1; 254 p1 = p2 + 1;
269 } 255 }
270 service[services - 1] = p1; 256 service[services - 1] = p1;
271 break; 257 break;
272 case 'n': /* short name of host in the monitoring configuration */ 258 case 'n': /* short name of host in the monitoring configuration */
273 host_shortname = optarg; 259 host_shortname = optarg;
274 break; 260 break;
275 261
@@ -277,67 +263,67 @@ process_arguments (int argc, char **argv)
277 comm_append("-l"); 263 comm_append("-l");
278 comm_append(optarg); 264 comm_append(optarg);
279 break; 265 break;
280 case 'l': /* login name */ 266 case 'l': /* login name */
281 comm_append("-l"); 267 comm_append("-l");
282 comm_append(optarg); 268 comm_append(optarg);
283 break; 269 break;
284 case 'i': /* identity */ 270 case 'i': /* identity */
285 comm_append("-i"); 271 comm_append("-i");
286 comm_append(optarg); 272 comm_append(optarg);
287 break; 273 break;
288 274
289 case '1': /* Pass these switches directly to ssh */ 275 case '1': /* Pass these switches directly to ssh */
290 comm_append("-1"); 276 comm_append("-1");
291 break; 277 break;
292 case '2': /* 1 to force version 1, 2 to force version 2 */ 278 case '2': /* 1 to force version 1, 2 to force version 2 */
293 comm_append("-2"); 279 comm_append("-2");
294 break; 280 break;
295 case '4': /* -4 for IPv4 */ 281 case '4': /* -4 for IPv4 */
296 comm_append("-4"); 282 comm_append("-4");
297 break; 283 break;
298 case '6': /* -6 for IPv6 */ 284 case '6': /* -6 for IPv6 */
299 comm_append("-6"); 285 comm_append("-6");
300 break; 286 break;
301 case 'f': /* fork to background */ 287 case 'f': /* fork to background */
302 comm_append("-f"); 288 comm_append("-f");
303 break; 289 break;
304 case 'C': /* Command for remote machine */ 290 case 'C': /* Command for remote machine */
305 commands++; 291 commands++;
306 if (commands > 1) 292 if (commands > 1)
307 xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 293 xasprintf(&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
308 xasprintf (&remotecmd, "%s%s", remotecmd, optarg); 294 xasprintf(&remotecmd, "%s%s", remotecmd, optarg);
309 break; 295 break;
310 case 'S': /* skip n (or all) lines on stdout */ 296 case 'S': /* skip n (or all) lines on stdout */
311 if (optarg == NULL) 297 if (optarg == NULL)
312 skip_stdout = -1; /* skip all output on stdout */ 298 skip_stdout = -1; /* skip all output on stdout */
313 else if (!is_integer (optarg)) 299 else if (!is_integer(optarg))
314 usage_va(_("skip-stdout argument must be an integer")); 300 usage_va(_("skip-stdout argument must be an integer"));
315 else 301 else
316 skip_stdout = atoi (optarg); 302 skip_stdout = atoi(optarg);
317 break; 303 break;
318 case 'E': /* skip n (or all) lines on stderr */ 304 case 'E': /* skip n (or all) lines on stderr */
319 if (optarg == NULL) 305 if (optarg == NULL)
320 skip_stderr = -1; /* skip all output on stderr */ 306 skip_stderr = -1; /* skip all output on stderr */
321 else if (!is_integer (optarg)) 307 else if (!is_integer(optarg))
322 usage_va(_("skip-stderr argument must be an integer")); 308 usage_va(_("skip-stderr argument must be an integer"));
323 else 309 else
324 skip_stderr = atoi (optarg); 310 skip_stderr = atoi(optarg);
325 break; 311 break;
326 case 'W': /* exit with warning if there is an output on stderr */ 312 case 'W': /* exit with warning if there is an output on stderr */
327 warn_on_stderr = 1; 313 warn_on_stderr = 1;
328 break; 314 break;
329 case 'o': /* Extra options for the ssh command */ 315 case 'o': /* Extra options for the ssh command */
330 comm_append("-o"); 316 comm_append("-o");
331 comm_append(optarg); 317 comm_append(optarg);
332 break; 318 break;
333 case 'q': /* Tell the ssh command to be quiet */ 319 case 'q': /* Tell the ssh command to be quiet */
334 comm_append("-q"); 320 comm_append("-q");
335 break; 321 break;
336 case 'F': /* ssh configfile */ 322 case 'F': /* ssh configfile */
337 comm_append("-F"); 323 comm_append("-F");
338 comm_append(optarg); 324 comm_append(optarg);
339 break; 325 break;
340 default: /* help */ 326 default: /* help */
341 usage5(); 327 usage5();
342 } 328 }
343 } 329 }
@@ -345,7 +331,7 @@ process_arguments (int argc, char **argv)
345 c = optind; 331 c = optind;
346 if (hostname == NULL) { 332 if (hostname == NULL) {
347 if (c <= argc) { 333 if (c <= argc) {
348 die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); 334 die(STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname);
349 } 335 }
350 hostname = argv[c++]; 336 hostname = argv[c++];
351 } 337 }
@@ -353,143 +339,130 @@ process_arguments (int argc, char **argv)
353 if (strlen(remotecmd) == 0) { 339 if (strlen(remotecmd) == 0) {
354 for (; c < argc; c++) 340 for (; c < argc; c++)
355 if (strlen(remotecmd) > 0) 341 if (strlen(remotecmd) > 0)
356 xasprintf (&remotecmd, "%s %s", remotecmd, argv[c]); 342 xasprintf(&remotecmd, "%s %s", remotecmd, argv[c]);
357 else 343 else
358 xasprintf (&remotecmd, "%s", argv[c]); 344 xasprintf(&remotecmd, "%s", argv[c]);
359 } 345 }
360 346
361 if (commands > 1 || passive) 347 if (commands > 1 || passive)
362 xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 348 xasprintf(&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
363 349
364 if (remotecmd == NULL || strlen (remotecmd) <= 1) 350 if (remotecmd == NULL || strlen(remotecmd) <= 1)
365 usage_va(_("No remotecmd")); 351 usage_va(_("No remotecmd"));
366 352
367 comm_append(hostname); 353 comm_append(hostname);
368 comm_append(remotecmd); 354 comm_append(remotecmd);
369 355
370 return validate_arguments (); 356 return validate_arguments();
371} 357}
372 358
373 359void comm_append(const char *str) {
374void
375comm_append (const char *str)
376{
377 360
378 if (++commargc > NP_MAXARGS) 361 if (++commargc > NP_MAXARGS)
379 die(STATE_UNKNOWN, _("%s: Argument limit of %d exceeded\n"), progname, NP_MAXARGS); 362 die(STATE_UNKNOWN, _("%s: Argument limit of %d exceeded\n"), progname, NP_MAXARGS);
380 363
381 if ((commargv = (char **)realloc(commargv, (commargc+1) * sizeof(char *))) == NULL) 364 if ((commargv = (char **)realloc(commargv, (commargc + 1) * sizeof(char *))) == NULL)
382 die(STATE_UNKNOWN, _("Can not (re)allocate 'commargv' buffer\n")); 365 die(STATE_UNKNOWN, _("Can not (re)allocate 'commargv' buffer\n"));
383 366
384 commargv[commargc-1] = strdup(str); 367 commargv[commargc - 1] = strdup(str);
385 commargv[commargc] = NULL; 368 commargv[commargc] = NULL;
386
387} 369}
388 370
389int 371int validate_arguments(void) {
390validate_arguments (void)
391{
392 if (remotecmd == NULL || hostname == NULL) 372 if (remotecmd == NULL || hostname == NULL)
393 return ERROR; 373 return ERROR;
394 374
395 if (passive && commands != services) 375 if (passive && commands != services)
396 die (STATE_UNKNOWN, _("%s: In passive mode, you must provide a service name for each command.\n"), progname); 376 die(STATE_UNKNOWN, _("%s: In passive mode, you must provide a service name for each command.\n"), progname);
397 377
398 if (passive && host_shortname == NULL) 378 if (passive && host_shortname == NULL)
399 die (STATE_UNKNOWN, _("%s: In passive mode, you must provide the host short name from the monitoring configs.\n"), progname); 379 die(STATE_UNKNOWN, _("%s: In passive mode, you must provide the host short name from the monitoring configs.\n"), progname);
400 380
401 return OK; 381 return OK;
402} 382}
403 383
404 384void print_help(void) {
405void 385 print_revision(progname, NP_VERSION);
406print_help (void) 386
407{ 387 printf("Copyright (c) 1999 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
408 print_revision (progname, NP_VERSION); 388 printf(COPYRIGHT, copyright, email);
409 389
410 printf ("Copyright (c) 1999 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n"); 390 printf(_("This plugin uses SSH to execute commands on a remote host"));
411 printf (COPYRIGHT, copyright, email); 391
412 392 printf("\n\n");
413 printf (_("This plugin uses SSH to execute commands on a remote host")); 393
414 394 print_usage();
415 printf ("\n\n"); 395
416 396 printf(UT_HELP_VRSN);
417 print_usage (); 397
418 398 printf(UT_EXTRA_OPTS);
419 printf (UT_HELP_VRSN); 399
420 400 printf(UT_HOST_PORT, 'p', "none");
421 printf (UT_EXTRA_OPTS); 401
422 402 printf(UT_IPv46);
423 printf (UT_HOST_PORT, 'p', "none"); 403
424 404 printf(" %s\n", "-1, --proto1");
425 printf (UT_IPv46); 405 printf(" %s\n", _("tell ssh to use Protocol 1 [optional]"));
426 406 printf(" %s\n", "-2, --proto2");
427 printf (" %s\n", "-1, --proto1"); 407 printf(" %s\n", _("tell ssh to use Protocol 2 [optional]"));
428 printf (" %s\n", _("tell ssh to use Protocol 1 [optional]")); 408 printf(" %s\n", "-S, --skip-stdout[=n]");
429 printf (" %s\n", "-2, --proto2"); 409 printf(" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]"));
430 printf (" %s\n", _("tell ssh to use Protocol 2 [optional]")); 410 printf(" %s\n", "-E, --skip-stderr[=n]");
431 printf (" %s\n", "-S, --skip-stdout[=n]"); 411 printf(" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]"));
432 printf (" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]")); 412 printf(" %s\n", "-W, --warn-on-stderr]");
433 printf (" %s\n", "-E, --skip-stderr[=n]"); 413 printf(" %s\n", _("Exit with an warning, if there is an output on STDERR"));
434 printf (" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]")); 414 printf(" %s\n", "-f");
435 printf (" %s\n", "-W, --warn-on-stderr]"); 415 printf(" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed"));
436 printf (" %s\n", _("Exit with an warning, if there is an output on STDERR")); 416 printf(" %s\n", "-C, --command='COMMAND STRING'");
437 printf (" %s\n", "-f"); 417 printf(" %s\n", _("command to execute on the remote machine"));
438 printf (" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed")); 418 printf(" %s\n", "-l, --logname=USERNAME");
439 printf (" %s\n","-C, --command='COMMAND STRING'"); 419 printf(" %s\n", _("SSH user name on remote host [optional]"));
440 printf (" %s\n", _("command to execute on the remote machine")); 420 printf(" %s\n", "-i, --identity=KEYFILE");
441 printf (" %s\n","-l, --logname=USERNAME"); 421 printf(" %s\n", _("identity of an authorized key [optional]"));
442 printf (" %s\n", _("SSH user name on remote host [optional]")); 422 printf(" %s\n", "-O, --output=FILE");
443 printf (" %s\n","-i, --identity=KEYFILE"); 423 printf(" %s\n", _("external command file for monitoring [optional]"));
444 printf (" %s\n", _("identity of an authorized key [optional]")); 424 printf(" %s\n", "-s, --services=LIST");
445 printf (" %s\n","-O, --output=FILE"); 425 printf(" %s\n", _("list of monitoring service names, separated by ':' [optional]"));
446 printf (" %s\n", _("external command file for monitoring [optional]")); 426 printf(" %s\n", "-n, --name=NAME");
447 printf (" %s\n","-s, --services=LIST"); 427 printf(" %s\n", _("short name of host in the monitoring configuration [optional]"));
448 printf (" %s\n", _("list of monitoring service names, separated by ':' [optional]")); 428 printf(" %s\n", "-o, --ssh-option=OPTION");
449 printf (" %s\n","-n, --name=NAME"); 429 printf(" %s\n", _("Call ssh with '-o OPTION' (may be used multiple times) [optional]"));
450 printf (" %s\n", _("short name of host in the monitoring configuration [optional]")); 430 printf(" %s\n", "-F, --configfile");
451 printf (" %s\n","-o, --ssh-option=OPTION"); 431 printf(" %s\n", _("Tell ssh to use this configfile [optional]"));
452 printf (" %s\n", _("Call ssh with '-o OPTION' (may be used multiple times) [optional]")); 432 printf(" %s\n", "-q, --quiet");
453 printf (" %s\n","-F, --configfile"); 433 printf(" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]"));
454 printf (" %s\n", _("Tell ssh to use this configfile [optional]")); 434 printf(UT_WARN_CRIT);
455 printf (" %s\n","-q, --quiet"); 435 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
456 printf (" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]")); 436 printf(" %s\n", "-U, --unknown-timeout");
457 printf (UT_WARN_CRIT); 437 printf(" %s\n", _("Make connection problems return UNKNOWN instead of CRITICAL"));
458 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 438 printf(UT_VERBOSE);
459 printf (" %s\n","-U, --unknown-timeout"); 439 printf("\n");
460 printf (" %s\n", _("Make connection problems return UNKNOWN instead of CRITICAL")); 440 printf(" %s\n", _("The most common mode of use is to refer to a local identity file with"));
461 printf (UT_VERBOSE); 441 printf(" %s\n", _("the '-i' option. In this mode, the identity pair should have a null"));
442 printf(" %s\n", _("passphrase and the public key should be listed in the authorized_keys"));
443 printf(" %s\n", _("file of the remote host. Usually the key will be restricted to running"));
444 printf(" %s\n", _("only one command on the remote server. If the remote SSH server tracks"));
445 printf(" %s\n", _("invocation arguments, the one remote program may be an agent that can"));
446 printf(" %s\n", _("execute additional commands as proxy"));
447 printf("\n");
448 printf(" %s\n", _("To use passive mode, provide multiple '-C' options, and provide"));
449 printf(" %s\n", _("all of -O, -s, and -n options (servicelist order must match '-C'options)"));
462 printf("\n"); 450 printf("\n");
463 printf (" %s\n", _("The most common mode of use is to refer to a local identity file with")); 451 printf("%s\n", _("Examples:"));
464 printf (" %s\n", _("the '-i' option. In this mode, the identity pair should have a null")); 452 printf(" %s\n", "$ check_by_ssh -H localhost -n lh -s c1:c2:c3 -C uptime -C uptime -C uptime -O /tmp/foo");
465 printf (" %s\n", _("passphrase and the public key should be listed in the authorized_keys")); 453 printf(" %s\n", "$ cat /tmp/foo");
466 printf (" %s\n", _("file of the remote host. Usually the key will be restricted to running")); 454 printf(" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c1;0; up 2 days");
467 printf (" %s\n", _("only one command on the remote server. If the remote SSH server tracks")); 455 printf(" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c2;0; up 2 days");
468 printf (" %s\n", _("invocation arguments, the one remote program may be an agent that can")); 456 printf(" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c3;0; up 2 days");
469 printf (" %s\n", _("execute additional commands as proxy"));
470 printf("\n");
471 printf (" %s\n", _("To use passive mode, provide multiple '-C' options, and provide"));
472 printf (" %s\n", _("all of -O, -s, and -n options (servicelist order must match '-C'options)"));
473 printf ("\n");
474 printf ("%s\n", _("Examples:"));
475 printf (" %s\n", "$ check_by_ssh -H localhost -n lh -s c1:c2:c3 -C uptime -C uptime -C uptime -O /tmp/foo");
476 printf (" %s\n", "$ cat /tmp/foo");
477 printf (" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c1;0; up 2 days");
478 printf (" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c2;0; up 2 days");
479 printf (" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c3;0; up 2 days");
480 457
481 printf(UT_SUPPORT); 458 printf(UT_SUPPORT);
482} 459}
483 460
484 461void print_usage(void) {
485 462 printf("%s\n", _("Usage:"));
486void 463 printf(" %s -H <host> -C <command> [-fqvU] [-1|-2] [-4|-6]\n"
487print_usage (void) 464 " [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n"
488{ 465 " [-l user] [-n name] [-s servicelist] [-O outputfile]\n"
489 printf ("%s\n", _("Usage:")); 466 " [-p port] [-o ssh-option] [-F configfile]\n",
490 printf (" %s -H <host> -C <command> [-fqvU] [-1|-2] [-4|-6]\n" 467 progname);
491 " [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n"
492 " [-l user] [-n name] [-s servicelist] [-O outputfile]\n"
493 " [-p port] [-o ssh-option] [-F configfile]\n",
494 progname);
495} 468}