summaryrefslogtreecommitdiffstats
path: root/lib/output.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output.h')
-rw-r--r--lib/output.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/output.h b/lib/output.h
new file mode 100644
index 00000000..ffc36f53
--- /dev/null
+++ b/lib/output.h
@@ -0,0 +1,85 @@
1#pragma once
2
3#include "../config.h"
4#include "./perfdata.h"
5#include "./states.h"
6
7/*
8 * A partial check result
9 */
10typedef struct {
11 mp_state_enum state; // OK, Warning, Critical ... set explicitly
12 mp_state_enum default_state; // OK, Warning, Critical .. if not set explicitly
13 bool state_set_explicitly; // was the state set explicitly (or should it be derived from subchecks)
14
15 char *output; // Text output for humans ("Filesystem xyz is fine", "Could not create TCP connection to..")
16 pd_list *perfdata; // Performance data for this check
17 struct subcheck_list *subchecks; // subchecks deeper in the hierarchy
18} mp_subcheck;
19
20/*
21 * A list of subchecks, used in subchecks and the main check
22 */
23typedef struct subcheck_list {
24 mp_subcheck subcheck;
25 struct subcheck_list *next;
26} mp_subcheck_list;
27
28/*
29 * Possible output formats
30 */
31typedef enum output_format {
32 MP_FORMAT_MULTI_LINE,
33 MP_FORMAT_TEST_JSON,
34} mp_output_format;
35
36#define MP_FORMAT_DEFAULT MP_FORMAT_MULTI_LINE
37
38/*
39 * The main state object of a plugin. Exists only ONCE per plugin.
40 * This is the "root" of a tree of singular checks.
41 * The final result is always derived from the children and the "worst" state
42 * in the first layer of subchecks
43 */
44typedef struct {
45 mp_output_format format; // The output format
46 char *summary; // Overall summary, if not set a summary will be automatically generated
47 mp_subcheck_list *subchecks;
48} mp_check;
49
50mp_check mp_check_init(void);
51mp_subcheck mp_subcheck_init(void);
52
53mp_subcheck mp_set_subcheck_state(mp_subcheck, mp_state_enum);
54mp_subcheck mp_set_subcheck_default_state(mp_subcheck, mp_state_enum);
55
56int mp_add_subcheck_to_check(mp_check check[static 1], mp_subcheck);
57int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck);
58
59void mp_add_perfdata_to_subcheck(mp_subcheck check[static 1], mp_perfdata);
60
61void mp_add_summary(mp_check check[static 1], char *summary);
62
63mp_state_enum mp_compute_check_state(mp_check);
64mp_state_enum mp_compute_subcheck_state(mp_subcheck);
65
66typedef struct {
67 bool parsing_success;
68 mp_output_format output_format;
69} parsed_output_format;
70parsed_output_format mp_parse_output_format(char *format_string);
71
72// TODO free and stuff
73// void mp_cleanup_check(mp_check check[static 1]);
74
75char *mp_fmt_output(mp_check);
76
77void mp_print_output(mp_check);
78
79/*
80 * ==================
81 * Exit functionality
82 * ==================
83 */
84
85void mp_exit(mp_check) __attribute__((noreturn));