From 9bbc76483888c9e2ef2f4ed281c0ab8f2aab7bb6 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 8 Jun 2026 08:23:44 +0200 Subject: Ok summary (#2270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib: implement functionality to set ok summary * check_load: implement setting ok summary * OK summary for ntp_peer, ntp_time and users * check_apt: implement ok summary * check_curl: implement ok summary * check_disk: implement ok summary * check_dbi: implement ok summary * check_ldap: auto formatting * check_ldap: implement ok summary * check_ssh: implement ok summary * check_tcp: implement ok summary * fixup! check_curl: implement ok summary * fixup! check_dbi: implement ok summary * fixup! check_ldap: implement ok summary * fixup! check_ssh: implement ok summary * fixup! check_tcp: implement ok summary * check_apt: remove illegal free * check_mrtg: fix link * check_mrtg: implement ok summary * check_mrtgtraf: fix link * check_mrtgtraf: implement ok summary * check_mysql: implement ok summary * check_mysql_query: implement ok summary * check_pgsql: implement ok summary * check_radius: implement ok summary * check_real: implement ok summary * check_smtp: implement ok summary * check_snmp: implement ok summary * check_swap: implement ok summary * check_ups: add OK summary --------- Co-authored-by: Lorenz Kästle --- lib/output.c | 26 +++++++++++++------------- lib/output.h | 2 ++ 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/output.c b/lib/output.c index 9bcd02d9..b1e91231 100644 --- a/lib/output.c +++ b/lib/output.c @@ -105,6 +105,7 @@ static inline char *fmt_subcheck_perfdata(mp_subcheck check) { */ mp_check mp_check_init(void) { mp_check check = { + .ok_summary = NULL, .evaluation_function = &mp_eval_check_default, .default_output_override = NULL, .default_output_override_content = NULL, @@ -211,6 +212,14 @@ int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck subchec */ void mp_set_summary(mp_check check[static 1], char *summary) { check->summary = strdup(summary); } +/* + * set the summary for the OK state + * this allows to set the content in the first line of the plugin + * if the overall state is OK + */ +void mp_set_ok_summary(mp_check check[static 1], char *ok_summary) { + check->ok_summary = strdup(ok_summary); +} /* * Generate the summary string of a mp_check object based on its subchecks */ @@ -255,21 +264,12 @@ char *get_subcheck_summary(mp_check check) { } if (result == NULL) { - if (ok_count > 0) { + // Nothing in result yet, we must be in an OK state + if (check.ok_summary != NULL) { + asprintf(&result, "%s", check.ok_summary); + } else if (ok_count > 0) { asprintf(&result, "ok=%d", ok_count); } - - if (warning_count > 0) { - asprintf(&result, "%swarning=%d", (result == NULL ? "" : ", "), warning_count); - } - - if (critical_count > 0) { - asprintf(&result, "%scritical=%d", (result == NULL ? "" : ", "), critical_count); - } - - if (unknown_count > 0) { - asprintf(&result, "%sunknown=%d", (result == NULL ? "" : ", "), unknown_count); - } } return result; diff --git a/lib/output.h b/lib/output.h index 6ca63cfe..b9cdb07d 100644 --- a/lib/output.h +++ b/lib/output.h @@ -66,6 +66,7 @@ mp_output_detail_level mp_get_level_of_detail(void); typedef struct mp_check mp_check; struct mp_check { char *summary; // Overall summary, if not set a summary will be automatically generated + char *ok_summary; // (optional) Summary if the overall state is OK mp_subcheck_list *subchecks; // the evaluation_functions computes the state of check @@ -88,6 +89,7 @@ int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck); void mp_add_perfdata_to_subcheck(mp_subcheck check[static 1], mp_perfdata); void mp_set_summary(mp_check check[static 1], char *summary); +void mp_set_ok_summary(mp_check check[static 1], char *ok_summary); mp_state_enum mp_compute_check_state(mp_check); mp_state_enum mp_compute_subcheck_state(mp_subcheck); -- cgit v1.2.3-74-g34f1