diff options
author | Juan Carlos Fernandez <jcfernandez@cediant.es> | 2013-05-22 16:35:17 (GMT) |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-17 23:28:13 (GMT) |
commit | 8e66a58d41bfeff62ad7e3f222cf65cf8a633ca5 (patch) | |
tree | b89c35a1f48d6a1eff2f6106f7d4933ba324a740 | |
parent | 0738903dbc57a41d18d40f15656f63abbf25f4b1 (diff) | |
download | monitoring-plugins-8e66a58d41bfeff62ad7e3f222cf65cf8a633ca5.tar.gz |
Added ssl support to check_myslq
-rw-r--r-- | plugins/check_mysql.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 51579c2..18c884c 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
@@ -49,6 +49,12 @@ char *db_host = NULL; | |||
49 | char *db_socket = NULL; | 49 | char *db_socket = NULL; |
50 | char *db_pass = NULL; | 50 | char *db_pass = NULL; |
51 | char *db = NULL; | 51 | char *db = NULL; |
52 | char *ca_cert = NULL; | ||
53 | char *ca_path = NULL; | ||
54 | char *cert = NULL; | ||
55 | char *key = NULL; | ||
56 | char *cipher = NULL; | ||
57 | bool ssl = false; | ||
52 | unsigned int db_port = MYSQL_PORT; | 58 | unsigned int db_port = MYSQL_PORT; |
53 | int check_slave = 0, warn_sec = 0, crit_sec = 0; | 59 | int check_slave = 0, warn_sec = 0, crit_sec = 0; |
54 | int verbose = 0; | 60 | int verbose = 0; |
@@ -89,6 +95,8 @@ main (int argc, char **argv) | |||
89 | 95 | ||
90 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); | 96 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); |
91 | 97 | ||
98 | if (ssl) | ||
99 | mysql_ssl_set(&mysql,key,cert,ca_cert,ca_path,cipher); | ||
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)) { |
94 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) | 102 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) |
@@ -260,6 +268,12 @@ process_arguments (int argc, char **argv) | |||
260 | {"verbose", no_argument, 0, 'v'}, | 268 | {"verbose", no_argument, 0, 'v'}, |
261 | {"version", no_argument, 0, 'V'}, | 269 | {"version", no_argument, 0, 'V'}, |
262 | {"help", no_argument, 0, 'h'}, | 270 | {"help", no_argument, 0, 'h'}, |
271 | {"ssl", no_argument, 0, 'l'}, | ||
272 | {"ca_cert", optional_argument, 0, 'A'}, | ||
273 | {"key", required_argument,0,'k'}, | ||
274 | {"cert", required_argument,0,'a'}, | ||
275 | {"ca_path", required_argument, 0, 'F'}, | ||
276 | {"cipher", required_argument, 0, 'C'}, | ||
263 | {0, 0, 0, 0} | 277 | {0, 0, 0, 0} |
264 | }; | 278 | }; |
265 | 279 | ||
@@ -267,7 +281,7 @@ process_arguments (int argc, char **argv) | |||
267 | return ERROR; | 281 | return ERROR; |
268 | 282 | ||
269 | while (1) { | 283 | while (1) { |
270 | c = getopt_long (argc, argv, "hvVSP:p:u:d:H:s:c:w:", longopts, &option); | 284 | c = getopt_long (argc, argv, "hlvVSP:p:u:d:H:s:c:w:A:a:k:F:C:", longopts, &option); |
271 | 285 | ||
272 | if (c == -1 || c == EOF) | 286 | if (c == -1 || c == EOF) |
273 | break; | 287 | break; |
@@ -287,6 +301,24 @@ process_arguments (int argc, char **argv) | |||
287 | case 'd': /* database */ | 301 | case 'd': /* database */ |
288 | db = optarg; | 302 | db = optarg; |
289 | break; | 303 | break; |
304 | case 'l': | ||
305 | ssl = true; | ||
306 | break; | ||
307 | case 'A': | ||
308 | ca_cert = optarg; | ||
309 | break; | ||
310 | case 'a': | ||
311 | cert = optarg; | ||
312 | break; | ||
313 | case 'k': | ||
314 | key = optarg; | ||
315 | break; | ||
316 | case 'F': | ||
317 | ca_path = optarg; | ||
318 | break; | ||
319 | case 'C': | ||
320 | cipher = optarg; | ||
321 | break; | ||
290 | case 'u': /* username */ | 322 | case 'u': /* username */ |
291 | db_user = optarg; | 323 | db_user = optarg; |
292 | break; | 324 | break; |
@@ -409,6 +441,19 @@ print_help (void) | |||
409 | printf (" %s\n", "-c, --critical"); | 441 | printf (" %s\n", "-c, --critical"); |
410 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); | 442 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); |
411 | printf (" %s\n", _("behind master")); | 443 | printf (" %s\n", _("behind master")); |
444 | printf (" %s\n", "-l, --ssl"); | ||
445 | printf (" %s\n", _("Use ssl encryptation")); | ||
446 | printf (" %s\n", "-A, --ca_cert"); | ||
447 | printf (" %s\n", _("Path to CA signing the cert")); | ||
448 | printf (" %s\n", "-a, --cert"); | ||
449 | printf (" %s\n", _("Path to certificate to use for encriptation")); | ||
450 | printf (" %s\n", "-k, --key"); | ||
451 | printf (" %s\n", _("Path to certificate key")); | ||
452 | printf (" %s\n", "-F, --ca_path"); | ||
453 | printf (" %s\n", _("Path to CA dir")); | ||
454 | printf (" %s\n", "-C, --cipher"); | ||
455 | printf (" %s\n", _("List of valid cipher to use for encriptation")); | ||
456 | |||
412 | 457 | ||
413 | printf ("\n"); | 458 | printf ("\n"); |
414 | printf (" %s\n", _("There are no required arguments. By default, the local database is checked")); | 459 | printf (" %s\n", _("There are no required arguments. By default, the local database is checked")); |
@@ -429,5 +474,6 @@ print_usage (void) | |||
429 | { | 474 | { |
430 | printf ("%s\n", _("Usage:")); | 475 | printf ("%s\n", _("Usage:")); |
431 | printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); | 476 | printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); |
432 | printf (" [-u user] [-p password] [-S]\n"); | 477 | printf (" [-u user] [-p password] [-S] [-l] [-A ca] [-a cert]\n"); |
478 | printf (" [-k key] [-F ca_dir] [-C cipher]\n"); | ||
433 | } | 479 | } |