check_dbi: add output format parameter

This commit is contained in:
Lorenz Kästle 2025-10-29 23:27:31 +01:00
parent 071de8a73a
commit 408783f53d
2 changed files with 24 additions and 0 deletions

View file

@ -100,6 +100,10 @@ int main(int argc, char **argv) {
const check_dbi_config config = tmp.config;
if (config.output_format_is_set) {
mp_set_format(config.output_format);
}
/* Set signal handling and alarm */
if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) {
usage4(_("Cannot catch SIGALRM"));
@ -421,6 +425,9 @@ int main(int argc, char **argv) {
/* process command-line arguments */
check_dbi_config_wrapper process_arguments(int argc, char **argv) {
enum {
output_format_index = CHAR_MAX + 1,
};
int option = 0;
static struct option longopts[] = {STD_LONG_OPTS,
@ -432,6 +439,7 @@ check_dbi_config_wrapper process_arguments(int argc, char **argv) {
{"option", required_argument, 0, 'o'},
{"query", required_argument, 0, 'q'},
{"database", required_argument, 0, 'D'},
{"output-format", required_argument, 0, output_format_index},
{0, 0, 0, 0}};
check_dbi_config_wrapper result = {
@ -556,6 +564,18 @@ check_dbi_config_wrapper process_arguments(int argc, char **argv) {
case 'D':
result.config.dbi_database = optarg;
break;
case output_format_index: {
parsed_output_format parser = mp_parse_output_format(optarg);
if (!parser.parsing_success) {
// TODO List all available formats here, maybe add anothoer usage function
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;
}
}
}

View file

@ -38,6 +38,8 @@ typedef struct {
char *critical_range;
thresholds *dbi_thresholds;
bool output_format_is_set;
mp_output_format output_format;
} check_dbi_config;
check_dbi_config check_dbi_config_init() {
@ -58,6 +60,8 @@ check_dbi_config check_dbi_config_init() {
.warning_range = NULL,
.critical_range = NULL,
.dbi_thresholds = NULL,
.output_format_is_set = false,
};
return tmp;
}