0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-15 01:58:34 +00:00
netdata_netdata/libnetdata/config/dyncfg.h
Costa Tsaousis f466b8aef5
DYNCFG: dynamically configured alerts ()
* cleanup alerts

* fix references

* fix references

* fix references

* load alerts once and apply them to each node

* simplify health_create_alarm_entry()

* Compile without warnings with compiler flags:

   -Wall -Wextra -Wformat=2 -Wshadow -Wno-format-nonliteral -Winit-self

* code re-organization and cleanup

* generate patterns when applying prototypes; give unique dyncfg names to all alerts

* eval expressions keep the source and the parsed_as as STRING pointers

* renamed host to node in dyncfg ids

* renamed host to node in dyncfg ids

* add all cloud roles to the list of parsed X-Netdata-Role header and also default to member access level

* working functionality

* code re-organization: moved health event-loop to a new file, moved health globals to health.c

* rrdcalctemplate is removed; alert_cfg is removed; foreach dimension is removed; RRDCALCs are now instanciated only when they are linked to RRDSETs

* dyncfg alert prototypes initialization for alerts

* health dyncfg split to separate file

* cleanup not-needed code

* normalize matches between parsing and json

* also detect !* for disabled alerts

* dyncfg capability disabled

* Store alert config part1

* Add rrdlabels_common_count

* wip health variables lookup without indexes

* Improve rrdlabels_common_count by reusing rrdlabels_find_label_with_key_unsafe with an additional parameter

* working variables with runtime lookup

* working variables with runtime lookup

* delete rrddimvar and rrdfamily index

* remove rrdsetvar; now all variables are in RRDVARs inside hosts and charts

* added /api/v1/variable that resolves a variable the same way alerts do

* remove rrdcalc from eval

* remove debug code

* remove duplicate assignment

* Fix memory leak

* all alert variables are now handled by alert_variable_lookup() and EVAL is now independent of alerts

* hide all internal structures of EVAL

* Enable -Wformat flag

Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud>

* Adjust binding for calculation, warning, critical

* Remove unused macro

* Update config hash id

* use the right info and summary in alerts log

* use synchronous queries for alerts

* Handle cases when config_hash_id is missing from health_log

* remove deadlock from health worker

* parsing to json payload for health alert prototypes

* cleaner parsing and avoiding memory leaks in case of duplicate members in json

* fix left-over rename of function

* Keep original lookup field to send to the cloud
Cleanup / rename function to store config
Remove unused DEFINEs, functions

* Use ac->lookup

* link jobs to the host when the template is registered; do not accept running a function without a host

* full dyncfg support for health alerts, except action TEST

* working dyncfg additions, updates, removals

* fixed missing source, wrong status updates

* add alerts by type, component, classification, recipient and module at the /api/v2/alerts endpoint

* fix dyncfg unittest

* rename functions

* generalize the json-c parser macros and move them to libnetdata

* report progress when enabling and disabling dyncfg templates

* moved rrdcalc and rrdvar to health

* update alarms

* added schema for alerts; separated alert_action_options from rrdr_options; restructured the json payload for alerts

* enable parsed json alerts; allow sending back accepted but disabled

* added format_version for alerts payload; enables/disables status now is also inheritted by the status of the rules; fixed variable names in json output

* remove the RRDHOST pointer from DYNCFG

* Fix command field submitted to the cloud

* do not send updates to creation requests, for DYNCFG jobs

---------

Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud>
Co-authored-by: Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com>
Co-authored-by: Tasos Katsoulas <tasos@netdata.cloud>
Co-authored-by: ilyam8 <ilya@netdata.cloud>
2024-01-23 20:20:41 +02:00

