@cryptotaxi247 / netdata-1 / commits / 452fc2662

hostname is bundled with the alarm log - preparation to support multi-host alarms

Costa Tsaousis (ktsaou) committed Sep 7, 2016 at 02:50 UTC 452fc2662545e8b144022e145838a8da53337e8f
2 files changed +14 -8
src/health.c
+4 -2
@@ -1526,8 +1526,9 @@ static inline void health_string2json(BUFFER *wb, const char *prefix, const char
1526 buffer_sprintf(wb, "%s\"%s\":null%s", prefix, label, suffix);
1527 }
1528
1529 -static inline void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae) {
1529 +static inline void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host) {
1530 buffer_sprintf(wb, "\n\t{\n"
1531 + "\t\t\"hostname\":\"%s\",\n"
1532 "\t\t\"unique_id\":%u,\n"
1533 "\t\t\"alarm_id\":%u,\n"
1534 "\t\t\"alarm_event_id\":%u,\n"
@@ -1549,6 +1550,7 @@ static inline void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae) {
1550 "\t\t\"non_clear_duration\":%lu,\n"
1551 "\t\t\"status\":\"%s\",\n"
1552 "\t\t\"old_status\":\"%s\",\n",
1553 + host->hostname,
1554 ae->unique_id,
1555 ae->alarm_id,
1556 ae->alarm_event_id,
@@ -1594,7 +1596,7 @@ void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after) {
1596 for(ae = host->health_log.alarms; ae && count < max ; count++, ae = ae->next) {
1597 if(ae->unique_id > after) {
1598 if(likely(count)) buffer_strcat(wb, ",");
1597 - health_alarm_entry2json_nolock(wb, ae);
1599 + health_alarm_entry2json_nolock(wb, ae, host);
1600 }
1601 }
1602
web/dashboard.js
+10 -6
@@ -50,8 +50,6 @@
50 // global namespace
51 var NETDATA = window.NETDATA || {};
52
53 - NETDATA.hostname = 'localhost';
54 -
53 // ----------------------------------------------------------------------------------------------------------------
54 // Detect the netdata server
55
@@ -633,8 +631,6 @@
631 }
632 else NETDATA.error(406, host + '/api/v1/charts');
633
636 - NETDATA.hostname = data.hostname;
637 -
634 if(typeof callback === 'function')
635 callback(data);
636 })
@@ -5608,8 +5604,8 @@
5604 }
5605
5606 var name = entry.name.replace(/_/g, ' ');
5607 + var status = entry.status.toLowerCase();
5608 var title = name + ' = ' + ((entry.value === null)?'NaN':Math.floor(entry.value)).toString() + ' ' + entry.units;
5612 - var body = NETDATA.hostname + ' - ' + entry.chart + ' (' + entry.family + ') - ' + entry.status.toLowerCase() + ': ' + entry.info;
5609 var tag = entry.alarm_id;
5610 var icon = 'images/seo-performance-128.png';
5611 var interaction = false;
@@ -5633,17 +5629,23 @@
5629 // console.log('alarm' + entry.unique_id + ' switch to CLEAR from ' + entry.old_status);
5630 return;
5631 }
5636 - title = entry.name + ' back to normal';
5632 + title = name + ' back to normal';
5633 icon = 'images/check-mark-2-128-green.png'
5634 interaction = false;
5635 break;
5636
5637 case 'WARNING':
5638 + if(entry.old_status === 'CRITICAL')
5639 + status = 'demoted to ' + entry.status.toLowerCase();
5640 +
5641 icon = 'images/alert-128-orange.png';
5642 interaction = false;
5643 break;
5644
5645 case 'CRITICAL':
5646 + if(entry.old_status === 'WARNING')
5647 + status = 'escalated to ' + entry.status.toLowerCase();
5648 +
5649 icon = 'images/alert-128-red.png'
5650 interaction = true;
5651 break;
@@ -5653,6 +5655,8 @@
5655 return;
5656 }
5657
5658 + var body = entry.hostname + ' - ' + entry.chart + ' (' + entry.family + ') - ' + status + ': ' + entry.info;
5659 +
5660 // cleanup old notifications with the same alarm_id as this one
5661 var len = NETDATA.alarms.notifications_shown.length;
5662 while(len--) {