113
netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
114
}
115
116
+static inline void health_rrdcalc_values2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC *rc) {
117
+ (void)host;
118
+ buffer_sprintf(wb,
119
+ "\t\t\"%s.%s\": {\n"
120
+ "\t\t\t\"id\": %lu,\n"
121
+ , rc->chart, rc->name
122
+ , (unsigned long)rc->id);
123
+
124
+ buffer_strcat(wb, "\t\t\t\"value\":");
125
+ buffer_rrd_value(wb, rc->value);
126
+ buffer_strcat(wb, ",\n");
127
+
128
+ buffer_sprintf(wb,
129
+ "\t\t\t\"status\": \"%s\"\n"
130
+ , rrdcalc_status2string(rc->status));
131
+
132
+ buffer_strcat(wb, "\t\t}");
133
+}
134
+
135
static inline void health_rrdcalc2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC *rc) {
136
char value_string[100 + 1];
137
format_value_and_unit(value_string, 100, rc->value, rc->units, -1);
291
rrdhost_unlock(host);
292
}
293
275
-void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) {
294
+void health_alarms2json_fill_alarms(RRDHOST *host, BUFFER *wb, int all, void (*fp)(RRDHOST *, BUFFER *, RRDCALC *)) {
295
+ RRDCALC *rc;
296
int i;
297
+ for(i = 0, rc = host->alarms; rc ; rc = rc->next) {
298
+ if(unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec))
299
+ continue;
300
+
301
+ if(likely(!all && !(rc->status == RRDCALC_STATUS_WARNING || rc->status == RRDCALC_STATUS_CRITICAL)))
302
+ continue;
303
+
304
+ if(likely(i)) buffer_strcat(wb, ",\n");
305
+ fp(host, wb, rc);
306
+ i++;
307
+ }
308
+}
309
310
+void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) {
311
rrdhost_rdlock(host);
312
buffer_sprintf(wb, "{\n\t\"hostname\": \"%s\","
313
"\n\t\"latest_alarm_log_unique_id\": %u,"
319
host->health_enabled?"true":"false",
320
(unsigned long)now_realtime_sec());
321
289
- RRDCALC *rc;
290
- for(i = 0, rc = host->alarms; rc ; rc = rc->next) {
291
- if(unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec))
292
- continue;
293
-
294
- if(likely(!all && !(rc->status == RRDCALC_STATUS_WARNING || rc->status == RRDCALC_STATUS_CRITICAL)))
295
- continue;
296
-
297
- if(likely(i)) buffer_strcat(wb, ",\n");
298
- health_rrdcalc2json_nolock(host, wb, rc);
299
- i++;
300
- }
322
+ health_alarms2json_fill_alarms(host, wb, all, health_rrdcalc2json_nolock);
323
324
// buffer_strcat(wb, "\n\t},\n\t\"templates\": {");
325
// RRDCALCTEMPLATE *rt;
330
rrdhost_unlock(host);
331
}
332
333
+void health_alarms_values2json(RRDHOST *host, BUFFER *wb, int all) {
334
+ rrdhost_rdlock(host);
335
+ buffer_sprintf(wb, "{\n\t\"hostname\": \"%s\","
336
+ "\n\t\"alarms\": {\n",
337
+ host->hostname);
338
339
+ health_alarms2json_fill_alarms(host, wb, all, health_rrdcalc_values2json_nolock);
340
341
+ buffer_strcat(wb, "\n\t}\n}\n");
342
+ rrdhost_unlock(host);
343
+}