mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-04-15 22:00:06 -04:00
Add output formatting option where they were forgotten
This commit is contained in:
parent
3657197cf7
commit
317ee266a8
5 changed files with 54 additions and 0 deletions
|
|
@ -688,6 +688,8 @@ void print_help(void) {
|
|||
|
||||
printf(UT_VERBOSE);
|
||||
|
||||
printf(UT_OUTPUT_FORMAT);
|
||||
|
||||
printf("\n");
|
||||
printf(" %s\n", _("A DBI driver (-d option) is required. If the specified metric operates"));
|
||||
printf(" %s\n\n", _("on a query, one has to be specified (-q option)."));
|
||||
|
|
|
|||
|
|
@ -96,6 +96,10 @@ int main(int argc, char **argv) {
|
|||
|
||||
const check_mysql_config config = tmp_config.config;
|
||||
|
||||
if (config.output_format_is_set) {
|
||||
mp_set_format(config.output_format);
|
||||
}
|
||||
|
||||
MYSQL mysql;
|
||||
/* initialize mysql */
|
||||
mysql_init(&mysql);
|
||||
|
|
@ -471,6 +475,7 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
enum {
|
||||
CHECK_REPLICA_OPT = CHAR_MAX + 1,
|
||||
output_format_index,
|
||||
};
|
||||
|
||||
static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
|
||||
|
|
@ -495,6 +500,7 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) {
|
|||
{"cert", required_argument, 0, 'a'},
|
||||
{"ca-dir", required_argument, 0, 'D'},
|
||||
{"ciphers", required_argument, 0, 'L'},
|
||||
{"output-format", required_argument, 0, output_format_index},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_mysql_config_wrapper result = {
|
||||
|
|
@ -605,6 +611,17 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
case '?': /* help */
|
||||
usage5();
|
||||
case output_format_index: {
|
||||
parsed_output_format parser = mp_parse_output_format(optarg);
|
||||
if (!parser.parsing_success) {
|
||||
printf("Invalid output format: %s\n", optarg);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
result.config.output_format_is_set = true;
|
||||
result.config.output_format = parser.output_format;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -711,6 +728,8 @@ void print_help(void) {
|
|||
printf(" %s\n", "-L, --ciphers=STRING");
|
||||
printf(" %s\n", _("List of valid SSL ciphers"));
|
||||
|
||||
printf(UT_OUTPUT_FORMAT);
|
||||
|
||||
printf("\n");
|
||||
printf(" %s\n",
|
||||
_("There are no required arguments. By default, the local database is checked"));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../config.h"
|
||||
#include "output.h"
|
||||
#include "thresholds.h"
|
||||
#include <stddef.h>
|
||||
#include <mysql.h>
|
||||
|
|
@ -26,6 +27,8 @@ typedef struct {
|
|||
|
||||
mp_thresholds replica_thresholds;
|
||||
|
||||
bool output_format_is_set;
|
||||
mp_output_format output_format;
|
||||
} check_mysql_config;
|
||||
|
||||
check_mysql_config check_mysql_config_init() {
|
||||
|
|
@ -49,6 +52,8 @@ check_mysql_config check_mysql_config_init() {
|
|||
.ignore_auth = false,
|
||||
|
||||
.replica_thresholds = mp_thresholds_init(),
|
||||
|
||||
.output_format_is_set = false,
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ int main(int argc, char **argv) {
|
|||
|
||||
const check_mysql_query_config config = tmp_config.config;
|
||||
|
||||
if (config.output_format_is_set) {
|
||||
mp_set_format(config.output_format);
|
||||
}
|
||||
|
||||
MYSQL mysql;
|
||||
/* initialize mysql */
|
||||
mysql_init(&mysql);
|
||||
|
|
@ -185,6 +189,10 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* process command-line arguments */
|
||||
check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
|
||||
enum {
|
||||
output_format_index = CHAR_MAX + 1,
|
||||
};
|
||||
|
||||
static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
|
||||
{"socket", required_argument, 0, 's'},
|
||||
{"database", required_argument, 0, 'd'},
|
||||
|
|
@ -199,6 +207,7 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
|
|||
{"query", required_argument, 0, 'q'},
|
||||
{"warning", required_argument, 0, 'w'},
|
||||
{"critical", required_argument, 0, 'c'},
|
||||
{"output-format", required_argument, 0, output_format_index},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_mysql_query_config_wrapper result = {
|
||||
|
|
@ -282,6 +291,17 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
|
|||
} break;
|
||||
case '?': /* help */
|
||||
usage5();
|
||||
case output_format_index: {
|
||||
parsed_output_format parser = mp_parse_output_format(optarg);
|
||||
if (!parser.parsing_success) {
|
||||
printf("Invalid output format: %s\n", optarg);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
result.config.output_format_is_set = true;
|
||||
result.config.output_format = parser.output_format;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -344,6 +364,8 @@ void print_help(void) {
|
|||
printf(" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!"));
|
||||
printf(" %s\n", _("Your clear-text password could be visible as a process table entry"));
|
||||
|
||||
printf(UT_OUTPUT_FORMAT);
|
||||
|
||||
printf("\n");
|
||||
printf(" %s\n", _("A query is required. The result from the query should be numeric."));
|
||||
printf(" %s\n", _("For extra security, create a user with minimal access."));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../config.h"
|
||||
#include "output.h"
|
||||
#include "thresholds.h"
|
||||
#include <mysql.h>
|
||||
|
||||
|
|
@ -16,6 +17,9 @@ typedef struct {
|
|||
|
||||
char *sql_query;
|
||||
mp_thresholds thresholds;
|
||||
|
||||
bool output_format_is_set;
|
||||
mp_output_format output_format;
|
||||
} check_mysql_query_config;
|
||||
|
||||
check_mysql_query_config check_mysql_query_config_init() {
|
||||
|
|
@ -31,6 +35,8 @@ check_mysql_query_config check_mysql_query_config_init() {
|
|||
|
||||
.sql_query = NULL,
|
||||
.thresholds = mp_thresholds_init(),
|
||||
|
||||
.output_format_is_set = false,
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue