properly check for duplicate alarms, allowing alarms to override templates; fixes #904
Costa Tsaousis (ktsaou) committed
Sep 7, 2016 at 21:22 UTC
f11e2ab8fc606a7cc4bbb8e240fb17794de249e0
1 file changed
+16
-22
src/health.c
+16
-22
@@ -555,14 +555,22 @@ RRDCALC *rrdcalc_find(RRDSET *st, const char *name) {
555
return NULL;
556
}
557
558
-static inline int rrdcalc_exists(RRDHOST *host, const char *name, uint32_t hash) {
558
+static inline int rrdcalc_exists(RRDHOST *host, const char *chart, const char *name, uint32_t hash_chart, uint32_t hash_name) {
559
RRDCALC *rc;
560
561
+ if(unlikely(!chart)) {
562
+ error("attempt to find RRDCALC '%s' without giving a chart name", name);
563
+ return 1;
564
+ }
565
+
566
+ if(unlikely(!hash_chart)) hash_chart = simple_hash(chart);
567
+ if(unlikely(!hash_name)) hash_name = simple_hash(name);
568
+
569
// make sure it does not already exist
570
for(rc = host->alarms; rc ; rc = rc->next) {
563
- if (unlikely(rc->hash == hash && !strcmp(name, rc->name))) {
564
- debug(D_HEALTH, "Health alarm '%s' already exists in host '%s'.", name, host->hostname);
565
- error("Health alarm '%s' already exists in host '%s'.", name, host->hostname);
571
+ if (unlikely(rc->chart && rc->hash == hash_name && rc->hash_chart == hash_chart && !strcmp(name, rc->name) && !strcmp(chart, rc->chart))) {
572
+ debug(D_HEALTH, "Health alarm '%s.%s' already exists in host '%s'.", chart, name, host->hostname);
573
+ error("Health alarm '%s.%s' already exists in host '%s'.", chart, name, host->hostname);
574
return 1;
575
}
576
}
@@ -615,12 +623,6 @@ static inline void rrdcalc_create_part2(RRDHOST *host, RRDCALC *rc) {
623
}
624
}
625
618
-static inline uint32_t rrdcalc_fullname(char *fullname, size_t len, const char *chart, const char *name) {
619
- snprintfz(fullname, len - 1, "%s%s%s", chart?chart:"", chart?".":"", name);
620
- rrdvar_fix_name(fullname);
621
- return simple_hash(fullname);
622
-}
623
-
626
static inline RRDCALC *rrdcalc_create(RRDHOST *host, const char *name, const char *chart, const char *dimensions,
627
const char *units, const char *info,
628
int group_method, int after, int before, int update_every, uint32_t options,
@@ -630,10 +632,7 @@ static inline RRDCALC *rrdcalc_create(RRDHOST *host, const char *name, const cha
632
633
debug(D_HEALTH, "Health creating dynamic alarm (from template) '%s.%s'", chart, name);
634
633
- char fullname[RRDVAR_MAX_LENGTH + 1];
634
- uint32_t hash = rrdcalc_fullname(fullname, RRDVAR_MAX_LENGTH + 1, chart, name);
635
-
636
- if(rrdcalc_exists(host, fullname, hash))
635
+ if(rrdcalc_exists(host, chart, name, 0, 0))
636
return NULL;
637
638
RRDCALC *rc = callocz(1, sizeof(RRDCALC));
@@ -823,14 +822,6 @@ static inline void rrdcalctemplate_free(RRDHOST *host, RRDCALCTEMPLATE *rt) {
822
#define HEALTH_INFO_KEY "info"
823
824
static inline int rrdcalc_add_alarm_from_config(RRDHOST *host, RRDCALC *rc) {
826
- {
827
- char fullname[RRDVAR_MAX_LENGTH + 1];
828
- uint32_t hash = rrdcalc_fullname(fullname, RRDVAR_MAX_LENGTH + 1, rc->chart, rc->name);
829
-
830
- if (rrdcalc_exists(host, fullname, hash))
831
- return 0;
832
- }
833
-
825
if(!rc->chart) {
826
error("Health configuration for alarm '%s' does not have a chart", rc->name);
827
return 0;
@@ -846,6 +837,9 @@ static inline int rrdcalc_add_alarm_from_config(RRDHOST *host, RRDCALC *rc) {
837
return 0;
838
}
839
840
+ if (rrdcalc_exists(host, rc->chart, rc->name, rc->hash_chart, rc->hash))
841
+ return 0;
842
+
843
debug(D_HEALTH, "Health configuration adding alarm '%s.%s': exec '%s', recipient '%s', green %Lf, red %Lf, lookup: group %d, after %d, before %d, options %u, dimensions '%s', update every %d, calculation '%s', warning '%s', critical '%s', source '%s",
844
rc->chart?rc->chart:"NOCHART",
845
rc->name,