diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-18 22:25:08 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-18 22:25:08 +0200 |
commit | 14bc7af32307d8d3aed2b0800a0efd7fbda79152 (patch) | |
tree | 606de1b939ebb666afea93d60da46829325e7f3a /plugins | |
parent | 6d6f090eaa384aab6677953e6ea378dc228ac667 (diff) | |
parent | 5ed7194c7e1f6c46c9b40dccbe760dfef853bae1 (diff) | |
download | monitoring-plugins-14bc7af32307d8d3aed2b0800a0efd7fbda79152.tar.gz |
Merge branch 'master' of https://github.com/jonmilby/nagios-plugins
* 'master' of https://github.com/jonmilby/nagios-plugins:
Updated check_mysql.c to take client options file and group parameters
Conflicts:
plugins/check_mysql.c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_mysql.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 11d4a2fd..521c902d 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
@@ -55,6 +55,8 @@ char *cert = NULL; | |||
55 | char *key = NULL; | 55 | char *key = NULL; |
56 | char *ciphers = NULL; | 56 | char *ciphers = NULL; |
57 | bool ssl = false; | 57 | bool ssl = false; |
58 | char *opt_file = NULL; | ||
59 | char *opt_group = NULL; | ||
58 | unsigned int db_port = MYSQL_PORT; | 60 | unsigned int db_port = MYSQL_PORT; |
59 | int check_slave = 0, warn_sec = 0, crit_sec = 0; | 61 | int check_slave = 0, warn_sec = 0, crit_sec = 0; |
60 | int verbose = 0; | 62 | int verbose = 0; |
@@ -121,8 +123,14 @@ main (int argc, char **argv) | |||
121 | 123 | ||
122 | /* initialize mysql */ | 124 | /* initialize mysql */ |
123 | mysql_init (&mysql); | 125 | mysql_init (&mysql); |
126 | |||
127 | if (opt_file != NULL) | ||
128 | mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file); | ||
124 | 129 | ||
125 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); | 130 | if (opt_group != NULL) |
131 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,opt_group); | ||
132 | else | ||
133 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); | ||
126 | 134 | ||
127 | if (ssl) | 135 | if (ssl) |
128 | mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers); | 136 | mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers); |
@@ -327,6 +335,8 @@ process_arguments (int argc, char **argv) | |||
327 | {"database", required_argument, 0, 'd'}, | 335 | {"database", required_argument, 0, 'd'}, |
328 | {"username", required_argument, 0, 'u'}, | 336 | {"username", required_argument, 0, 'u'}, |
329 | {"password", required_argument, 0, 'p'}, | 337 | {"password", required_argument, 0, 'p'}, |
338 | {"file", required_argument, 0, 'f'}, | ||
339 | {"group", required_argument, 0, 'g'}, | ||
330 | {"port", required_argument, 0, 'P'}, | 340 | {"port", required_argument, 0, 'P'}, |
331 | {"critical", required_argument, 0, 'c'}, | 341 | {"critical", required_argument, 0, 'c'}, |
332 | {"warning", required_argument, 0, 'w'}, | 342 | {"warning", required_argument, 0, 'w'}, |
@@ -347,7 +357,7 @@ process_arguments (int argc, char **argv) | |||
347 | return ERROR; | 357 | return ERROR; |
348 | 358 | ||
349 | while (1) { | 359 | while (1) { |
350 | c = getopt_long (argc, argv, "hlvVSP:p:u:d:H:s:c:w:a:k:C:D:L:", longopts, &option); | 360 | c = getopt_long (argc, argv, "hlvVSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option); |
351 | 361 | ||
352 | if (c == -1 || c == EOF) | 362 | if (c == -1 || c == EOF) |
353 | break; | 363 | break; |
@@ -397,6 +407,12 @@ process_arguments (int argc, char **argv) | |||
397 | optarg++; | 407 | optarg++; |
398 | } | 408 | } |
399 | break; | 409 | break; |
410 | case 'f': /* username */ | ||
411 | opt_file = optarg; | ||
412 | break; | ||
413 | case 'g': /* username */ | ||
414 | opt_group = optarg; | ||
415 | break; | ||
400 | case 'P': /* critical time threshold */ | 416 | case 'P': /* critical time threshold */ |
401 | db_port = atoi (optarg); | 417 | db_port = atoi (optarg); |
402 | break; | 418 | break; |
@@ -440,6 +456,10 @@ process_arguments (int argc, char **argv) | |||
440 | } | 456 | } |
441 | else if (db_user == NULL) | 457 | else if (db_user == NULL) |
442 | db_user = argv[c++]; | 458 | db_user = argv[c++]; |
459 | else if (opt_file == NULL) | ||
460 | opt_file = argv[c++]; | ||
461 | else if (opt_group == NULL) | ||
462 | opt_group = argv[c++]; | ||
443 | else if (db_pass == NULL) | 463 | else if (db_pass == NULL) |
444 | db_pass = argv[c++]; | 464 | db_pass = argv[c++]; |
445 | else if (db == NULL) | 465 | else if (db == NULL) |
@@ -460,6 +480,12 @@ validate_arguments (void) | |||
460 | if (db_user == NULL) | 480 | if (db_user == NULL) |
461 | db_user = strdup(""); | 481 | db_user = strdup(""); |
462 | 482 | ||
483 | if (opt_file == NULL) | ||
484 | opt_file = strdup(""); | ||
485 | |||
486 | if (opt_group == NULL) | ||
487 | opt_group = strdup(""); | ||
488 | |||
463 | if (db_host == NULL) | 489 | if (db_host == NULL) |
464 | db_host = strdup(""); | 490 | db_host = strdup(""); |
465 | 491 | ||
@@ -474,7 +500,7 @@ void | |||
474 | print_help (void) | 500 | print_help (void) |
475 | { | 501 | { |
476 | char *myport; | 502 | char *myport; |
477 | xasprintf (&myport, "%d", MYSQL_PORT); | 503 | asprintf (&myport, "%d", MYSQL_PORT); |
478 | 504 | ||
479 | print_revision (progname, NP_VERSION); | 505 | print_revision (progname, NP_VERSION); |
480 | 506 | ||
@@ -495,6 +521,10 @@ print_help (void) | |||
495 | 521 | ||
496 | printf (" %s\n", "-d, --database=STRING"); | 522 | printf (" %s\n", "-d, --database=STRING"); |
497 | printf (" %s\n", _("Check database with indicated name")); | 523 | printf (" %s\n", _("Check database with indicated name")); |
524 | printf (" %s\n", "-f, --file=STRING"); | ||
525 | printf (" %s\n", _("Read from the specified client options file")); | ||
526 | printf (" %s\n", "-g, --group=STRING"); | ||
527 | printf (" %s\n", _("Use a client options group")); | ||
498 | printf (" %s\n", "-u, --username=STRING"); | 528 | printf (" %s\n", "-u, --username=STRING"); |
499 | printf (" %s\n", _("Connect using the indicated username")); | 529 | printf (" %s\n", _("Connect using the indicated username")); |
500 | printf (" %s\n", "-p, --password=STRING"); | 530 | printf (" %s\n", "-p, --password=STRING"); |
@@ -543,5 +573,5 @@ print_usage (void) | |||
543 | printf ("%s\n", _("Usage:")); | 573 | printf ("%s\n", _("Usage:")); |
544 | printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); | 574 | printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); |
545 | printf (" [-u user] [-p password] [-S] [-l] [-a cert] [-k key]\n"); | 575 | printf (" [-u user] [-p password] [-S] [-l] [-a cert] [-k key]\n"); |
546 | printf (" [-C ca-cert] [-D ca-dir] [-L ciphers]\n"); | 576 | printf (" [-C ca-cert] [-D ca-dir] [-L ciphers] [-f optfile] [-g group]\n"); |
547 | } | 577 | } |