86 lines
3.4 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef LIBNETDATA_DYNCFG_H
#define LIBNETDATA_DYNCFG_H
#define DYNCFG_VERSION (size_t)1
#define DYNCFG_RESP_SUCCESS(code) (code >= 200 && code <= 299)
#define DYNCFG_RESP_RUNNING 200 // accepted and running
#define DYNCFG_RESP_ACCEPTED 202 // accepted, but not running yet
#define DYNCFG_RESP_ACCEPTED_DISABLED 298 // accepted, but is disabled
#define DYNCFG_RESP_ACCEPTED_RESTART_REQUIRED 299 // accepted, but restart is required to apply it
typedef enum __attribute__((packed)) {
DYNCFG_TYPE_SINGLE = 0,
DYNCFG_TYPE_TEMPLATE,
DYNCFG_TYPE_JOB,
} DYNCFG_TYPE;
DYNCFG_TYPE dyncfg_type2id(const char *type);
const char *dyncfg_id2type(DYNCFG_TYPE type);
typedef enum __attribute__((packed)) {
DYNCFG_SOURCE_TYPE_INTERNAL = 0,
DYNCFG_SOURCE_TYPE_STOCK,
DYNCFG_SOURCE_TYPE_USER,
DYNCFG_SOURCE_TYPE_DYNCFG,
DYNCFG_SOURCE_TYPE_DISCOVERED,
} DYNCFG_SOURCE_TYPE;
DYNCFG_SOURCE_TYPE dyncfg_source_type2id(const char *source_type);
const char *dyncfg_id2source_type(DYNCFG_SOURCE_TYPE source_type);
typedef enum __attribute__((packed)) {
DYNCFG_STATUS_NONE = 0,
DYNCFG_STATUS_ACCEPTED, // the plugin has accepted the configuration
DYNCFG_STATUS_RUNNING, // the plugin runs the accepted configuration
DYNCFG_STATUS_FAILED, // the plugin fails to run the accepted configuration
DYNCFG_STATUS_DISABLED, // the configuration is disabled by a user
DYNCFG_STATUS_ORPHAN, // no plugin has claimed this configurations
DYNCFG_STATUS_INCOMPLETE, // a special kind of failed configuration
} DYNCFG_STATUS;
DYNCFG_STATUS dyncfg_status2id(const char *status);
const char *dyncfg_id2status(DYNCFG_STATUS status);
typedef enum __attribute__((packed)) {
DYNCFG_CMD_NONE = 0,
DYNCFG_CMD_GET = (1 << 0),
DYNCFG_CMD_SCHEMA = (1 << 1),
DYNCFG_CMD_UPDATE = (1 << 2),
DYNCFG_CMD_ADD = (1 << 3),
DYNCFG_CMD_TEST = (1 << 4),
DYNCFG_CMD_REMOVE = (1 << 5),
DYNCFG_CMD_ENABLE = (1 << 6),
DYNCFG_CMD_DISABLE = (1 << 7),
DYNCFG_CMD_RESTART = (1 << 8),
} DYNCFG_CMDS;
DYNCFG_CMDS dyncfg_cmds2id(const char *cmds);
void dyncfg_cmds2buffer(DYNCFG_CMDS cmds, struct web_buffer *wb);
void dyncfg_cmds2json_array(DYNCFG_CMDS cmds, const char *key, struct web_buffer *wb);
void dyncfg_cmds2fp(DYNCFG_CMDS cmds, FILE *fp);
const char *dyncfg_id2cmd_one(DYNCFG_CMDS cmd);
bool dyncfg_is_valid_id(const char *id);
char *dyncfg_escape_id_for_filename(const char *id);
#include "../clocks/clocks.h"
#include "../buffer/buffer.h"
#include "../dictionary/dictionary.h"
typedef int (*dyncfg_cb_t)(const char *transaction, const char *id, DYNCFG_CMDS cmd, const char *add_name, BUFFER *payload, usec_t *stop_monotonic_ut, bool *cancelled, BUFFER *result, const char *source, void *data);
struct dyncfg_node {
DYNCFG_TYPE type;
DYNCFG_CMDS cmds;
dyncfg_cb_t cb;
void *data;
};
#define dyncfg_nodes_dictionary_create() dictionary_create_advanced(DICT_OPTION_FIXED_SIZE, NULL, sizeof(struct dyncfg_node))
int dyncfg_default_response(BUFFER *wb, int code, const char *msg);
int dyncfg_node_find_and_call(DICTIONARY *dyncfg_nodes, const char *transaction, const char *function,
usec_t *stop_monotonic_ut, bool *cancelled,
BUFFER *payload, const char *source, BUFFER *result);
#endif //LIBNETDATA_DYNCFG_H