summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2020-06-29 22:12:08 +0300
committerGitHub <noreply@github.com>2020-06-29 22:12:08 +0300
commitadc37259c2b158232e8faf0c9806df1546558044 (patch)
tree984f3b35c58b1e7fb3c892dde9772711fbf347b6 /database
parent5d21a9d5427a35a251d64ed372d3d5e16e016474 (diff)
Fixed duplicate alarm ids in health-log.db (#9428)
Fixed duplicate alarm ids in health-log.db
Diffstat (limited to 'database')
-rw-r--r--database/rrdcalc.c3
-rw-r--r--database/rrdhost.c60
2 files changed, 33 insertions, 30 deletions
diff --git a/database/rrdcalc.c b/database/rrdcalc.c
index 23303a81bd..1d7b15dd0d 100644
--- a/database/rrdcalc.c
+++ b/database/rrdcalc.c
@@ -252,6 +252,9 @@ inline uint32_t rrdcalc_get_unique_id(RRDHOST *host, const char *chart, const ch
}
}
+ if (unlikely(!host->health_log.next_alarm_id))
+ host->health_log.next_alarm_id = (uint32_t)now_realtime_sec();
+
return host->health_log.next_alarm_id++;
}
diff --git a/database/rrdhost.c b/database/rrdhost.c
index ff8bbd56f8..6c909197d2 100644
--- a/database/rrdhost.c
+++ b/database/rrdhost.c
@@ -199,8 +199,8 @@ RRDHOST *rrdhost_create(const char *hostname,
host->health_log.next_log_id = 1;
host->health_log.next_alarm_id = 1;
host->health_log.max = 1000;
- host->health_log.next_log_id =
- host->health_log.next_alarm_id = (uint32_t)now_realtime_sec();
+ host->health_log.next_log_id = (uint32_t)now_realtime_sec();
+ host->health_log.next_alarm_id = 0;
long n = config_get_number(CONFIG_SECTION_HEALTH, "in memory max health log entries", host->health_log.max);
if(n < 10) {
@@ -243,6 +243,34 @@ RRDHOST *rrdhost_create(const char *hostname,
}
}
+
+ if(host->health_enabled) {
+ snprintfz(filename, FILENAME_MAX, "%s/health", host->varlib_dir);
+ int r = mkdir(filename, 0775);
+ if(r != 0 && errno != EEXIST)
+ error("Host '%s': cannot create directory '%s'", host->hostname, filename);
+ }
+
+ snprintfz(filename, FILENAME_MAX, "%s/health/health-log.db", host->varlib_dir);
+ host->health_log_filename = strdupz(filename);
+
+ snprintfz(filename, FILENAME_MAX, "%s/alarm-notify.sh", netdata_configured_primary_plugins_dir);
+ host->health_default_exec = strdupz(config_get(CONFIG_SECTION_HEALTH, "script to execute on alarm", filename));
+ host->health_default_recipient = strdupz("root");
+
+
+ // ------------------------------------------------------------------------
+ // load health configuration
+
+ if(host->health_enabled) {
+ rrdhost_wrlock(host);
+ health_readdir(host, health_user_config_dir(), health_stock_config_dir(), NULL);
+ rrdhost_unlock(host);
+
+ health_alarm_log_load(host);
+ health_alarm_log_open(host);
+ }
+
if (host->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
#ifdef ENABLE_DBENGINE
if (unlikely(-1 == uuid_parse(host->machine_guid, host->host_uuid))) {
@@ -273,34 +301,6 @@ RRDHOST *rrdhost_create(const char *hostname,
#endif
}
- if(host->health_enabled) {
- snprintfz(filename, FILENAME_MAX, "%s/health", host->varlib_dir);
- int r = mkdir(filename, 0775);
- if(r != 0 && errno != EEXIST)
- error("Host '%s': cannot create directory '%s'", host->hostname, filename);
- }
-
- snprintfz(filename, FILENAME_MAX, "%s/health/health-log.db", host->varlib_dir);
- host->health_log_filename = strdupz(filename);
-
- snprintfz(filename, FILENAME_MAX, "%s/alarm-notify.sh", netdata_configured_primary_plugins_dir);
- host->health_default_exec = strdupz(config_get(CONFIG_SECTION_HEALTH, "script to execute on alarm", filename));
- host->health_default_recipient = strdupz("root");
-
-
- // ------------------------------------------------------------------------
- // load health configuration
-
- if(host->health_enabled) {
- rrdhost_wrlock(host);
- health_readdir(host, health_user_config_dir(), health_stock_config_dir(), NULL);
- rrdhost_unlock(host);
-
- health_alarm_log_load(host);
- health_alarm_log_open(host);
- }
-
-
// ------------------------------------------------------------------------
// link it and add it to the index