rrdcalctemplate.c 2.1 KB

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