[monitoring-plugins] Make multiline output look better

Lorenz Kästle git at monitoring-plugins.org
Sun Jul 6 23:40:12 CEST 2025


 Module: monitoring-plugins
 Branch: master
 Commit: bb4ce15997a3023c5c4f2bb434b37699797272da
 Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
   Date: Sun Jul  6 22:47:01 2025 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=bb4ce159

Make multiline output look better

---

 lib/output.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/output.c b/lib/output.c
index 61fbf832..fbde490e 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -332,7 +332,37 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
 	mp_subcheck_list *subchecks = NULL;
 
 	switch (output_format) {
-	case MP_FORMAT_MULTI_LINE:
+	case MP_FORMAT_MULTI_LINE: {
+		char *tmp_string = NULL;
+		if ((tmp_string = strchr(check.output, '\n')) != NULL) {
+			// This is a multiline string, put the correct indentation in before proceeding
+			char *intermediate_string = "";
+			bool have_residual_chars = false;
+
+			while (tmp_string != NULL) {
+				*tmp_string = '\0';
+				xasprintf(&intermediate_string, "%s%s\n%s", intermediate_string,check.output, generate_indentation_string(indentation+1)); // one more indentation to make it look better
+
+				if (*(tmp_string + 1) != '\0') {
+					check.output = tmp_string + 1;
+					have_residual_chars = true;
+				} else {
+					// Null after the \n, so this is the end
+					have_residual_chars = false;
+					break;
+				}
+
+				tmp_string = strchr(check.output, '\n');
+			}
+
+			// add the rest (if any)
+			if (have_residual_chars) {
+				char *tmp = check.output;
+				xasprintf(&check.output, "%s\n%s%s", intermediate_string, generate_indentation_string(indentation+1), tmp);
+			} else {
+				check.output = intermediate_string;
+			}
+		}
 		asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation), state_text(mp_compute_subcheck_state(check)),
 				 check.output);
 
@@ -343,6 +373,7 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
 			subchecks = subchecks->next;
 		}
 		return result;
+	}
 	default:
 		die(STATE_UNKNOWN, "Invalid format");
 	}



More information about the Commits mailing list