]> arthur.barton.de Git - netdata.git/blob - src/rrdcalctemplate.c
proxies disconnect and reconnect to follow the receiving side
[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     debug(D_HEALTH, "Health removing template '%s' of host '%s'", rt->name, host->hostname);
27
28     if(host->templates == rt) {
29         host->templates = rt->next;
30     }
31     else {
32         RRDCALCTEMPLATE *t;
33         for (t = host->templates; t && t->next != rt; t = t->next ) ;
34         if(t) {
35             t->next = rt->next;
36             rt->next = NULL;
37         }
38         else
39             error("Cannot find RRDCALCTEMPLATE '%s' linked in host '%s'", rt->name, host->hostname);
40     }
41
42     expression_free(rt->calculation);
43     expression_free(rt->warning);
44     expression_free(rt->critical);
45
46     freez(rt->family_match);
47     simple_pattern_free(rt->family_pattern);
48
49     freez(rt->name);
50     freez(rt->exec);
51     freez(rt->recipient);
52     freez(rt->context);
53     freez(rt->source);
54     freez(rt->units);
55     freez(rt->info);
56     freez(rt->dimensions);
57     freez(rt);
58 }
59
60