diff options
Diffstat (limited to 'lib/output.h')
| -rw-r--r-- | lib/output.h | 117 | 
1 files changed, 117 insertions, 0 deletions
| diff --git a/lib/output.h b/lib/output.h new file mode 100644 index 00000000..c63c8e3f --- /dev/null +++ b/lib/output.h | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../config.h" | ||
| 4 | #include "./perfdata.h" | ||
| 5 | #include "./states.h" | ||
| 6 | |||
| 7 | /* | ||
| 8 | * A partial check result | ||
| 9 | */ | ||
| 10 | typedef struct mp_subcheck mp_subcheck; | ||
| 11 | struct mp_subcheck { | ||
| 12 | mp_state_enum state; // OK, Warning, Critical ... set explicitly | ||
| 13 | mp_state_enum default_state; // OK, Warning, Critical .. if not set explicitly | ||
| 14 | bool state_set_explicitly; // was the state set explicitly (or should it be derived from | ||
| 15 | // subchecks) | ||
| 16 | |||
| 17 | char *output; // Text output for humans ("Filesystem xyz is fine", "Could not create TCP | ||
| 18 | // connection to..") | ||
| 19 | pd_list *perfdata; // Performance data for this check | ||
| 20 | struct subcheck_list *subchecks; // subchecks deeper in the hierarchy | ||
| 21 | |||
| 22 | // the evaluation_functions computes the state of subcheck | ||
| 23 | mp_state_enum (*evaluation_function)(mp_subcheck); | ||
| 24 | }; | ||
| 25 | |||
| 26 | /* | ||
| 27 | * A list of subchecks, used in subchecks and the main check | ||
| 28 | */ | ||
| 29 | typedef struct subcheck_list { | ||
| 30 | mp_subcheck subcheck; | ||
| 31 | struct subcheck_list *next; | ||
| 32 | } mp_subcheck_list; | ||
| 33 | |||
| 34 | /* | ||
| 35 | * Possible output formats | ||
| 36 | */ | ||
| 37 | typedef enum output_format { | ||
| 38 | MP_FORMAT_MULTI_LINE, | ||
| 39 | MP_FORMAT_TEST_JSON, | ||
| 40 | } mp_output_format; | ||
| 41 | |||
| 42 | #define MP_FORMAT_DEFAULT MP_FORMAT_MULTI_LINE | ||
| 43 | |||
| 44 | /* | ||
| 45 | * Format related functions | ||
| 46 | */ | ||
| 47 | void mp_set_format(mp_output_format format); | ||
| 48 | mp_output_format mp_get_format(void); | ||
| 49 | |||
| 50 | // Output detail level | ||
| 51 | |||
| 52 | typedef enum output_detail_level { | ||
| 53 | MP_DETAIL_ALL, | ||
| 54 | MP_DETAIL_NON_OK_ONLY, | ||
| 55 | } mp_output_detail_level; | ||
| 56 | |||
| 57 | void mp_set_level_of_detail(mp_output_detail_level level); | ||
| 58 | mp_output_detail_level mp_get_level_of_detail(void); | ||
| 59 | |||
| 60 | /* | ||
| 61 | * The main state object of a plugin. Exists only ONCE per plugin. | ||
| 62 | * This is the "root" of a tree of singular checks. | ||
| 63 | * The final result is always derived from the children and the "worst" state | ||
| 64 | * in the first layer of subchecks | ||
| 65 | */ | ||
| 66 | typedef struct mp_check mp_check; | ||
| 67 | struct mp_check { | ||
| 68 | char *summary; // Overall summary, if not set a summary will be automatically generated | ||
| 69 | mp_subcheck_list *subchecks; | ||
| 70 | |||
| 71 | // the evaluation_functions computes the state of check | ||
| 72 | mp_state_enum (*evaluation_function)(mp_check); | ||
| 73 | }; | ||
| 74 | |||
| 75 | mp_check mp_check_init(void); | ||
| 76 | mp_subcheck mp_subcheck_init(void); | ||
| 77 | |||
| 78 | mp_subcheck mp_set_subcheck_state(mp_subcheck, mp_state_enum); | ||
| 79 | mp_subcheck mp_set_subcheck_default_state(mp_subcheck, mp_state_enum); | ||
| 80 | |||
| 81 | int mp_add_subcheck_to_check(mp_check check[static 1], mp_subcheck); | ||
| 82 | int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck); | ||
| 83 | |||
| 84 | void mp_add_perfdata_to_subcheck(mp_subcheck check[static 1], mp_perfdata); | ||
| 85 | |||
| 86 | void mp_add_summary(mp_check check[static 1], char *summary); | ||
| 87 | |||
| 88 | mp_state_enum mp_compute_check_state(mp_check); | ||
| 89 | mp_state_enum mp_compute_subcheck_state(mp_subcheck); | ||
| 90 | |||
| 91 | mp_state_enum mp_eval_ok(mp_check overall); | ||
| 92 | mp_state_enum mp_eval_warning(mp_check overall); | ||
| 93 | mp_state_enum mp_eval_critical(mp_check overall); | ||
| 94 | mp_state_enum mp_eval_unknown(mp_check overall); | ||
| 95 | mp_state_enum mp_eval_check_default(mp_check check); | ||
| 96 | mp_state_enum mp_eval_subcheck_default(mp_subcheck subcheck); | ||
| 97 | |||
| 98 | typedef struct { | ||
| 99 | bool parsing_success; | ||
| 100 | mp_output_format output_format; | ||
| 101 | } parsed_output_format; | ||
| 102 | parsed_output_format mp_parse_output_format(char *format_string); | ||
| 103 | |||
| 104 | // TODO free and stuff | ||
| 105 | // void mp_cleanup_check(mp_check check[static 1]); | ||
| 106 | |||
| 107 | char *mp_fmt_output(mp_check); | ||
| 108 | |||
| 109 | void mp_print_output(mp_check); | ||
| 110 | |||
| 111 | /* | ||
| 112 | * ================== | ||
| 113 | * Exit functionality | ||
| 114 | * ================== | ||
| 115 | */ | ||
| 116 | |||
| 117 | void mp_exit(mp_check) __attribute__((noreturn)); | ||
