summaryrefslogtreecommitdiffstats
path: root/database/rrdcalctemplate.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-08-12 07:26:17 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-08-12 07:26:17 +0000
commit7877a98bd9c00db5e81dd2f8c734cba2bab20be7 (patch)
treed18b767250f7c7ced9b8abe2ece784ac1fe24d3e /database/rrdcalctemplate.c
parentReleasing debian version 1.35.1-2. (diff)
downloadnetdata-7877a98bd9c00db5e81dd2f8c734cba2bab20be7.tar.xz
netdata-7877a98bd9c00db5e81dd2f8c734cba2bab20be7.zip
Merging upstream version 1.36.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'database/rrdcalctemplate.c')
-rw-r--r--database/rrdcalctemplate.c102
1 files changed, 27 insertions, 75 deletions
diff --git a/database/rrdcalctemplate.c b/database/rrdcalctemplate.c
index 9789f4bea..3f9804b93 100644
--- a/database/rrdcalctemplate.c
+++ b/database/rrdcalctemplate.c
@@ -4,98 +4,50 @@
#include "rrd.h"
// ----------------------------------------------------------------------------
+// RRDCALCTEMPLATE management
+/**
+ * RRDCALC TEMPLATE LINK MATCHING
+ *
+ * @param rt is the template used to create the chart.
+ * @param st is the chart where the alarm will be attached.
+ */
+void rrdcalctemplate_check_conditions_and_link(RRDCALCTEMPLATE *rt, RRDSET *st, RRDHOST *host) {
+ if(rt->hash_context != st->hash_context || strcmp(rt->context, st->context) != 0)
+ return;
-static int rrdcalctemplate_is_there_label_restriction(RRDCALCTEMPLATE *rt, RRDHOST *host) {
- if(!rt->labels)
- return 0;
-
- errno = 0;
- struct label *move = host->labels.head;
- char cmp[CONFIG_FILE_LINE_MAX+1];
-
- int ret;
- if(move) {
- rrdhost_check_rdlock(host);
- netdata_rwlock_rdlock(&host->labels.labels_rwlock);
- while(move) {
- snprintfz(cmp, CONFIG_FILE_LINE_MAX, "%s=%s", move->key, move->value);
- if (simple_pattern_matches(rt->splabels, move->key) ||
- simple_pattern_matches(rt->splabels, cmp)) {
- break;
- }
- move = move->next;
- }
- netdata_rwlock_unlock(&host->labels.labels_rwlock);
-
- if(!move) {
- error("Health template '%s' cannot be applied, because the host %s does not have the label(s) '%s'",
- rt->name,
- host->hostname,
- rt->labels
- );
- ret = 1;
- } else {
- ret = 0;
- }
- } else {
- ret =0;
- }
-
- return ret;
-}
-
-static inline int rrdcalctemplate_test_additional_restriction(RRDCALCTEMPLATE *rt, RRDSET *st) {
if (rt->charts_pattern && !simple_pattern_matches(rt->charts_pattern, st->name))
- return 0;
+ return;
if (rt->family_pattern && !simple_pattern_matches(rt->family_pattern, st->family))
- return 0;
+ return;
if (rt->module_pattern && !simple_pattern_matches(rt->module_pattern, st->module_name))
- return 0;
+ return;
if (rt->plugin_pattern && !simple_pattern_matches(rt->plugin_pattern, st->plugin_name))
- return 0;
+ return;
- return 1;
-}
+ if(host->host_labels && rt->host_labels_pattern && !rrdlabels_match_simple_pattern_parsed(host->host_labels, rt->host_labels_pattern, '='))
+ return;
-// RRDCALCTEMPLATE management
-/**
- * RRDCALC TEMPLATE LINK MATCHING
- *
- * @param rt is the template used to create the chart.
- * @param st is the chart where the alarm will be attached.
- */
-void rrdcalctemplate_link_matching_test(RRDCALCTEMPLATE *rt, RRDSET *st, RRDHOST *host) {
- if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context) &&
- rrdcalctemplate_test_additional_restriction(rt, st) ) {
- if (!rrdcalctemplate_is_there_label_restriction(rt, host)) {
- RRDCALC *rc = rrdcalc_create_from_template(host, rt, st->id);
- if (unlikely(!rc))
- info("Health tried to create alarm from template '%s' on chart '%s' of host '%s', but it failed",
- rt->name, st->id, host->hostname);
+ RRDCALC *rc = rrdcalc_create_from_template(host, rt, st->id);
+ if (unlikely(!rc))
+ info("Health tried to create alarm from template '%s' on chart '%s' of host '%s', but it failed", rt->name, st->id, host->hostname);
#ifdef NETDATA_INTERNAL_CHECKS
- else if (rc->rrdset != st &&
- !rc->foreachdim) //When we have a template with foreadhdim, the child will be added to the index late
- error("Health alarm '%s.%s' should be linked to chart '%s', but it is not",
- rc->chart ? rc->chart : "NOCHART", rc->name, st->id);
+ else if (rc->rrdset != st && !rc->foreachdim) //When we have a template with foreadhdim, the child will be added to the index late
+ error("Health alarm '%s.%s' should be linked to chart '%s', but it is not", rc->chart ? rc->chart : "NOCHART", rc->name, st->id);
#endif
- }
- }
}
void rrdcalctemplate_link_matching(RRDSET *st) {
RRDHOST *host = st->rrdhost;
RRDCALCTEMPLATE *rt;
- for(rt = host->templates; rt ; rt = rt->next) {
- rrdcalctemplate_link_matching_test(rt, st, host);
- }
+ for(rt = host->templates; rt ; rt = rt->next)
+ rrdcalctemplate_check_conditions_and_link(rt, st, host);
- for(rt = host->alarms_template_with_foreach; rt ; rt = rt->next) {
- rrdcalctemplate_link_matching_test(rt, st, host);
- }
+ for(rt = host->alarms_template_with_foreach; rt ; rt = rt->next)
+ rrdcalctemplate_check_conditions_and_link(rt, st, host);
}
inline void rrdcalctemplate_free(RRDCALCTEMPLATE *rt) {
@@ -129,9 +81,9 @@ inline void rrdcalctemplate_free(RRDCALCTEMPLATE *rt) {
freez(rt->info);
freez(rt->dimensions);
freez(rt->foreachdim);
- freez(rt->labels);
+ freez(rt->host_labels);
simple_pattern_free(rt->spdim);
- simple_pattern_free(rt->splabels);
+ simple_pattern_free(rt->host_labels_pattern);
freez(rt);
}