summaryrefslogtreecommitdiffstats
path: root/lib/output.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output.h')
-rw-r--r--lib/output.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/lib/output.h b/lib/output.h
new file mode 100644
index 00000000..2bdfa074
--- /dev/null
+++ b/lib/output.h
@@ -0,0 +1,90 @@
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 * Format related functions
40 */
41 void mp_set_format(mp_output_format format);
42 mp_output_format mp_get_format(void);
43
44/*
45 * The main state object of a plugin. Exists only ONCE per plugin.
46 * This is the "root" of a tree of singular checks.
47 * The final result is always derived from the children and the "worst" state
48 * in the first layer of subchecks
49 */
50typedef struct {
51 char *summary; // Overall summary, if not set a summary will be automatically generated
52 mp_subcheck_list *subchecks;
53} mp_check;
54
55mp_check mp_check_init(void);
56mp_subcheck mp_subcheck_init(void);
57
58mp_subcheck mp_set_subcheck_state(mp_subcheck, mp_state_enum);
59mp_subcheck mp_set_subcheck_default_state(mp_subcheck, mp_state_enum);
60
61int mp_add_subcheck_to_check(mp_check check[static 1], mp_subcheck);
62int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck);
63
64void mp_add_perfdata_to_subcheck(mp_subcheck check[static 1], mp_perfdata);
65
66void mp_add_summary(mp_check check[static 1], char *summary);
67
68mp_state_enum mp_compute_check_state(mp_check);
69mp_state_enum mp_compute_subcheck_state(mp_subcheck);
70
71typedef struct {
72 bool parsing_success;
73 mp_output_format output_format;
74} parsed_output_format;
75parsed_output_format mp_parse_output_format(char *format_string);
76
77// TODO free and stuff
78// void mp_cleanup_check(mp_check check[static 1]);
79
80char *mp_fmt_output(mp_check);
81
82void mp_print_output(mp_check);
83
84/*
85 * ==================
86 * Exit functionality
87 * ==================
88 */
89
90void mp_exit(mp_check) __attribute__((noreturn));