summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-04-30 12:50:52 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-04-30 12:50:52 (GMT)
commitaca1e6a6cec40754c67d3cf229db2660c4685202 (patch)
treef9093f5eefea0dcf6745a6a92e17b74950a1efa3 /plugins/check_mysql.c
parent6f2ee45c932dfec9d9a1e651b39d18f98b2ef009 (diff)
downloadmonitoring-plugins-aca1e6a6cec40754c67d3cf229db2660c4685202.tar.gz
Add socket support to check_mysql*
Also clears the password from check_mysql command-line options git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1988 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index ea2e30d..3d7426d 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -50,6 +50,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
50 50
51char *db_user = NULL; 51char *db_user = NULL;
52char *db_host = NULL; 52char *db_host = NULL;
53char *db_socket = NULL;
53char *db_pass = NULL; 54char *db_pass = NULL;
54char *db = NULL; 55char *db = NULL;
55unsigned int db_port = MYSQL_PORT; 56unsigned int db_port = MYSQL_PORT;
@@ -90,7 +91,7 @@ main (int argc, char **argv)
90 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); 91 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client");
91 92
92 /* establish a connection to the server and error checking */ 93 /* establish a connection to the server and error checking */
93 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) { 94 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
94 if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) 95 if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
95 die (STATE_WARNING, "%s\n", mysql_error (&mysql)); 96 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
96 else if (mysql_errno (&mysql) == CR_VERSION_ERROR) 97 else if (mysql_errno (&mysql) == CR_VERSION_ERROR)
@@ -243,6 +244,7 @@ process_arguments (int argc, char **argv)
243 int option = 0; 244 int option = 0;
244 static struct option longopts[] = { 245 static struct option longopts[] = {
245 {"hostname", required_argument, 0, 'H'}, 246 {"hostname", required_argument, 0, 'H'},
247 {"socket", required_argument, 0, 's'},
246 {"database", required_argument, 0, 'd'}, 248 {"database", required_argument, 0, 'd'},
247 {"username", required_argument, 0, 'u'}, 249 {"username", required_argument, 0, 'u'},
248 {"password", required_argument, 0, 'p'}, 250 {"password", required_argument, 0, 'p'},
@@ -260,7 +262,7 @@ process_arguments (int argc, char **argv)
260 return ERROR; 262 return ERROR;
261 263
262 while (1) { 264 while (1) {
263 c = getopt_long (argc, argv, "hvVSP:p:u:d:H:c:w:", longopts, &option); 265 c = getopt_long (argc, argv, "hvVSP:p:u:d:H:s:c:w:", longopts, &option);
264 266
265 if (c == -1 || c == EOF) 267 if (c == -1 || c == EOF)
266 break; 268 break;
@@ -274,14 +276,23 @@ process_arguments (int argc, char **argv)
274 usage2 (_("Invalid hostname/address"), optarg); 276 usage2 (_("Invalid hostname/address"), optarg);
275 } 277 }
276 break; 278 break;
277 case 'd': /* hostname */ 279 case 's': /* socket */
280 db_socket = optarg;
281 break;
282 case 'd': /* database */
278 db = optarg; 283 db = optarg;
279 break; 284 break;
280 case 'u': /* username */ 285 case 'u': /* username */
281 db_user = optarg; 286 db_user = optarg;
282 break; 287 break;
283 case 'p': /* authentication information: password */ 288 case 'p': /* authentication information: password */
284 db_pass = optarg; 289 db_pass = strdup(optarg);
290
291 /* Delete the password from process list */
292 while (*optarg != '\0') {
293 *optarg = 'X';
294 optarg++;
295 }
285 break; 296 break;
286 case 'P': /* critical time threshold */ 297 case 'P': /* critical time threshold */
287 db_port = atoi (optarg); 298 db_port = atoi (optarg);
@@ -373,28 +384,33 @@ print_help (void)
373 384
374 print_usage (); 385 print_usage ();
375 386
376 printf (_(UT_HELP_VRSN)); 387 printf (_(UT_HELP_VRSN));
377 388
378 printf (_(UT_HOST_PORT), 'P', myport); 389 printf (_(UT_HOST_PORT), 'P', myport);
390 printf (" %s\n", "-s, --socket=STRING");
391 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)"));
379 392
380 printf (" %s\n", "-d, --database=STRING"); 393 printf (" %s\n", "-d, --database=STRING");
381 printf (" %s\n", _("Check database with indicated name")); 394 printf (" %s\n", _("Check database with indicated name"));
382 printf (" %s\n", "-u, --username=STRING"); 395 printf (" %s\n", "-u, --username=STRING");
383 printf (" %s\n", _("Connect using the indicated username")); 396 printf (" %s\n", _("Connect using the indicated username"));
384 printf (" %s\n", "-p, --password=STRING"); 397 printf (" %s\n", "-p, --password=STRING");
385 printf (" %s\n", _("Use the indicated password to authenticate the connection")); 398 printf (" %s\n", _("Use the indicated password to authenticate the connection"));
386 printf (" %s\n", _("==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==")); 399 printf (" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!"));
387 printf (" %s\n", _("Your clear-text password will be visible as a process table entry")); 400 printf (" %s\n", _("Your clear-text password could be visible as a process table entry"));
388 printf (" %s\n", "-S, --check-slave"); 401 printf (" %s\n", "-S, --check-slave");
389 printf (" %s\n", _("Check if the slave thread is running properly.")); 402 printf (" %s\n", _("Check if the slave thread is running properly."));
390 printf (" %s\n", "-w, --warning"); 403 printf (" %s\n", "-w, --warning");
391 printf (" %s\n", _("Exit with WARNING status if slave server is more than INTEGER seconds behind master")); 404 printf (" %s\n", _("Exit with WARNING status if slave server is more than INTEGER seconds"));
405 printf (" %s\n", _("behind master"));
392 printf (" %s\n", "-c, --critical"); 406 printf (" %s\n", "-c, --critical");
393 printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds behind master")); 407 printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds"));
408 printf (" %s\n", _("behind master"));
394 409
395 printf ("\n"); 410 printf ("\n");
396 printf (" %s\n", _("There are no required arguments. By default, the local database with")); 411 printf (" %s\n", _("There are no required arguments. By default, the local database is checked"));
397 printf (_(" a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT); 412 printf (" %s\n", _("using the default unix socket. You can force TCP on localhost by using an"));
413 printf (" %s\n", _("IP address or FQDN ('localhost' will use the socket as well)."));
398 414
399 printf (_(UT_SUPPORT)); 415 printf (_(UT_SUPPORT));
400} 416}
@@ -404,5 +420,6 @@ void
404print_usage (void) 420print_usage (void)
405{ 421{
406 printf (_("Usage:")); 422 printf (_("Usage:"));
407 printf ("%s [-d database] [-H host] [-P port] [-u user] [-p password] [-S]\n",progname); 423 printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname);
424 printf (" [-u user] [-p password] [-S]\n");
408} 425}