summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
authorJonathan Milby <jon@uky.edu>2012-12-28 17:40:23 (GMT)
committerJonathan Milby <jon@uky.edu>2012-12-28 17:40:23 (GMT)
commit5ed7194c7e1f6c46c9b40dccbe760dfef853bae1 (patch)
tree21b9ca9a015ce957893ec736e249e4650b34bdd2 /plugins/check_mysql.c
parent1845c4cdf98fe9cf4bc95b6e11ae94cec1dcd4cc (diff)
downloadmonitoring-plugins-5ed7194c7e1f6c46c9b40dccbe760dfef853bae1.tar.gz
Updated check_mysql.c to take client options file and group parametersrefs/pull/32/head
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 4fbdc2b..cacc6c2 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -49,6 +49,8 @@ char *db_host = NULL;
49char *db_socket = NULL; 49char *db_socket = NULL;
50char *db_pass = NULL; 50char *db_pass = NULL;
51char *db = NULL; 51char *db = NULL;
52char *opt_file = NULL;
53char *opt_group = NULL;
52unsigned int db_port = MYSQL_PORT; 54unsigned int db_port = MYSQL_PORT;
53int check_slave = 0, warn_sec = 0, crit_sec = 0; 55int check_slave = 0, warn_sec = 0, crit_sec = 0;
54int verbose = 0; 56int verbose = 0;
@@ -86,8 +88,14 @@ main (int argc, char **argv)
86 88
87 /* initialize mysql */ 89 /* initialize mysql */
88 mysql_init (&mysql); 90 mysql_init (&mysql);
91
92 if (opt_file != NULL)
93 mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file);
89 94
90 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); 95 if (opt_group != NULL)
96 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,opt_group);
97 else
98 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client");
91 99
92 /* establish a connection to the server and error checking */ 100 /* establish a connection to the server and error checking */
93 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { 101 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)
248 {"database", required_argument, 0, 'd'}, 256 {"database", required_argument, 0, 'd'},
249 {"username", required_argument, 0, 'u'}, 257 {"username", required_argument, 0, 'u'},
250 {"password", required_argument, 0, 'p'}, 258 {"password", required_argument, 0, 'p'},
259 {"file", required_argument, 0, 'f'},
260 {"group", required_argument, 0, 'g'},
251 {"port", required_argument, 0, 'P'}, 261 {"port", required_argument, 0, 'P'},
252 {"critical", required_argument, 0, 'c'}, 262 {"critical", required_argument, 0, 'c'},
253 {"warning", required_argument, 0, 'w'}, 263 {"warning", required_argument, 0, 'w'},
@@ -262,7 +272,7 @@ process_arguments (int argc, char **argv)
262 return ERROR; 272 return ERROR;
263 273
264 while (1) { 274 while (1) {
265 c = getopt_long (argc, argv, "hvVSP:p:u:d:H:s:c:w:", longopts, &option); 275 c = getopt_long (argc, argv, "hvVSP:p:u:d:f:g:H:s:c:w:", longopts, &option);
266 276
267 if (c == -1 || c == EOF) 277 if (c == -1 || c == EOF)
268 break; 278 break;
@@ -294,6 +304,12 @@ process_arguments (int argc, char **argv)
294 optarg++; 304 optarg++;
295 } 305 }
296 break; 306 break;
307 case 'f': /* username */
308 opt_file = optarg;
309 break;
310 case 'g': /* username */
311 opt_group = optarg;
312 break;
297 case 'P': /* critical time threshold */ 313 case 'P': /* critical time threshold */
298 db_port = atoi (optarg); 314 db_port = atoi (optarg);
299 break; 315 break;
@@ -335,6 +351,10 @@ process_arguments (int argc, char **argv)
335 } 351 }
336 else if (db_user == NULL) 352 else if (db_user == NULL)
337 db_user = argv[c++]; 353 db_user = argv[c++];
354 else if (opt_file == NULL)
355 opt_file = argv[c++];
356 else if (opt_group == NULL)
357 opt_group = argv[c++];
338 else if (db_pass == NULL) 358 else if (db_pass == NULL)
339 db_pass = argv[c++]; 359 db_pass = argv[c++];
340 else if (db == NULL) 360 else if (db == NULL)
@@ -355,6 +375,12 @@ validate_arguments (void)
355 if (db_user == NULL) 375 if (db_user == NULL)
356 db_user = strdup(""); 376 db_user = strdup("");
357 377
378 if (opt_file == NULL)
379 opt_file = strdup("");
380
381 if (opt_group == NULL)
382 opt_group = strdup("");
383
358 if (db_host == NULL) 384 if (db_host == NULL)
359 db_host = strdup(""); 385 db_host = strdup("");
360 386
@@ -369,7 +395,7 @@ void
369print_help (void) 395print_help (void)
370{ 396{
371 char *myport; 397 char *myport;
372 xasprintf (&myport, "%d", MYSQL_PORT); 398 asprintf (&myport, "%d", MYSQL_PORT);
373 399
374 print_revision (progname, NP_VERSION); 400 print_revision (progname, NP_VERSION);
375 401
@@ -390,6 +416,10 @@ print_help (void)
390 416
391 printf (" %s\n", "-d, --database=STRING"); 417 printf (" %s\n", "-d, --database=STRING");
392 printf (" %s\n", _("Check database with indicated name")); 418 printf (" %s\n", _("Check database with indicated name"));
419 printf (" %s\n", "-f, --file=STRING");
420 printf (" %s\n", _("Read from the specified client options file"));
421 printf (" %s\n", "-g, --group=STRING");
422 printf (" %s\n", _("Use a client options group"));
393 printf (" %s\n", "-u, --username=STRING"); 423 printf (" %s\n", "-u, --username=STRING");
394 printf (" %s\n", _("Connect using the indicated username")); 424 printf (" %s\n", _("Connect using the indicated username"));
395 printf (" %s\n", "-p, --password=STRING"); 425 printf (" %s\n", "-p, --password=STRING");
@@ -424,5 +454,6 @@ print_usage (void)
424{ 454{
425 printf ("%s\n", _("Usage:")); 455 printf ("%s\n", _("Usage:"));
426 printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); 456 printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname);
427 printf (" [-u user] [-p password] [-S]\n"); 457 printf (" [-u user] [-p password] [-S] [-f optfile]\n");
458 printf (" [-g group]\n");
428} 459}