health_internals.h 4.5 KB

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