]> arthur.barton.de Git - netdata.git/commitdiff
hostname is bundled with the alarm log - preparation to support multi-host alarms
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 6 Sep 2016 23:50:14 +0000 (02:50 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 6 Sep 2016 23:50:14 +0000 (02:50 +0300)
src/health.c
web/dashboard.js

index 613f10606116c2e4f85cc557ace15c9b8f357892..1381e81c5dbaf8a793ed395edccf97ba70cc7fb5 100644 (file)
@@ -1526,8 +1526,9 @@ static inline void health_string2json(BUFFER *wb, const char *prefix, const char
         buffer_sprintf(wb, "%s\"%s\":null%s", prefix, label, suffix);
 }
 
-static inline void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae) {
+static inline void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host) {
     buffer_sprintf(wb, "\n\t{\n"
+                           "\t\t\"hostname\":\"%s\",\n"
                            "\t\t\"unique_id\":%u,\n"
                            "\t\t\"alarm_id\":%u,\n"
                            "\t\t\"alarm_event_id\":%u,\n"
@@ -1549,6 +1550,7 @@ static inline void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae) {
                            "\t\t\"non_clear_duration\":%lu,\n"
                            "\t\t\"status\":\"%s\",\n"
                            "\t\t\"old_status\":\"%s\",\n",
+                   host->hostname,
                    ae->unique_id,
                    ae->alarm_id,
                    ae->alarm_event_id,
@@ -1594,7 +1596,7 @@ void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after) {
     for(ae = host->health_log.alarms; ae && count < max ; count++, ae = ae->next) {
         if(ae->unique_id > after) {
             if(likely(count)) buffer_strcat(wb, ",");
-            health_alarm_entry2json_nolock(wb, ae);
+            health_alarm_entry2json_nolock(wb, ae, host);
         }
     }
 
index 485e5f3e46d657fefa1f6ce030934ff210f13ab9..613a96e568def317c26a29c6c429b60f880d7d36 100644 (file)
@@ -50,8 +50,6 @@
     // global namespace
     var NETDATA = window.NETDATA || {};
 
-    NETDATA.hostname = 'localhost';
-
     // ----------------------------------------------------------------------------------------------------------------
     // Detect the netdata server
 
                 }
                 else NETDATA.error(406, host + '/api/v1/charts');
 
-                NETDATA.hostname = data.hostname;
-
                 if(typeof callback === 'function')
                     callback(data);
             })
             }
 
             var name = entry.name.replace(/_/g, ' ');
+            var status = entry.status.toLowerCase();
             var title = name + ' = ' + ((entry.value === null)?'NaN':Math.floor(entry.value)).toString() + ' ' + entry.units;
-            var body = NETDATA.hostname + ' - ' + entry.chart + ' (' + entry.family + ') - ' + entry.status.toLowerCase() + ': ' + entry.info;
             var tag = entry.alarm_id;
             var icon = 'images/seo-performance-128.png';
             var interaction = false;
                         // console.log('alarm' + entry.unique_id + ' switch to CLEAR from ' + entry.old_status);
                         return;
                     }
-                    title = entry.name + ' back to normal';
+                    title = name + ' back to normal';
                     icon = 'images/check-mark-2-128-green.png'
                     interaction = false;
                     break;
 
                 case 'WARNING':
+                    if(entry.old_status === 'CRITICAL')
+                        status = 'demoted to ' + entry.status.toLowerCase();
+
                     icon = 'images/alert-128-orange.png';
                     interaction = false;
                     break;
 
                 case 'CRITICAL':
+                    if(entry.old_status === 'WARNING')
+                        status = 'escalated to ' + entry.status.toLowerCase();
+                    
                     icon = 'images/alert-128-red.png'
                     interaction = true;
                     break;
                     return;
             }
 
+            var body = entry.hostname + ' - ' + entry.chart + ' (' + entry.family + ') - ' + status + ': ' + entry.info;
+
             // cleanup old notifications with the same alarm_id as this one
             var len = NETDATA.alarms.notifications_shown.length;
             while(len--) {