summaryrefslogtreecommitdiffstats
path: root/plugins/check_by_ssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_by_ssh.c')
-rw-r--r--plugins/check_by_ssh.c330
1 files changed, 185 insertions, 145 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 905b2393..2bc38d49 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -32,48 +32,28 @@ const char *email = "devel@monitoring-plugins.org";
32 32
33#include "common.h" 33#include "common.h"
34#include "utils.h" 34#include "utils.h"
35#include "netutils.h"
36#include "utils_cmd.h" 35#include "utils_cmd.h"
36#include "check_by_ssh.d/config.h"
37#include "states.h"
37 38
38#ifndef NP_MAXARGS 39#ifndef NP_MAXARGS
39# define NP_MAXARGS 1024 40# define NP_MAXARGS 1024
40#endif 41#endif
41 42
42static int process_arguments(int /*argc*/, char ** /*argv*/); 43typedef struct {
43static int validate_arguments(void); 44 int errorcode;
44static void comm_append(const char * /*str*/); 45 check_by_ssh_config config;
46} check_by_ssh_config_wrapper;
47static check_by_ssh_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
48static check_by_ssh_config_wrapper validate_arguments(check_by_ssh_config_wrapper /*config_wrapper*/);
49
50static command_construct comm_append(command_construct /*cmd*/, const char * /*str*/);
45static void print_help(void); 51static void print_help(void);
46void print_usage(void); 52void print_usage(void);
47 53
48static unsigned int commands = 0;
49static unsigned int services = 0;
50static int skip_stdout = 0;
51static int skip_stderr = 0;
52static int warn_on_stderr = 0;
53static bool unknown_timeout = false;
54static char *remotecmd = NULL;
55static char **commargv = NULL;
56static int commargc = 0;
57static char *hostname = NULL;
58static char *outputfile = NULL;
59static char *host_shortname = NULL;
60static char **service;
61static bool passive = false;
62static bool verbose = false; 54static bool verbose = false;
63 55
64int main(int argc, char **argv) { 56int main(int argc, char **argv) {
65
66 char *status_text;
67 int cresult;
68 int result = STATE_UNKNOWN;
69 time_t local_time;
70 FILE *file_pointer = NULL;
71 output chld_out;
72 output chld_err;
73
74 remotecmd = "";
75 comm_append(SSH_COMMAND);
76
77 setlocale(LC_ALL, ""); 57 setlocale(LC_ALL, "");
78 bindtextdomain(PACKAGE, LOCALEDIR); 58 bindtextdomain(PACKAGE, LOCALEDIR);
79 textdomain(PACKAGE); 59 textdomain(PACKAGE);
@@ -81,9 +61,14 @@ int main(int argc, char **argv) {
81 /* Parse extra opts if any */ 61 /* Parse extra opts if any */
82 argv = np_extra_opts(&argc, argv, progname); 62 argv = np_extra_opts(&argc, argv, progname);
83 63
64 check_by_ssh_config_wrapper tmp_config = process_arguments(argc, argv);
65
84 /* process arguments */ 66 /* process arguments */
85 if (process_arguments(argc, argv) == ERROR) 67 if (tmp_config.errorcode == ERROR) {
86 usage_va(_("Could not parse arguments")); 68 usage_va(_("Could not parse arguments"));
69 }
70
71 const check_by_ssh_config config = tmp_config.config;
87 72
88 /* Set signal handling and alarm timeout */ 73 /* Set signal handling and alarm timeout */
89 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { 74 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) {
@@ -93,47 +78,64 @@ int main(int argc, char **argv) {
93 78
94 /* run the command */ 79 /* run the command */
95 if (verbose) { 80 if (verbose) {
96 printf("Command: %s\n", commargv[0]); 81 printf("Command: %s\n", config.cmd.commargv[0]);
97 for (int i = 1; i < commargc; i++) 82 for (int i = 1; i < config.cmd.commargc; i++) {
98 printf("Argument %i: %s\n", i, commargv[i]); 83 printf("Argument %i: %s\n", i, config.cmd.commargv[i]);
84 }
99 } 85 }
100 86
101 result = cmd_run_array(commargv, &chld_out, &chld_err, 0); 87 output chld_out;
88 output chld_err;
89 mp_state_enum result = cmd_run_array(config.cmd.commargv, &chld_out, &chld_err, 0);
102 90
103 /* SSH returns 255 if connection attempt fails; include the first line of error output */ 91 /* SSH returns 255 if connection attempt fails; include the first line of error output */
104 if (result == 255 && unknown_timeout) { 92 if (result == 255 && config.unknown_timeout) {
105 printf(_("SSH connection failed: %s\n"), chld_err.lines > 0 ? chld_err.line[0] : "(no error output)"); 93 printf(_("SSH connection failed: %s\n"), chld_err.lines > 0 ? chld_err.line[0] : "(no error output)");
106 return STATE_UNKNOWN; 94 return STATE_UNKNOWN;
107 } 95 }
108 96
109 if (verbose) { 97 if (verbose) {
110 for (size_t i = 0; i < chld_out.lines; i++) 98 for (size_t i = 0; i < chld_out.lines; i++) {
111 printf("stdout: %s\n", chld_out.line[i]); 99 printf("stdout: %s\n", chld_out.line[i]);
112 for (size_t i = 0; i < chld_err.lines; i++) 100 }
101 for (size_t i = 0; i < chld_err.lines; i++) {
113 printf("stderr: %s\n", chld_err.line[i]); 102 printf("stderr: %s\n", chld_err.line[i]);
103 }
114 } 104 }
115 105
116 if (skip_stdout == -1) /* --skip-stdout specified without argument */ 106 size_t skip_stdout = 0;
107 if (config.skip_stdout == -1) { /* --skip-stdout specified without argument */
117 skip_stdout = chld_out.lines; 108 skip_stdout = chld_out.lines;
118 if (skip_stderr == -1) /* --skip-stderr specified without argument */ 109 } else {
110 skip_stdout = config.skip_stdout;
111 }
112
113 size_t skip_stderr = 0;
114 if (config.skip_stderr == -1) { /* --skip-stderr specified without argument */
119 skip_stderr = chld_err.lines; 115 skip_stderr = chld_err.lines;
116 } else {
117 skip_stderr = config.skip_stderr;
118 }
120 119
121 /* UNKNOWN or worse if (non-skipped) output found on stderr */ 120 /* UNKNOWN or worse if (non-skipped) output found on stderr */
122 if (chld_err.lines > (size_t)skip_stderr) { 121 if (chld_err.lines > (size_t)skip_stderr) {
123 printf(_("Remote command execution failed: %s\n"), chld_err.line[skip_stderr]); 122 printf(_("Remote command execution failed: %s\n"), chld_err.line[skip_stderr]);
124 if (warn_on_stderr) 123 if (config.warn_on_stderr) {
125 return max_state_alt(result, STATE_WARNING); 124 return max_state_alt(result, STATE_WARNING);
125 }
126 return max_state_alt(result, STATE_UNKNOWN); 126 return max_state_alt(result, STATE_UNKNOWN);
127 } 127 }
128 128
129 /* this is simple if we're not supposed to be passive. 129 /* this is simple if we're not supposed to be passive.
130 * Wrap up quickly and keep the tricks below */ 130 * Wrap up quickly and keep the tricks below */
131 if (!passive) { 131 if (!config.passive) {
132 if (chld_out.lines > (size_t)skip_stdout) 132 if (chld_out.lines > (size_t)skip_stdout) {
133 for (size_t i = skip_stdout; i < chld_out.lines; i++) 133 for (size_t i = skip_stdout; i < chld_out.lines; i++) {
134 puts(chld_out.line[i]); 134 puts(chld_out.line[i]);
135 else 135 }
136 printf(_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), state_text(result), remotecmd, result); 136 } else {
137 printf(_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), state_text(result), config.remotecmd, result);
138 }
137 return result; /* return error status from remote command */ 139 return result; /* return error status from remote command */
138 } 140 }
139 141
@@ -142,35 +144,34 @@ int main(int argc, char **argv) {
142 */ 144 */
143 145
144 /* process output */ 146 /* process output */
145 if (!(file_pointer = fopen(outputfile, "a"))) { 147 FILE *file_pointer = NULL;
146 printf(_("SSH WARNING: could not open %s\n"), outputfile); 148 if (!(file_pointer = fopen(config.outputfile, "a"))) {
149 printf(_("SSH WARNING: could not open %s\n"), config.outputfile);
147 exit(STATE_UNKNOWN); 150 exit(STATE_UNKNOWN);
148 } 151 }
149 152
150 local_time = time(NULL); 153 time_t local_time = time(NULL);
151 commands = 0; 154 unsigned int commands = 0;
155 char *status_text;
156 int cresult;
152 for (size_t i = skip_stdout; i < chld_out.lines; i++) { 157 for (size_t i = skip_stdout; i < chld_out.lines; i++) {
153 status_text = chld_out.line[i++]; 158 status_text = chld_out.line[i++];
154 if (i == chld_out.lines || strstr(chld_out.line[i], "STATUS CODE: ") == NULL) 159 if (i == chld_out.lines || strstr(chld_out.line[i], "STATUS CODE: ") == NULL) {
155 die(STATE_UNKNOWN, _("%s: Error parsing output\n"), progname); 160 die(STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
161 }
156 162
157 if (service[commands] && status_text && sscanf(chld_out.line[i], "STATUS CODE: %d", &cresult) == 1) { 163 if (config.service[commands] && status_text && sscanf(chld_out.line[i], "STATUS CODE: %d", &cresult) == 1) {
158 fprintf(file_pointer, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, host_shortname, service[commands++], 164 fprintf(file_pointer, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, config.host_shortname,
159 cresult, status_text); 165 config.service[commands++], cresult, status_text);
160 } 166 }
161 } 167 }
162 168
163 /* Multiple commands and passive checking should always return OK */ 169 /* Multiple commands and passive checking should always return OK */
164 return result; 170 exit(result);
165} 171}
166 172
167/* process command-line arguments */ 173/* process command-line arguments */
168int process_arguments(int argc, char **argv) { 174check_by_ssh_config_wrapper process_arguments(int argc, char **argv) {
169 int c;
170 char *p1;
171 char *p2;
172
173 int option = 0;
174 static struct option longopts[] = {{"version", no_argument, 0, 'V'}, 175 static struct option longopts[] = {{"version", no_argument, 0, 'V'},
175 {"help", no_argument, 0, 'h'}, 176 {"help", no_argument, 0, 'h'},
176 {"verbose", no_argument, 0, 'v'}, 177 {"verbose", no_argument, 0, 'v'},
@@ -200,20 +201,33 @@ int process_arguments(int argc, char **argv) {
200 {"configfile", optional_argument, 0, 'F'}, 201 {"configfile", optional_argument, 0, 'F'},
201 {0, 0, 0, 0}}; 202 {0, 0, 0, 0}};
202 203
203 if (argc < 2) 204 check_by_ssh_config_wrapper result = {
204 return ERROR; 205 .errorcode = OK,
206 .config = check_by_ssh_config_init(),
207 };
205 208
206 for (c = 1; c < argc; c++) 209 if (argc < 2) {
207 if (strcmp("-to", argv[c]) == 0) 210 result.errorcode = ERROR;
208 strcpy(argv[c], "-t"); 211 return result;
212 }
209 213
210 while (1) { 214 for (int index = 1; index < argc; index++) {
211 c = getopt_long(argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, &option); 215 if (strcmp("-to", argv[index]) == 0) {
216 strcpy(argv[index], "-t");
217 }
218 }
219
220 result.config.cmd = comm_append(result.config.cmd, SSH_COMMAND);
221
222 int option = 0;
223 while (true) {
224 int opt_index = getopt_long(argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, &option);
212 225
213 if (c == -1 || c == EOF) 226 if (opt_index == -1 || opt_index == EOF) {
214 break; 227 break;
228 }
215 229
216 switch (c) { 230 switch (opt_index) {
217 case 'V': /* version */ 231 case 'V': /* version */
218 print_revision(progname, NP_VERSION); 232 print_revision(progname, NP_VERSION);
219 exit(STATE_UNKNOWN); 233 exit(STATE_UNKNOWN);
@@ -224,162 +238,189 @@ int process_arguments(int argc, char **argv) {
224 verbose = true; 238 verbose = true;
225 break; 239 break;
226 case 't': /* timeout period */ 240 case 't': /* timeout period */
227 if (!is_integer(optarg)) 241 if (!is_integer(optarg)) {
228 usage_va(_("Timeout interval must be a positive integer")); 242 usage_va(_("Timeout interval must be a positive integer"));
229 else 243 } else {
230 timeout_interval = atoi(optarg); 244 timeout_interval = atoi(optarg);
245 }
231 break; 246 break;
232 case 'U': 247 case 'U':
233 unknown_timeout = true; 248 result.config.unknown_timeout = true;
234 break; 249 break;
235 case 'H': /* host */ 250 case 'H': /* host */
236 hostname = optarg; 251 result.config.hostname = optarg;
237 break; 252 break;
238 case 'p': /* port number */ 253 case 'p': /* port number */
239 if (!is_integer(optarg)) 254 if (!is_integer(optarg)) {
240 usage_va(_("Port must be a positive integer")); 255 usage_va(_("Port must be a positive integer"));
241 comm_append("-p"); 256 }
242 comm_append(optarg); 257 result.config.cmd = comm_append(result.config.cmd, "-p");
258 result.config.cmd = comm_append(result.config.cmd, optarg);
243 break; 259 break;
244 case 'O': /* output file */ 260 case 'O': /* output file */
245 outputfile = optarg; 261 result.config.outputfile = optarg;
246 passive = true; 262 result.config.passive = true;
247 break; 263 break;
248 case 's': /* description of service to check */ 264 case 's': /* description of service to check */ {
265 char *p1;
266 char *p2;
267
249 p1 = optarg; 268 p1 = optarg;
250 service = realloc(service, (++services) * sizeof(char *)); 269 result.config.service = realloc(result.config.service, (++result.config.number_of_services) * sizeof(char *));
251 while ((p2 = index(p1, ':'))) { 270 while ((p2 = index(p1, ':'))) {
252 *p2 = '\0'; 271 *p2 = '\0';
253 service[services - 1] = p1; 272 result.config.service[result.config.number_of_services - 1] = p1;
254 service = realloc(service, (++services) * sizeof(char *)); 273 result.config.service = realloc(result.config.service, (++result.config.number_of_services) * sizeof(char *));
255 p1 = p2 + 1; 274 p1 = p2 + 1;
256 } 275 }
257 service[services - 1] = p1; 276 result.config.service[result.config.number_of_services - 1] = p1;
258 break; 277 break;
259 case 'n': /* short name of host in the monitoring configuration */ 278 case 'n': /* short name of host in the monitoring configuration */
260 host_shortname = optarg; 279 result.config.host_shortname = optarg;
261 break; 280 } break;
262
263 case 'u': 281 case 'u':
264 comm_append("-l"); 282 result.config.cmd = comm_append(result.config.cmd, "-l");
265 comm_append(optarg); 283 result.config.cmd = comm_append(result.config.cmd, optarg);
266 break; 284 break;
267 case 'l': /* login name */ 285 case 'l': /* login name */
268 comm_append("-l"); 286 result.config.cmd = comm_append(result.config.cmd, "-l");
269 comm_append(optarg); 287 result.config.cmd = comm_append(result.config.cmd, optarg);
270 break; 288 break;
271 case 'i': /* identity */ 289 case 'i': /* identity */
272 comm_append("-i"); 290 result.config.cmd = comm_append(result.config.cmd, "-i");
273 comm_append(optarg); 291 result.config.cmd = comm_append(result.config.cmd, optarg);
274 break; 292 break;
275 293
276 case '1': /* Pass these switches directly to ssh */ 294 case '1': /* Pass these switches directly to ssh */
277 comm_append("-1"); 295 result.config.cmd = comm_append(result.config.cmd, "-1");
278 break; 296 break;
279 case '2': /* 1 to force version 1, 2 to force version 2 */ 297 case '2': /* 1 to force version 1, 2 to force version 2 */
280 comm_append("-2"); 298 result.config.cmd = comm_append(result.config.cmd, "-2");
281 break; 299 break;
282 case '4': /* -4 for IPv4 */ 300 case '4': /* -4 for IPv4 */
283 comm_append("-4"); 301 result.config.cmd = comm_append(result.config.cmd, "-4");
284 break; 302 break;
285 case '6': /* -6 for IPv6 */ 303 case '6': /* -6 for IPv6 */
286 comm_append("-6"); 304 result.config.cmd = comm_append(result.config.cmd, "-6");
287 break; 305 break;
288 case 'f': /* fork to background */ 306 case 'f': /* fork to background */
289 comm_append("-f"); 307 result.config.cmd = comm_append(result.config.cmd, "-f");
290 break; 308 break;
291 case 'C': /* Command for remote machine */ 309 case 'C': /* Command for remote machine */
292 commands++; 310 result.config.commands++;
293 if (commands > 1) 311 if (result.config.commands > 1) {
294 xasprintf(&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 312 xasprintf(&result.config.remotecmd, "%s;echo STATUS CODE: $?;", result.config.remotecmd);
295 xasprintf(&remotecmd, "%s%s", remotecmd, optarg); 313 }
314 xasprintf(&result.config.remotecmd, "%s%s", result.config.remotecmd, optarg);
296 break; 315 break;
297 case 'S': /* skip n (or all) lines on stdout */ 316 case 'S': /* skip n (or all) lines on stdout */
298 if (optarg == NULL) 317 if (optarg == NULL) {
299 skip_stdout = -1; /* skip all output on stdout */ 318 result.config.skip_stdout = -1; /* skip all output on stdout */
300 else if (!is_integer(optarg)) 319 } else if (!is_integer(optarg)) {
301 usage_va(_("skip-stdout argument must be an integer")); 320 usage_va(_("skip-stdout argument must be an integer"));
302 else 321 } else {
303 skip_stdout = atoi(optarg); 322 result.config.skip_stdout = atoi(optarg);
323 }
304 break; 324 break;
305 case 'E': /* skip n (or all) lines on stderr */ 325 case 'E': /* skip n (or all) lines on stderr */
306 if (optarg == NULL) 326 if (optarg == NULL) {
307 skip_stderr = -1; /* skip all output on stderr */ 327 result.config.skip_stderr = -1; /* skip all output on stderr */
308 else if (!is_integer(optarg)) 328 } else if (!is_integer(optarg)) {
309 usage_va(_("skip-stderr argument must be an integer")); 329 usage_va(_("skip-stderr argument must be an integer"));
310 else 330 } else {
311 skip_stderr = atoi(optarg); 331 result.config.skip_stderr = atoi(optarg);
332 }
312 break; 333 break;
313 case 'W': /* exit with warning if there is an output on stderr */ 334 case 'W': /* exit with warning if there is an output on stderr */
314 warn_on_stderr = 1; 335 result.config.warn_on_stderr = true;
315 break; 336 break;
316 case 'o': /* Extra options for the ssh command */ 337 case 'o': /* Extra options for the ssh command */
317 comm_append("-o"); 338 result.config.cmd = comm_append(result.config.cmd, "-o");
318 comm_append(optarg); 339 result.config.cmd = comm_append(result.config.cmd, optarg);
319 break; 340 break;
320 case 'q': /* Tell the ssh command to be quiet */ 341 case 'q': /* Tell the ssh command to be quiet */
321 comm_append("-q"); 342 result.config.cmd = comm_append(result.config.cmd, "-q");
322 break; 343 break;
323 case 'F': /* ssh configfile */ 344 case 'F': /* ssh configfile */
324 comm_append("-F"); 345 result.config.cmd = comm_append(result.config.cmd, "-F");
325 comm_append(optarg); 346 result.config.cmd = comm_append(result.config.cmd, optarg);
326 break; 347 break;
327 default: /* help */ 348 default: /* help */
328 usage5(); 349 usage5();
329 } 350 }
330 } 351 }
331 352
332 c = optind; 353 int c = optind;
333 if (hostname == NULL) { 354 if (result.config.hostname == NULL) {
334 if (c <= argc) { 355 if (c <= argc) {
335 die(STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); 356 die(STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname);
336 } 357 }
337 hostname = argv[c++]; 358 result.config.hostname = argv[c++];
338 } 359 }
339 360
340 if (strlen(remotecmd) == 0) { 361 if (strlen(result.config.remotecmd) == 0) {
341 for (; c < argc; c++) 362 for (; c < argc; c++) {
342 if (strlen(remotecmd) > 0) 363 if (strlen(result.config.remotecmd) > 0) {
343 xasprintf(&remotecmd, "%s %s", remotecmd, argv[c]); 364 xasprintf(&result.config.remotecmd, "%s %s", result.config.remotecmd, argv[c]);
344 else 365 } else {
345 xasprintf(&remotecmd, "%s", argv[c]); 366 xasprintf(&result.config.remotecmd, "%s", argv[c]);
367 }
368 }
346 } 369 }
347 370
348 if (commands > 1 || passive) 371 if (result.config.commands > 1 || result.config.passive) {
349 xasprintf(&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 372 xasprintf(&result.config.remotecmd, "%s;echo STATUS CODE: $?;", result.config.remotecmd);
373 }
350 374
351 if (remotecmd == NULL || strlen(remotecmd) <= 1) 375 if (result.config.remotecmd == NULL || strlen(result.config.remotecmd) <= 1) {
352 usage_va(_("No remotecmd")); 376 usage_va(_("No remotecmd"));
377 }
353 378
354 comm_append(hostname); 379 result.config.cmd = comm_append(result.config.cmd, result.config.hostname);
355 comm_append(remotecmd); 380 result.config.cmd = comm_append(result.config.cmd, result.config.remotecmd);
356 381
357 return validate_arguments(); 382 return validate_arguments(result);
358} 383}
359 384
360void comm_append(const char *str) { 385command_construct comm_append(command_construct cmd, const char *str) {
386
387 if (verbose) {
388 for (int i = 0; i < cmd.commargc; i++) {
389 printf("Current command: [%i] %s\n", i, cmd.commargv[i]);
390 }
391
392 printf("Appending: %s\n", str);
393 }
361 394
362 if (++commargc > NP_MAXARGS) 395 if (++cmd.commargc > NP_MAXARGS) {
363 die(STATE_UNKNOWN, _("%s: Argument limit of %d exceeded\n"), progname, NP_MAXARGS); 396 die(STATE_UNKNOWN, _("%s: Argument limit of %d exceeded\n"), progname, NP_MAXARGS);
397 }
364 398
365 if ((commargv = (char **)realloc(commargv, (commargc + 1) * sizeof(char *))) == NULL) 399 if ((cmd.commargv = (char **)realloc(cmd.commargv, (cmd.commargc + 1) * sizeof(char *))) == NULL) {
366 die(STATE_UNKNOWN, _("Can not (re)allocate 'commargv' buffer\n")); 400 die(STATE_UNKNOWN, _("Can not (re)allocate 'commargv' buffer\n"));
401 }
402
403 cmd.commargv[cmd.commargc - 1] = strdup(str);
404 cmd.commargv[cmd.commargc] = NULL;
367 405
368 commargv[commargc - 1] = strdup(str); 406 return cmd;
369 commargv[commargc] = NULL;
370} 407}
371 408
372int validate_arguments(void) { 409check_by_ssh_config_wrapper validate_arguments(check_by_ssh_config_wrapper config_wrapper) {
373 if (remotecmd == NULL || hostname == NULL) 410 if (config_wrapper.config.remotecmd == NULL || config_wrapper.config.hostname == NULL) {
374 return ERROR; 411 config_wrapper.errorcode = ERROR;
412 return config_wrapper;
413 }
375 414
376 if (passive && commands != services) 415 if (config_wrapper.config.passive && config_wrapper.config.commands != config_wrapper.config.number_of_services) {
377 die(STATE_UNKNOWN, _("%s: In passive mode, you must provide a service name for each command.\n"), progname); 416 die(STATE_UNKNOWN, _("%s: In passive mode, you must provide a service name for each command.\n"), progname);
417 }
378 418
379 if (passive && host_shortname == NULL) 419 if (config_wrapper.config.passive && config_wrapper.config.host_shortname == NULL) {
380 die(STATE_UNKNOWN, _("%s: In passive mode, you must provide the host short name from the monitoring configs.\n"), progname); 420 die(STATE_UNKNOWN, _("%s: In passive mode, you must provide the host short name from the monitoring configs.\n"), progname);
421 }
381 422
382 return OK; 423 return config_wrapper;
383} 424}
384 425
385void print_help(void) { 426void print_help(void) {
@@ -432,7 +473,6 @@ void print_help(void) {
432 printf(" %s\n", _("Tell ssh to use this configfile [optional]")); 473 printf(" %s\n", _("Tell ssh to use this configfile [optional]"));
433 printf(" %s\n", "-q, --quiet"); 474 printf(" %s\n", "-q, --quiet");
434 printf(" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]")); 475 printf(" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]"));
435 printf(UT_WARN_CRIT);
436 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 476 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
437 printf(" %s\n", "-U, --unknown-timeout"); 477 printf(" %s\n", "-U, --unknown-timeout");
438 printf(" %s\n", _("Make connection problems return UNKNOWN instead of CRITICAL")); 478 printf(" %s\n", _("Make connection problems return UNKNOWN instead of CRITICAL"));