diff options
-rw-r--r-- | plugins/check_mysql.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 4fbdc2b9..cacc6c24 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -49,6 +49,8 @@ char *db_host = NULL; char *db_socket = NULL; char *db_pass = NULL; char *db = NULL; +char *opt_file = NULL; +char *opt_group = NULL; unsigned int db_port = MYSQL_PORT; int check_slave = 0, warn_sec = 0, crit_sec = 0; int verbose = 0; @@ -86,8 +88,14 @@ main (int argc, char **argv) /* initialize mysql */ mysql_init (&mysql); + + if (opt_file != NULL) + mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file); - mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); + if (opt_group != NULL) + mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,opt_group); + else + mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); /* establish a connection to the server and error checking */ if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { @@ -248,6 +256,8 @@ process_arguments (int argc, char **argv) {"database", required_argument, 0, 'd'}, {"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'}, + {"file", required_argument, 0, 'f'}, + {"group", required_argument, 0, 'g'}, {"port", required_argument, 0, 'P'}, {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, @@ -262,7 +272,7 @@ process_arguments (int argc, char **argv) return ERROR; while (1) { - c = getopt_long (argc, argv, "hvVSP:p:u:d:H:s:c:w:", longopts, &option); + c = getopt_long (argc, argv, "hvVSP:p:u:d:f:g:H:s:c:w:", longopts, &option); if (c == -1 || c == EOF) break; @@ -294,6 +304,12 @@ process_arguments (int argc, char **argv) optarg++; } break; + case 'f': /* username */ + opt_file = optarg; + break; + case 'g': /* username */ + opt_group = optarg; + break; case 'P': /* critical time threshold */ db_port = atoi (optarg); break; @@ -335,6 +351,10 @@ process_arguments (int argc, char **argv) } else if (db_user == NULL) db_user = argv[c++]; + else if (opt_file == NULL) + opt_file = argv[c++]; + else if (opt_group == NULL) + opt_group = argv[c++]; else if (db_pass == NULL) db_pass = argv[c++]; else if (db == NULL) @@ -355,6 +375,12 @@ validate_arguments (void) if (db_user == NULL) db_user = strdup(""); + if (opt_file == NULL) + opt_file = strdup(""); + + if (opt_group == NULL) + opt_group = strdup(""); + if (db_host == NULL) db_host = strdup(""); @@ -369,7 +395,7 @@ void print_help (void) { char *myport; - xasprintf (&myport, "%d", MYSQL_PORT); + asprintf (&myport, "%d", MYSQL_PORT); print_revision (progname, NP_VERSION); @@ -390,6 +416,10 @@ print_help (void) printf (" %s\n", "-d, --database=STRING"); printf (" %s\n", _("Check database with indicated name")); + printf (" %s\n", "-f, --file=STRING"); + printf (" %s\n", _("Read from the specified client options file")); + printf (" %s\n", "-g, --group=STRING"); + printf (" %s\n", _("Use a client options group")); printf (" %s\n", "-u, --username=STRING"); printf (" %s\n", _("Connect using the indicated username")); printf (" %s\n", "-p, --password=STRING"); @@ -424,5 +454,6 @@ print_usage (void) { printf ("%s\n", _("Usage:")); printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); - printf (" [-u user] [-p password] [-S]\n"); + printf (" [-u user] [-p password] [-S] [-f optfile]\n"); + printf (" [-g group]\n"); } |