master
h 116 lines 4.52 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_HEALTH_H
4 #define NETDATA_HEALTH_H 1
5
6 #include "database/rrd.h"
7 #include "rrdcalc.h"
8
9 typedef enum __attribute__((packed)) {
10 HEALTH_ENTRY_FLAG_PROCESSED = 0x00000001, // notifications engine has processed this
11 HEALTH_ENTRY_FLAG_UPDATED = 0x00000002, // there is a more recent update about this transition
12 HEALTH_ENTRY_FLAG_EXEC_RUN = 0x00000004, // notification script has been run (this is the intent, not the result)
13 HEALTH_ENTRY_FLAG_EXEC_FAILED = 0x00000008, // notification script couldn't be run
14 HEALTH_ENTRY_FLAG_SILENCED = 0x00000010,
15 HEALTH_ENTRY_RUN_ONCE = 0x00000020,
16 HEALTH_ENTRY_FLAG_EXEC_IN_PROGRESS = 0x00000040,
17 HEALTH_ENTRY_FLAG_IS_REPEATING = 0x00000080,
18 HEALTH_ENTRY_FLAG_SAVED = 0x10000000, // Saved to SQL
19 HEALTH_ENTRY_FLAG_ACLK_QUEUED = 0x20000000, // Sent to Netdata Cloud
20 HEALTH_ENTRY_FLAG_NO_CLEAR_NOTIFICATION = 0x80000000,
21 } HEALTH_ENTRY_FLAGS;
22
23 #define RRDR_OPTIONS_DATA_SOURCES (RRDR_OPTION_PERCENTAGE|RRDR_OPTION_ANOMALY_BIT)
24 #define RRDR_OPTIONS_DIMS_AGGREGATION (RRDR_OPTION_DIMS_MIN|RRDR_OPTION_DIMS_MAX|RRDR_OPTION_DIMS_AVERAGE|RRDR_OPTION_DIMS_MIN2MAX)
25 #define RRDR_OPTIONS_REMOVE_OVERLAPPING(options) ((options) & ~(RRDR_OPTIONS_DIMS_AGGREGATION|RRDR_OPTIONS_DATA_SOURCES))
26
27 void health_entry_flags_to_json_array(BUFFER *wb, const char *key, HEALTH_ENTRY_FLAGS flags);
28
29 #ifndef HEALTH_LISTEN_PORT
30 #define HEALTH_LISTEN_PORT 19998
31 #endif
32
33 #ifndef HEALTH_LISTEN_BACKLOG
34 #define HEALTH_LISTEN_BACKLOG 4096
35 #endif
36
37 #ifndef HEALTH_LOG_RETENTION_DEFAULT
38 #define HEALTH_LOG_RETENTION_DEFAULT (5 * 86400)
39 #endif
40
41 #ifndef HEALTH_LOG_MINIMUM_HISTORY
42 #define HEALTH_LOG_MINIMUM_HISTORY 86400
43 #endif
44
45 #define HEALTH_SILENCERS_MAX_FILE_LEN 10000
46
47 void health_plugin_init(void);
48 void health_plugin_destroy(void);
49
50 void health_plugin_reload(void);
51
52 void health_aggregate_alarms(RRDHOST *host, BUFFER *wb, BUFFER* context, RRDCALC_STATUS status);
53 void health_alarms2json(RRDHOST *host, BUFFER *wb, int all);
54 void health_alert2json_conf(RRDHOST *host, BUFFER *wb, CONTEXTS_OPTIONS all);
55 void health_alarms_values2json(RRDHOST *host, BUFFER *wb, int all);
56
57 void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *wb);
58 void health_api_v1_chart_custom_variables2json(RRDSET *st, BUFFER *buf);
59
60 int health_alarm_log_open(RRDHOST *host);
61 void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae, bool async);
62 void health_alarm_log_load(RRDHOST *host);
63
64 ALARM_ENTRY* health_create_alarm_entry(
65 RRDHOST *host,
66 RRDCALC *rc,
67 time_t when,
68 time_t duration,
69 NETDATA_DOUBLE old_value,
70 NETDATA_DOUBLE new_value,
71 RRDCALC_STATUS old_status,
72 RRDCALC_STATUS new_status,
73 int delay,
74 HEALTH_ENTRY_FLAGS flags);
75
76 void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae, bool async);
77
78 const char *health_user_config_dir(void);
79 const char *health_stock_config_dir(void);
80 void health_alarm_log_free(RRDHOST *host);
81
82 void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae);
83
84 // ARAL management functions for ALARM_ENTRY
85 void health_alarm_entry_aral_init(void);
86 struct aral_statistics *health_alarm_entry_aral_stats(void);
87 ALARM_ENTRY *health_alarm_entry_create(void);
88 void health_alarm_entry_destroy(ALARM_ENTRY *ae);
89
90 void *health_cmdapi_thread(void *ptr);
91
92 char *health_edit_command_from_source(const char *source);
93
94 void health_string2json(BUFFER *wb, const char *prefix, const char *label, const char *value, const char *suffix);
95
96 void health_log_alert_transition_with_trace(RRDHOST *host, ALARM_ENTRY *ae, int line, const char *file, const char *function);
97 #define health_log_alert(host, ae) health_log_alert_transition_with_trace(host, ae, __LINE__, __FILE__, __FUNCTION__)
98 bool health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(RRDCALC *rc, usec_t *global_id, nd_uuid_t *transitions_id);
99
100 int alert_variable_lookup_trace(RRDHOST *host, RRDSET *st, const char *variable, BUFFER *wb);
101
102 #include "health_prototypes.h"
103 #include "health_silencers.h"
104
105 typedef void (*prototype_metadata_cb_t)(void *data, STRING *type, STRING *component, STRING *classification, STRING *recipient);
106 void health_prototype_metadata_foreach(void *data, prototype_metadata_cb_t cb);
107
108 uint64_t health_evloop_current_iteration(void);
109 void rrdhost_set_health_evloop_iteration(RRDHOST *host);
110 uint64_t rrdhost_health_evloop_last_iteration(RRDHOST *host);
111
112 void health_load_config_defaults(void);
113
114 void alert_variable_lookup_cleanup(void);
115
116 #endif //NETDATA_HEALTH_H