mirror of
https://github.com/netdata/netdata.git
synced 2025-04-14 09:38:34 +00:00

* 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>
149 lines
5.1 KiB
C
149 lines
5.1 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "dyncfg-internals.h"
|
|
#include "dyncfg.h"
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// echo is when we send requests to plugins without any caller
|
|
// it is used for:
|
|
// 1. the first enable/disable requests we send, and also
|
|
// 2. updates to stock or user configurations
|
|
// 3. saved dynamic jobs we need to add to templates
|
|
|
|
struct dyncfg_echo {
|
|
const DICTIONARY_ITEM *item;
|
|
DYNCFG *df;
|
|
BUFFER *wb;
|
|
const char *cmd;
|
|
};
|
|
|
|
void dyncfg_echo_cb(BUFFER *wb __maybe_unused, int code __maybe_unused, void *result_cb_data) {
|
|
struct dyncfg_echo *e = result_cb_data;
|
|
|
|
if(!DYNCFG_RESP_SUCCESS(code))
|
|
nd_log(NDLS_DAEMON, NDLP_ERR,
|
|
"DYNCFG: received response code %d on request to id '%s', cmd: %s",
|
|
code, dictionary_acquired_item_name(e->item), e->cmd);
|
|
|
|
buffer_free(e->wb);
|
|
dictionary_acquired_item_release(dyncfg_globals.nodes, e->item);
|
|
|
|
e->wb = NULL;
|
|
e->df = NULL;
|
|
e->item = NULL;
|
|
freez((void *)e->cmd);
|
|
e->cmd = NULL;
|
|
freez(e);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void dyncfg_echo(const DICTIONARY_ITEM *item, DYNCFG *df, const char *id __maybe_unused, DYNCFG_CMDS cmd) {
|
|
RRDHOST *host = dyncfg_rrdhost(df);
|
|
if(!host) {
|
|
nd_log(NDLS_DAEMON, NDLP_ERR, "DYNCFG: cannot find host of configuration id '%s'", id);
|
|
return;
|
|
}
|
|
|
|
if(!(df->cmds & cmd)) {
|
|
nd_log(NDLS_DAEMON, NDLP_ERR, "DYNCFG: attempted to echo a cmd that is not supported");
|
|
return;
|
|
}
|
|
|
|
const char *cmd_str = dyncfg_id2cmd_one(cmd);
|
|
if(!cmd_str) {
|
|
nd_log(NDLS_DAEMON, NDLP_ERR, "DYNCFG: command given does not resolve to a known command");
|
|
return;
|
|
}
|
|
|
|
struct dyncfg_echo *e = callocz(1, sizeof(struct dyncfg_echo));
|
|
e->item = dictionary_acquired_item_dup(dyncfg_globals.nodes, item);
|
|
e->wb = buffer_create(0, NULL);
|
|
e->df = df;
|
|
e->cmd = strdupz(cmd_str);
|
|
|
|
char buf[string_strlen(df->function) + strlen(cmd_str) + 20];
|
|
snprintfz(buf, sizeof(buf), "%s %s", string2str(df->function), cmd_str);
|
|
|
|
rrd_function_run(
|
|
host, e->wb, 10, HTTP_ACCESS_ADMIN, buf, false, NULL,
|
|
dyncfg_echo_cb, e,
|
|
NULL, NULL,
|
|
NULL, NULL,
|
|
NULL, string2str(df->source));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
static void dyncfg_echo_payload(const DICTIONARY_ITEM *item, DYNCFG *df, const char *id, const char *cmd) {
|
|
RRDHOST *host = dyncfg_rrdhost(df);
|
|
if(!host) {
|
|
nd_log(NDLS_DAEMON, NDLP_ERR, "DYNCFG: cannot find host of configuration id '%s'", id);
|
|
return;
|
|
}
|
|
|
|
if(!df->payload) {
|
|
nd_log(NDLS_DAEMON, NDLP_ERR, "DYNCFG: requested to send a '%s' to '%s', but there is no payload", cmd, id);
|
|
return;
|
|
}
|
|
|
|
struct dyncfg_echo *e = callocz(1, sizeof(struct dyncfg_echo));
|
|
e->item = dictionary_acquired_item_dup(dyncfg_globals.nodes, item);
|
|
e->wb = buffer_create(0, NULL);
|
|
e->df = df;
|
|
e->cmd = strdupz(cmd);
|
|
|
|
char buf[string_strlen(df->function) + strlen(cmd) + 20];
|
|
snprintfz(buf, sizeof(buf), "%s %s", string2str(df->function), cmd);
|
|
|
|
rrd_function_run(
|
|
host, e->wb, 10, HTTP_ACCESS_ADMIN, buf, false, NULL,
|
|
dyncfg_echo_cb, e,
|
|
NULL, NULL,
|
|
NULL, NULL,
|
|
df->payload, string2str(df->source));
|
|
}
|
|
|
|
void dyncfg_echo_update(const DICTIONARY_ITEM *item, DYNCFG *df, const char *id) {
|
|
dyncfg_echo_payload(item, df, id, "update");
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
static void dyncfg_echo_payload_add(const DICTIONARY_ITEM *item_template __maybe_unused, const DICTIONARY_ITEM *item_job, DYNCFG *df_template, DYNCFG *df_job, const char *id_template, const char *cmd) {
|
|
RRDHOST *host = dyncfg_rrdhost(df_template);
|
|
if(!host) {
|
|
nd_log(NDLS_DAEMON, NDLP_ERR, "DYNCFG: cannot find host of configuration id '%s'", id_template);
|
|
return;
|
|
}
|
|
|
|
if(!df_job->payload) {
|
|
nd_log(NDLS_DAEMON, NDLP_ERR,
|
|
"DYNCFG: requested to send a '%s' to '%s', but there is no payload",
|
|
cmd, id_template);
|
|
return;
|
|
}
|
|
|
|
struct dyncfg_echo *e = callocz(1, sizeof(struct dyncfg_echo));
|
|
e->item = dictionary_acquired_item_dup(dyncfg_globals.nodes, item_job);
|
|
e->wb = buffer_create(0, NULL);
|
|
e->df = df_job;
|
|
e->cmd = strdupz(cmd);
|
|
|
|
char buf[string_strlen(df_template->function) + strlen(cmd) + 20];
|
|
snprintfz(buf, sizeof(buf), "%s %s", string2str(df_template->function), cmd);
|
|
|
|
rrd_function_run(
|
|
host, e->wb, 10, HTTP_ACCESS_ADMIN, buf, false, NULL,
|
|
dyncfg_echo_cb, e,
|
|
NULL, NULL,
|
|
NULL, NULL,
|
|
df_job->payload, string2str(df_job->source));
|
|
}
|
|
|
|
void dyncfg_echo_add(const DICTIONARY_ITEM *item_template, const DICTIONARY_ITEM *item_job, DYNCFG *df_template, DYNCFG *df_job, const char *template_id, const char *job_name) {
|
|
char buf[strlen(job_name) + 20];
|
|
snprintfz(buf, sizeof(buf), "add %s", job_name);
|
|
dyncfg_echo_payload_add(item_template, item_job, df_template, df_job, template_id, buf);
|
|
}
|
|
|