| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_HEALTH_PROTOTYPES_H |
| 4 | #define NETDATA_HEALTH_PROTOTYPES_H |
| 5 | |
| 6 | #include "../web/api/queries/rrdr.h" |
| 7 | |
| 8 | typedef enum __attribute__((packed)) { |
| 9 | ALERT_ACTION_OPTION_NONE = 0, |
| 10 | ALERT_ACTION_OPTION_NO_CLEAR_NOTIFICATION = (1 << 0), |
| 11 | } ALERT_ACTION_OPTIONS; |
| 12 | |
| 13 | typedef enum __attribute__((packed)) { |
| 14 | ALERT_LOOKUP_DATA_SOURCE_SAMPLES = 0, |
| 15 | ALERT_LOOKUP_DATA_SOURCE_PERCENTAGES, |
| 16 | ALERT_LOOKUP_DATA_SOURCE_ANOMALIES, |
| 17 | } ALERT_LOOKUP_DATA_SOURCE; |
| 18 | ALERT_LOOKUP_DATA_SOURCE alerts_data_sources2id(const char *source); |
| 19 | const char *alerts_data_source_id2source(ALERT_LOOKUP_DATA_SOURCE source); |
| 20 | |
| 21 | typedef enum __attribute__((packed)) { |
| 22 | ALERT_LOOKUP_DIMS_SUM = 0, |
| 23 | ALERT_LOOKUP_DIMS_MIN, |
| 24 | ALERT_LOOKUP_DIMS_MAX, |
| 25 | ALERT_LOOKUP_DIMS_AVERAGE, |
| 26 | ALERT_LOOKUP_DIMS_MIN2MAX, |
| 27 | } ALERT_LOOKUP_DIMS_GROUPING; |
| 28 | ALERT_LOOKUP_DIMS_GROUPING alerts_dims_grouping2id(const char *group); |
| 29 | const char *alerts_dims_grouping_id2group(ALERT_LOOKUP_DIMS_GROUPING grouping); |
| 30 | |
| 31 | typedef enum __attribute__((packed)) { |
| 32 | ALERT_LOOKUP_TIME_GROUP_CONDITION_EQUAL, |
| 33 | ALERT_LOOKUP_TIME_GROUP_CONDITION_NOT_EQUAL, |
| 34 | ALERT_LOOKUP_TIME_GROUP_CONDITION_GREATER, |
| 35 | ALERT_LOOKUP_TIME_GROUP_CONDITION_LESS, |
| 36 | ALERT_LOOKUP_TIME_GROUP_CONDITION_GREATER_EQUAL, |
| 37 | ALERT_LOOKUP_TIME_GROUP_CONDITION_LESS_EQUAL, |
| 38 | } ALERT_LOOKUP_TIME_GROUP_CONDITION; |
| 39 | ALERT_LOOKUP_TIME_GROUP_CONDITION alerts_group_condition2id(const char *source); |
| 40 | const char *alerts_group_conditions_id2txt(ALERT_LOOKUP_TIME_GROUP_CONDITION source); |
| 41 | |
| 42 | struct rrd_alert_match { |
| 43 | bool enabled; |
| 44 | |
| 45 | bool is_template; |
| 46 | union { |
| 47 | STRING *chart; |
| 48 | STRING *context; |
| 49 | } on; |
| 50 | |
| 51 | STRING *host_labels; // the label read from an alarm file |
| 52 | STRING *chart_labels; // the chart label read from an alarm file |
| 53 | |
| 54 | struct pattern_array *host_labels_pattern; |
| 55 | struct pattern_array *chart_labels_pattern; |
| 56 | }; |
| 57 | void rrd_alert_match_cleanup(struct rrd_alert_match *am); |
| 58 | |
| 59 | struct rrd_alert_config { |
| 60 | nd_uuid_t hash_id; |
| 61 | |
| 62 | STRING *name; // the name of this alarm |
| 63 | |
| 64 | STRING *exec; // the command to execute when this alarm switches state |
| 65 | STRING *recipient; // the recipient of the alarm (the first parameter to exec) |
| 66 | |
| 67 | STRING *classification; // the class that this alarm belongs |
| 68 | STRING *component; // the component that this alarm refers to |
| 69 | STRING *type; // type of the alarm |
| 70 | |
| 71 | DYNCFG_SOURCE_TYPE source_type; |
| 72 | STRING *source; // the source of this alarm |
| 73 | STRING *units; // the units of the alarm |
| 74 | STRING *summary; // a short alert summary |
| 75 | STRING *info; // a description of the alarm |
| 76 | |
| 77 | int update_every; // update frequency for the alarm |
| 78 | |
| 79 | ALERT_ACTION_OPTIONS alert_action_options; |
| 80 | |
| 81 | // ------------------------------------------------------------------------ |
| 82 | // database lookup settings |
| 83 | |
| 84 | STRING *dimensions; // the chart dimensions |
| 85 | RRDR_TIME_GROUPING time_group; // grouping method: average, max, etc. |
| 86 | ALERT_LOOKUP_TIME_GROUP_CONDITION time_group_condition; |
| 87 | NETDATA_DOUBLE time_group_value; |
| 88 | ALERT_LOOKUP_DIMS_GROUPING dims_group; // grouping method for dimensions |
| 89 | ALERT_LOOKUP_DATA_SOURCE data_source; |
| 90 | int before; // ending point in time-series |
| 91 | int after; // starting point in time-series |
| 92 | RRDR_OPTIONS options; // configuration options |
| 93 | |
| 94 | // ------------------------------------------------------------------------ |
| 95 | // expressions related to the alarm |
| 96 | |
| 97 | EVAL_EXPRESSION *calculation; // expression to calculate the value of the alarm |
| 98 | EVAL_EXPRESSION *warning; // expression to check the warning condition |
| 99 | EVAL_EXPRESSION *critical; // expression to check the critical condition |
| 100 | |
| 101 | // ------------------------------------------------------------------------ |
| 102 | // notification delay settings |
| 103 | |
| 104 | int delay_up_duration; // duration to delay notifications when alarm raises |
| 105 | int delay_down_duration; // duration to delay notifications when alarm lowers |
| 106 | int delay_max_duration; // the absolute max delay to apply to this alarm |
| 107 | float delay_multiplier; // multiplier for all delays when alarms switch status |
| 108 | // while now < delay_up_to |
| 109 | |
| 110 | // ------------------------------------------------------------------------ |
| 111 | // notification repeat settings |
| 112 | |
| 113 | bool has_custom_repeat_config; |
| 114 | uint32_t warn_repeat_every; // interval between repeating warning notifications |
| 115 | uint32_t crit_repeat_every; // interval between repeating critical notifications |
| 116 | }; |
| 117 | void rrd_alert_config_cleanup(struct rrd_alert_config *ac); |
| 118 | |
| 119 | #include "health.h" |
| 120 | |
| 121 | void health_init_prototypes(void); |
| 122 | |
| 123 | bool health_plugin_enabled(void); |
| 124 | void health_plugin_disable(void); |
| 125 | |
| 126 | void health_reload_prototypes(void); |
| 127 | void health_apply_prototypes_to_host(RRDHOST *host); |
| 128 | void health_apply_prototypes_to_all_hosts(void); |
| 129 | |
| 130 | void health_prototype_alerts_for_rrdset_incrementally(RRDSET *st); |
| 131 | |
| 132 | struct rrd_alert_config; |
| 133 | struct rrd_alert_match; |
| 134 | void health_prototype_copy_config(struct rrd_alert_config *dst, struct rrd_alert_config *src); |
| 135 | void health_prototype_copy_match_without_patterns(struct rrd_alert_match *dst, struct rrd_alert_match *src); |
| 136 | void health_prototype_reset_alerts_for_rrdset(RRDSET *st); |
| 137 | |
| 138 | #endif //NETDATA_HEALTH_PROTOTYPES_H |