summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorawiddersheim <awiddersheim@hotmail.com>2013-10-05 11:28:19 -0400
committerawiddersheim <awiddersheim@hotmail.com>2013-10-05 11:28:19 -0400
commitdccf53cf3833641d9865cbf946c6c1705a428fc5 (patch)
tree7d4e4ac28d70b884c0466a7062b4aad4cbd12519
parentf6576c6db4eeb655f16a71286757e4a93792887d (diff)
downloadmonitoring-plugins-dccf53cf3833641d9865cbf946c6c1705a428fc5.tar.gz
Add ability to read from options file to check_mysql_query.c
This is the same code that was added to check_mysql.c in 5ed7194.
-rw-r--r--plugins/check_mysql_query.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index 0bb83c3e..2e961a7d 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -46,6 +46,8 @@ char *db_host = NULL;
46char *db_socket = NULL; 46char *db_socket = NULL;
47char *db_pass = NULL; 47char *db_pass = NULL;
48char *db = NULL; 48char *db = NULL;
49char *opt_file = NULL;
50char *opt_group = NULL;
49unsigned int db_port = MYSQL_PORT; 51unsigned int db_port = MYSQL_PORT;
50 52
51int process_arguments (int, char **); 53int process_arguments (int, char **);
@@ -83,7 +85,13 @@ main (int argc, char **argv)
83 /* initialize mysql */ 85 /* initialize mysql */
84 mysql_init (&mysql); 86 mysql_init (&mysql);
85 87
86 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); 88 if (opt_file != NULL)
89 mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file);
90
91 if (opt_group != NULL)
92 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,opt_group);
93 else
94 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client");
87 95
88 /* establish a connection to the server and error checking */ 96 /* establish a connection to the server and error checking */
89 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { 97 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
@@ -174,6 +182,8 @@ process_arguments (int argc, char **argv)
174 {"database", required_argument, 0, 'd'}, 182 {"database", required_argument, 0, 'd'},
175 {"username", required_argument, 0, 'u'}, 183 {"username", required_argument, 0, 'u'},
176 {"password", required_argument, 0, 'p'}, 184 {"password", required_argument, 0, 'p'},
185 {"file", required_argument, 0, 'f'},
186 {"group", required_argument, 0, 'g'},
177 {"port", required_argument, 0, 'P'}, 187 {"port", required_argument, 0, 'P'},
178 {"verbose", no_argument, 0, 'v'}, 188 {"verbose", no_argument, 0, 'v'},
179 {"version", no_argument, 0, 'V'}, 189 {"version", no_argument, 0, 'V'},
@@ -188,7 +198,7 @@ process_arguments (int argc, char **argv)
188 return ERROR; 198 return ERROR;
189 199
190 while (1) { 200 while (1) {
191 c = getopt_long (argc, argv, "hvVP:p:u:d:H:s:q:w:c:", longopts, &option); 201 c = getopt_long (argc, argv, "hvVP:p:u:d:H:s:q:w:c:f:g:", longopts, &option);
192 202
193 if (c == -1 || c == EOF) 203 if (c == -1 || c == EOF)
194 break; 204 break;
@@ -220,6 +230,12 @@ process_arguments (int argc, char **argv)
220 optarg++; 230 optarg++;
221 } 231 }
222 break; 232 break;
233 case 'f': /* client options file */
234 opt_file = optarg;
235 break;
236 case 'g': /* client options group */
237 opt_group = optarg;
238 break;
223 case 'P': /* critical time threshold */ 239 case 'P': /* critical time threshold */
224 db_port = atoi (optarg); 240 db_port = atoi (optarg);
225 break; 241 break;
@@ -299,6 +315,10 @@ print_help (void)
299 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)")); 315 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)"));
300 printf (" -d, --database=STRING\n"); 316 printf (" -d, --database=STRING\n");
301 printf (" %s\n", _("Database to check")); 317 printf (" %s\n", _("Database to check"));
318 printf (" %s\n", "-f, --file=STRING");
319 printf (" %s\n", _("Read from the specified client options file"));
320 printf (" %s\n", "-g, --group=STRING");
321 printf (" %s\n", _("Use a client options group"));
302 printf (" -u, --username=STRING\n"); 322 printf (" -u, --username=STRING\n");
303 printf (" %s\n", _("Username to login with")); 323 printf (" %s\n", _("Username to login with"));
304 printf (" -p, --password=STRING\n"); 324 printf (" -p, --password=STRING\n");