summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c67
1 files changed, 36 insertions, 31 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 9d8094c0..26730d4c 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -96,6 +96,10 @@ int main(int argc, char **argv) {
96 96
97 const check_mysql_config config = tmp_config.config; 97 const check_mysql_config config = tmp_config.config;
98 98
99 if (config.output_format_is_set) {
100 mp_set_format(config.output_format);
101 }
102
99 MYSQL mysql; 103 MYSQL mysql;
100 /* initialize mysql */ 104 /* initialize mysql */
101 mysql_init(&mysql); 105 mysql_init(&mysql);
@@ -341,37 +345,23 @@ int main(int argc, char **argv) {
341 int replica_io_field = -1; 345 int replica_io_field = -1;
342 int replica_sql_field = -1; 346 int replica_sql_field = -1;
343 int seconds_behind_field = -1; 347 int seconds_behind_field = -1;
344 int num_fields; 348 unsigned int num_fields = mysql_num_fields(res);
345 MYSQL_FIELD *fields; 349 MYSQL_FIELD *fields = mysql_fetch_fields(res);
346 num_fields = mysql_num_fields(res); 350 for (int i = 0; i < (int)num_fields; i++) {
347 fields = mysql_fetch_fields(res); 351 if ((strcasecmp(fields[i].name, "Slave_IO_Running") == 0) ||
348 for (int i = 0; i < num_fields; i++) { 352 (strcasecmp(fields[i].name, "Replica_IO_Running") == 0)) {
349 if (use_deprecated_slave_status) { 353 replica_io_field = i;
350 if (strcmp(fields[i].name, "Slave_IO_Running") == 0) { 354 continue;
351 replica_io_field = i; 355 }
352 continue; 356 if ((strcasecmp(fields[i].name, "Slave_SQL_Running") == 0) ||
353 } 357 (strcasecmp(fields[i].name, "Replica_SQL_Running") == 0)) {
354 if (strcmp(fields[i].name, "Slave_SQL_Running") == 0) { 358 replica_sql_field = i;
355 replica_sql_field = i; 359 continue;
356 continue; 360 }
357 } 361 if ((strcasecmp(fields[i].name, "Seconds_Behind_Master") == 0) ||
358 if (strcmp(fields[i].name, "Seconds_Behind_Master") == 0) { 362 (strcasecmp(fields[i].name, "Seconds_Behind_Source") == 0)) {
359 seconds_behind_field = i; 363 seconds_behind_field = i;
360 continue; 364 continue;
361 }
362 } else {
363 if (strcmp(fields[i].name, "Replica_IO_Running") == 0) {
364 replica_io_field = i;
365 continue;
366 }
367 if (strcmp(fields[i].name, "Replica_SQL_Running") == 0) {
368 replica_sql_field = i;
369 continue;
370 }
371 if (strcmp(fields[i].name, "Seconds_Behind_Source") == 0) {
372 seconds_behind_field = i;
373 continue;
374 }
375 } 365 }
376 } 366 }
377 367
@@ -471,6 +461,7 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) {
471 461
472 enum { 462 enum {
473 CHECK_REPLICA_OPT = CHAR_MAX + 1, 463 CHECK_REPLICA_OPT = CHAR_MAX + 1,
464 output_format_index,
474 }; 465 };
475 466
476 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, 467 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
@@ -495,6 +486,7 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) {
495 {"cert", required_argument, 0, 'a'}, 486 {"cert", required_argument, 0, 'a'},
496 {"ca-dir", required_argument, 0, 'D'}, 487 {"ca-dir", required_argument, 0, 'D'},
497 {"ciphers", required_argument, 0, 'L'}, 488 {"ciphers", required_argument, 0, 'L'},
489 {"output-format", required_argument, 0, output_format_index},
498 {0, 0, 0, 0}}; 490 {0, 0, 0, 0}};
499 491
500 check_mysql_config_wrapper result = { 492 check_mysql_config_wrapper result = {
@@ -605,6 +597,17 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) {
605 break; 597 break;
606 case '?': /* help */ 598 case '?': /* help */
607 usage5(); 599 usage5();
600 case output_format_index: {
601 parsed_output_format parser = mp_parse_output_format(optarg);
602 if (!parser.parsing_success) {
603 printf("Invalid output format: %s\n", optarg);
604 exit(STATE_UNKNOWN);
605 }
606
607 result.config.output_format_is_set = true;
608 result.config.output_format = parser.output_format;
609 break;
610 }
608 } 611 }
609 } 612 }
610 613
@@ -711,6 +714,8 @@ void print_help(void) {
711 printf(" %s\n", "-L, --ciphers=STRING"); 714 printf(" %s\n", "-L, --ciphers=STRING");
712 printf(" %s\n", _("List of valid SSL ciphers")); 715 printf(" %s\n", _("List of valid SSL ciphers"));
713 716
717 printf(UT_OUTPUT_FORMAT);
718
714 printf("\n"); 719 printf("\n");
715 printf(" %s\n", 720 printf(" %s\n",
716 _("There are no required arguments. By default, the local database is checked")); 721 _("There are no required arguments. By default, the local database is checked"));