]> arthur.barton.de Git - netdata.git/blob - src/rrdcalctemplate.c
Merge pull request #1998 from ktsaou/master
[netdata.git] / src / rrdcalctemplate.c
1 #define NETDATA_HEALTH_INTERNALS
2 #include "common.h"
3
4 // ----------------------------------------------------------------------------
5 // RRDCALCTEMPLATE management
6
7 void rrdcalctemplate_link_matching(RRDSET *st) {
8     RRDCALCTEMPLATE *rt;
9
10     for(rt = st->rrdhost->templates; rt ; rt = rt->next) {
11         if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context)
12            && (!rt->family_pattern || simple_pattern_matches(rt->family_pattern, st->family))) {
13             RRDCALC *rc = rrdcalc_create(st->rrdhost, rt, st->id);
14             if(unlikely(!rc))
15                 error("Health tried to create alarm from template '%s', but it failed", rt->name);
16
17 #ifdef NETDATA_INTERNAL_CHECKS
18             else if(rc->rrdset != st)
19                 error("Health alarm '%s.%s' should be linked to chart '%s', but it is not", rc->chart?rc->chart:"NOCHART", rc->name, st->id);
20 #endif
21         }
22     }
23 }
24
25 inline void rrdcalctemplate_free(RRDHOST *host, RRDCALCTEMPLATE *rt) {
26     if(unlikely(!rt)) return;
27
28     debug(D_HEALTH, "Health removing template '%s' of host '%s'", rt->name, host->hostname);
29
30     if(host->templates == rt) {
31         host->templates = rt->next;
32     }
33     else {
34         RRDCALCTEMPLATE *t;
35         for (t = host->templates; t && t->next != rt; t = t->next ) ;
36         if(t) {
37             t->next = rt->next;
38             rt->next = NULL;
39         }
40         else
41             error("Cannot find RRDCALCTEMPLATE '%s' linked in host '%s'", rt->name, host->hostname);
42     }
43
44     expression_free(rt->calculation);
45     expression_free(rt->warning);
46     expression_free(rt->critical);
47
48     freez(rt->family_match);
49     simple_pattern_free(rt->family_pattern);
50
51     freez(rt->name);
52     freez(rt->exec);
53     freez(rt->recipient);
54     freez(rt->context);
55     freez(rt->source);
56     freez(rt->units);
57     freez(rt->info);
58     freez(rt->dimensions);
59     freez(rt);
60 }
61
62