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