summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/output.c12
-rw-r--r--lib/output.h7
-rw-r--r--plugins/check_ssh.c2
-rw-r--r--plugins/check_swap.c2
4 files changed, 17 insertions, 6 deletions
diff --git a/lib/output.c b/lib/output.c
index 17919afc..61fbf832 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -11,6 +11,9 @@
11#include "perfdata.h" 11#include "perfdata.h"
12#include "states.h" 12#include "states.h"
13 13
14// == Global variables
15static mp_output_format output_format = MP_FORMAT_DEFAULT;
16
14// == Prototypes == 17// == Prototypes ==
15static char *fmt_subcheck_output(mp_output_format output_format, mp_subcheck check, unsigned int indentation); 18static char *fmt_subcheck_output(mp_output_format output_format, mp_subcheck check, unsigned int indentation);
16static inline cJSON *json_serialize_subcheck(mp_subcheck subcheck); 19static inline cJSON *json_serialize_subcheck(mp_subcheck subcheck);
@@ -55,7 +58,6 @@ static inline char *fmt_subcheck_perfdata(mp_subcheck check) {
55 */ 58 */
56mp_check mp_check_init(void) { 59mp_check mp_check_init(void) {
57 mp_check check = {0}; 60 mp_check check = {0};
58 check.format = MP_FORMAT_DEFAULT;
59 return check; 61 return check;
60} 62}
61 63
@@ -234,7 +236,7 @@ mp_state_enum mp_compute_check_state(const mp_check check) {
234char *mp_fmt_output(mp_check check) { 236char *mp_fmt_output(mp_check check) {
235 char *result = NULL; 237 char *result = NULL;
236 238
237 switch (check.format) { 239 switch (output_format) {
238 case MP_FORMAT_MULTI_LINE: { 240 case MP_FORMAT_MULTI_LINE: {
239 if (check.summary == NULL) { 241 if (check.summary == NULL) {
240 check.summary = get_subcheck_summary(check); 242 check.summary = get_subcheck_summary(check);
@@ -482,7 +484,7 @@ void mp_print_output(mp_check check) { puts(mp_fmt_output(check)); }
482 */ 484 */
483void mp_exit(mp_check check) { 485void mp_exit(mp_check check) {
484 mp_print_output(check); 486 mp_print_output(check);
485 if (check.format == MP_FORMAT_TEST_JSON) { 487 if (output_format == MP_FORMAT_TEST_JSON) {
486 exit(0); 488 exit(0);
487 } 489 }
488 490
@@ -533,3 +535,7 @@ parsed_output_format mp_parse_output_format(char *format_string) {
533 535
534 return result; 536 return result;
535} 537}
538
539void mp_set_format(mp_output_format format) { output_format = format; }
540
541mp_output_format mp_get_format(void) { return output_format; }
diff --git a/lib/output.h b/lib/output.h
index ffc36f53..2bdfa074 100644
--- a/lib/output.h
+++ b/lib/output.h
@@ -36,13 +36,18 @@ typedef enum output_format {
36#define MP_FORMAT_DEFAULT MP_FORMAT_MULTI_LINE 36#define MP_FORMAT_DEFAULT MP_FORMAT_MULTI_LINE
37 37
38/* 38/*
39 * Format related functions
40 */
41 void mp_set_format(mp_output_format format);
42 mp_output_format mp_get_format(void);
43
44/*
39 * The main state object of a plugin. Exists only ONCE per plugin. 45 * The main state object of a plugin. Exists only ONCE per plugin.
40 * This is the "root" of a tree of singular checks. 46 * This is the "root" of a tree of singular checks.
41 * The final result is always derived from the children and the "worst" state 47 * The final result is always derived from the children and the "worst" state
42 * in the first layer of subchecks 48 * in the first layer of subchecks
43 */ 49 */
44typedef struct { 50typedef struct {
45 mp_output_format format; // The output format
46 char *summary; // Overall summary, if not set a summary will be automatically generated 51 char *summary; // Overall summary, if not set a summary will be automatically generated
47 mp_subcheck_list *subchecks; 52 mp_subcheck_list *subchecks;
48} mp_check; 53} mp_check;
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index 2ad7af66..9d0d7cde 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -77,7 +77,7 @@ int main(int argc, char **argv) {
77 77
78 mp_check overall = mp_check_init(); 78 mp_check overall = mp_check_init();
79 if (config.output_format_is_set) { 79 if (config.output_format_is_set) {
80 overall.format = config.output_format; 80 mp_set_format(config.output_format);
81 } 81 }
82 82
83 /* initialize alarm signal handling */ 83 /* initialize alarm signal handling */
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 4d3b6099..cb95949a 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -93,7 +93,7 @@ int main(int argc, char **argv) {
93 double percent_used; 93 double percent_used;
94 mp_check overall = mp_check_init(); 94 mp_check overall = mp_check_init();
95 if (config.output_format_is_set) { 95 if (config.output_format_is_set) {
96 overall.format = config.output_format; 96 mp_set_format(config.output_format);
97 } 97 }
98 mp_subcheck sc1 = mp_subcheck_init(); 98 mp_subcheck sc1 = mp_subcheck_init();
99 sc1 = mp_set_subcheck_default_state(sc1, STATE_OK); 99 sc1 = mp_set_subcheck_default_state(sc1, STATE_OK);