+// health alarm log load/save
+// no need for locking - only one thread is reading / writing the alarms log
+
+static inline int health_alarm_log_open(void) {
+ if(health.log_fp)
+ fclose(health.log_fp);
+
+ health.log_fp = fopen(health.log_filename, "a");
+
+ if(health.log_fp) {
+ if (setvbuf(health.log_fp, NULL, _IOLBF, 0) != 0)
+ error("Cannot set line buffering on health log file.");
+ return 0;
+ }
+
+ error("Cannot open health log file '%s'. Health data will be lost in case of netdata or server crash.", health.log_filename);
+ return -1;
+}
+
+static inline void health_alarm_log_close(void) {
+ if(health.log_fp) {
+ fclose(health.log_fp);
+ health.log_fp = NULL;
+ }
+}
+
+static inline void health_log_recreate(void) {
+ if(health.log_fp != NULL) {
+ health_alarm_log_close();
+
+ // open it with truncate
+ health.log_fp = fopen(health.log_filename, "w");
+ if(health.log_fp) fclose(health.log_fp);
+ else error("Cannot truncate health log '%s'", health.log_filename);
+
+ health.log_fp = NULL;
+
+ health_alarm_log_open();
+ }
+}
+
+static inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae) {
+ (void)host;
+ (void)ae;
+
+/* if(likely(health.log_fp)) {
+ if(unlikely(fprintf(health.log_fp, "A\t%s\t%08x\t%08x\t%08x\t%08x\t%08x\t%08x\t%s\t%s\t%s\t%s\t%s\t%08x\n",
+ host->hostname,
+ ae->unique_id,
+ ae->alarm_id,
+ ae->alarm_event_id,
+ (uint32_t)ae->when,
+ (uint32_t)ae->duration,
+ (uint32_t)ae->non_clear_duration,
+ (uint32_t)ae->exec_run_timestamp,
+ ae->name,
+ ae->chart,
+ ae->family,
+ ae->exec,
+ ae->recipient
+ ) < 0))
+ error("Health: failed to save alarm log entry. Health data may be lost in case of abnormal restart.");
+ }
+*/
+}
+
+static inline void health_alarm_log_load(RRDHOST *host) {
+ (void)host;
+
+}
+
+// ----------------------------------------------------------------------------
+// health alarm log management