| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_HEALTH_INTERNALS_H |
| 4 | #define NETDATA_HEALTH_INTERNALS_H |
| 5 | |
| 6 | #include "health.h" |
| 7 | |
| 8 | #define HEALTH_LOG_ENTRIES_DEFAULT 1000U |
| 9 | #define HEALTH_LOG_ENTRIES_MAX 100000U |
| 10 | #define HEALTH_LOG_ENTRIES_MIN 10U |
| 11 | |
| 12 | #define HEALTH_LOG_RETENTION_DEFAULT (5 * 86400) |
| 13 | |
| 14 | #define HEALTH_CONF_MAX_LINE 4096 |
| 15 | |
| 16 | #define HEALTH_ALARM_KEY "alarm" |
| 17 | #define HEALTH_TEMPLATE_KEY "template" |
| 18 | #define HEALTH_CHART_KEY "chart" |
| 19 | #define HEALTH_CONTEXT_KEY "context" |
| 20 | #define HEALTH_ON_KEY "on" |
| 21 | #define HEALTH_HOST_KEY "hosts" |
| 22 | #define HEALTH_OS_KEY "os" |
| 23 | #define HEALTH_PLUGIN_KEY "plugin" |
| 24 | #define HEALTH_MODULE_KEY "module" |
| 25 | #define HEALTH_LOOKUP_KEY "lookup" |
| 26 | #define HEALTH_CALC_KEY "calc" |
| 27 | #define HEALTH_EVERY_KEY "every" |
| 28 | #define HEALTH_GREEN_KEY "green" |
| 29 | #define HEALTH_RED_KEY "red" |
| 30 | #define HEALTH_WARN_KEY "warn" |
| 31 | #define HEALTH_CRIT_KEY "crit" |
| 32 | #define HEALTH_EXEC_KEY "exec" |
| 33 | #define HEALTH_RECIPIENT_KEY "to" |
| 34 | #define HEALTH_UNITS_KEY "units" |
| 35 | #define HEALTH_SUMMARY_KEY "summary" |
| 36 | #define HEALTH_INFO_KEY "info" |
| 37 | #define HEALTH_CLASS_KEY "class" |
| 38 | #define HEALTH_COMPONENT_KEY "component" |
| 39 | #define HEALTH_TYPE_KEY "type" |
| 40 | #define HEALTH_DELAY_KEY "delay" |
| 41 | #define HEALTH_OPTIONS_KEY "options" |
| 42 | #define HEALTH_REPEAT_KEY "repeat" |
| 43 | #define HEALTH_HOST_LABEL_KEY "host labels" |
| 44 | #define HEALTH_CHART_LABEL_KEY "chart labels" |
| 45 | |
| 46 | void alert_action_options_to_buffer_json_array(BUFFER *wb, const char *key, ALERT_ACTION_OPTIONS options); |
| 47 | void alert_action_options_to_buffer(BUFFER *wb, ALERT_ACTION_OPTIONS options); |
| 48 | ALERT_ACTION_OPTIONS alert_action_options_parse(char *o); |
| 49 | ALERT_ACTION_OPTIONS alert_action_options_parse_one(const char *o); |
| 50 | |
| 51 | typedef struct rrd_alert_prototype { |
| 52 | struct rrd_alert_match match; |
| 53 | struct rrd_alert_config config; |
| 54 | |
| 55 | struct { |
| 56 | bool enabled; |
| 57 | bool is_on_disk; |
| 58 | RW_SPINLOCK rw_spinlock; |
| 59 | struct rrd_alert_prototype *prev, *next; |
| 60 | } _internal; |
| 61 | } RRD_ALERT_PROTOTYPE; |
| 62 | bool health_prototype_add(RRD_ALERT_PROTOTYPE *ap, char **msg); |
| 63 | void health_prototype_cleanup(RRD_ALERT_PROTOTYPE *ap); |
| 64 | void health_prototype_free(RRD_ALERT_PROTOTYPE *ap); |
| 65 | |
| 66 | struct health_plugin_globals { |
| 67 | struct { |
| 68 | SPINLOCK spinlock; |
| 69 | bool done; |
| 70 | } initialization; |
| 71 | |
| 72 | struct { |
| 73 | bool enabled; |
| 74 | bool stock_enabled; |
| 75 | bool use_summary_for_notifications; |
| 76 | |
| 77 | unsigned int health_log_entries_max; |
| 78 | uint32_t health_log_retention_s; // the health log retention in seconds to be kept in db |
| 79 | |
| 80 | STRING *silencers_filename; |
| 81 | STRING *default_exec; |
| 82 | STRING *default_recipient; |
| 83 | |
| 84 | SIMPLE_PATTERN *enabled_alerts; |
| 85 | |
| 86 | uint32_t default_warn_repeat_every; // the default value for the interval between repeating warning notifications |
| 87 | uint32_t default_crit_repeat_every; // the default value for the interval between repeating critical notifications |
| 88 | |
| 89 | int32_t run_at_least_every_seconds; |
| 90 | int32_t postpone_alarms_during_hibernation_for_seconds; |
| 91 | int32_t notification_execution_timeout_seconds; // kill notification commands running longer than this (0 = wait forever) |
| 92 | } config; |
| 93 | |
| 94 | struct { |
| 95 | DICTIONARY *dict; |
| 96 | bool registering; |
| 97 | } prototypes; |
| 98 | }; |
| 99 | |
| 100 | extern struct health_plugin_globals health_globals; |
| 101 | |
| 102 | int health_readfile(const char *filename, void *data, bool stock_config); |
| 103 | |
| 104 | // for unit testing |
| 105 | int health_parse_db_lookup(size_t line, const char *filename, char *string, struct rrd_alert_config *ac); |
| 106 | void unlink_alarm_notify_in_progress(ALARM_ENTRY *ae); |
| 107 | void wait_for_all_notifications_to_finish_before_allowing_health_to_be_cleaned_up(void); |
| 108 | |
| 109 | void health_alarm_wait_for_execution(ALARM_ENTRY *ae); |
| 110 | |
| 111 | bool rrdcalc_add_from_prototype(RRDHOST *host, RRDSET *st, RRD_ALERT_PROTOTYPE *ap); |
| 112 | |
| 113 | int dyncfg_health_cb(const char *transaction, const char *id, DYNCFG_CMDS cmd, const char *add_name, |
| 114 | BUFFER *payload, usec_t *stop_monotonic_ut, bool *cancelled, |
| 115 | BUFFER *result, HTTP_ACCESS access, const char *source, void *data); |
| 116 | |
| 117 | void health_dyncfg_unregister_all_prototypes(void); |
| 118 | void health_dyncfg_register_all_prototypes(void); |
| 119 | void health_prototype_to_json(BUFFER *wb, RRD_ALERT_PROTOTYPE *ap, bool for_hashing); |
| 120 | |
| 121 | bool alert_variable_lookup(STRING *variable, void *data, NETDATA_DOUBLE *result); |
| 122 | |
| 123 | struct health_raised_summary; |
| 124 | struct health_raised_summary *alerts_raised_summary_create(RRDHOST *host); |
| 125 | void alerts_raised_summary_populate(struct health_raised_summary *hrm); |
| 126 | void alerts_raised_summary_free(struct health_raised_summary *hrm); |
| 127 | void health_send_notification(RRDHOST *host, ALARM_ENTRY *ae, struct health_raised_summary *hrm); |
| 128 | void health_alarm_log_process_to_send_notifications(RRDHOST *host, struct health_raised_summary *hrm); |
| 129 | |
| 130 | void health_apply_prototype_to_host(RRDHOST *host, RRD_ALERT_PROTOTYPE *ap); |
| 131 | void health_prototype_apply_to_all_hosts(RRD_ALERT_PROTOTYPE *ap); |
| 132 | |
| 133 | #endif //NETDATA_HEALTH_INTERNALS_H |