summaryrefslogtreecommitdiffstats
path: root/lib/output.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output.c')
-rw-r--r--lib/output.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/output.c b/lib/output.c
index 62e1366d..54d505d9 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -61,6 +61,8 @@ static inline char *fmt_subcheck_perfdata(mp_subcheck check) {
61mp_check mp_check_init(void) { 61mp_check mp_check_init(void) {
62 mp_check check = { 62 mp_check check = {
63 .evaluation_function = &mp_eval_check_default, 63 .evaluation_function = &mp_eval_check_default,
64 .default_output_override = NULL,
65 .default_output_override_content = NULL,
64 }; 66 };
65 return check; 67 return check;
66} 68}
@@ -165,7 +167,7 @@ int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck subchec
165void mp_add_summary(mp_check check[static 1], char *summary) { check->summary = summary; } 167void mp_add_summary(mp_check check[static 1], char *summary) { check->summary = summary; }
166 168
167/* 169/*
168 * Generate the summary string of a mp_check object based on it's subchecks 170 * Generate the summary string of a mp_check object based on its subchecks
169 */ 171 */
170char *get_subcheck_summary(mp_check check) { 172char *get_subcheck_summary(mp_check check) {
171 mp_subcheck_list *subchecks = check.subchecks; 173 mp_subcheck_list *subchecks = check.subchecks;
@@ -175,7 +177,7 @@ char *get_subcheck_summary(mp_check check) {
175 unsigned int critical = 0; 177 unsigned int critical = 0;
176 unsigned int unknown = 0; 178 unsigned int unknown = 0;
177 while (subchecks != NULL) { 179 while (subchecks != NULL) {
178 switch (subchecks->subcheck.state) { 180 switch (mp_compute_subcheck_state(subchecks->subcheck)) {
179 case STATE_OK: 181 case STATE_OK:
180 ok++; 182 ok++;
181 break; 183 break;
@@ -243,7 +245,7 @@ mp_state_enum mp_compute_check_state(const mp_check check) {
243} 245}
244 246
245/* 247/*
246 * Generate the result state of a mp_check object based on it's own state and it's subchecks states 248 * Generate the result state of a mp_check object based on its own state and its subchecks states
247 */ 249 */
248mp_state_enum mp_eval_check_default(const mp_check check) { 250mp_state_enum mp_eval_check_default(const mp_check check) {
249 assert(check.subchecks != NULL); // a mp_check without subchecks is invalid, die here 251 assert(check.subchecks != NULL); // a mp_check without subchecks is invalid, die here
@@ -259,6 +261,21 @@ mp_state_enum mp_eval_check_default(const mp_check check) {
259 return result; 261 return result;
260} 262}
261 263
264// Remove troublesome symbols from plugin output
265char *sanitize_output_insitu(char *input) {
266 if (input == NULL) {
267 return input;
268 }
269
270 for (char *walker = input; *walker != '\0'; walker++) {
271 if (*walker == '|') {
272 *walker = ' ';
273 }
274 }
275
276 return input;
277}
278
262/* 279/*
263 * Generate output string for a mp_check object 280 * Generate output string for a mp_check object
264 * Non static to be available for testing functions 281 * Non static to be available for testing functions
@@ -268,6 +285,11 @@ char *mp_fmt_output(mp_check check) {
268 285
269 switch (output_format) { 286 switch (output_format) {
270 case MP_FORMAT_MULTI_LINE: { 287 case MP_FORMAT_MULTI_LINE: {
288 if (check.default_output_override != NULL) {
289 result = check.default_output_override(check.default_output_override_content);
290 break;
291 }
292
271 if (check.summary == NULL) { 293 if (check.summary == NULL) {
272 check.summary = get_subcheck_summary(check); 294 check.summary = get_subcheck_summary(check);
273 } 295 }
@@ -299,6 +321,8 @@ char *mp_fmt_output(mp_check check) {
299 subchecks = subchecks->next; 321 subchecks = subchecks->next;
300 } 322 }
301 323
324 result = sanitize_output_insitu(result);
325
302 if (pd_string != NULL && strlen(pd_string) > 0) { 326 if (pd_string != NULL && strlen(pd_string) > 0) {
303 asprintf(&result, "%s|%s", result, pd_string); 327 asprintf(&result, "%s|%s", result, pd_string);
304 } 328 }