summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_mysql.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 11d4a2f..521c902 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -55,6 +55,8 @@ char *cert = NULL;
55char *key = NULL; 55char *key = NULL;
56char *ciphers = NULL; 56char *ciphers = NULL;
57bool ssl = false; 57bool ssl = false;
58char *opt_file = NULL;
59char *opt_group = NULL;
58unsigned int db_port = MYSQL_PORT; 60unsigned int db_port = MYSQL_PORT;
59int check_slave = 0, warn_sec = 0, crit_sec = 0; 61int check_slave = 0, warn_sec = 0, crit_sec = 0;
60int verbose = 0; 62int 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
474print_help (void) 500print_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}