فهرست منبع

AMBARI-1071. Nagios alerts not updating in UI. (Srimanth Gunturi via yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1431584 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 سال پیش
والد
کامیت
46a5083e4d

+ 2 - 0
CHANGES.txt

@@ -639,6 +639,8 @@ AMBARI-666 branch (unreleased changes)
 
   BUG FIXES
 
+  AMBARI-1071. Nagios alerts not updating in UI. (Srimanth Gunturi via yusaku)
+
   AMBARI-1063. Workflow Web Service potentially leaks DB connections upon
   exceptions. (yusaku)
 

+ 1 - 1
ambari-web/app/app.js

@@ -63,7 +63,7 @@ DS.attr.transforms.date = {
   to: function (deserialized) {
     if (deserialized instanceof Date) {
       return deserialized.getTime();
-    } else if (date === undefined) {
+    } else if (deserialized === undefined) {
       return undefined;
     } else {
       return null;

+ 1 - 1
ambari-web/app/controllers/global/cluster_controller.js

@@ -169,7 +169,7 @@ App.ClusterController = Em.Controller.extend({
       var statusDiff = right.get('status') - left.get('status');
       if (statusDiff == 0) { // same error severity - sort by time
         var rightTime = right.get('date');
-        var leftTime = left.get('time');
+        var leftTime = left.get('date');
         rightTime = rightTime ? rightTime.getTime() : 0;
         leftTime = leftTime ? leftTime.getTime() : 0;
         statusDiff = rightTime - leftTime;

+ 32 - 8
ambari-web/app/mappers/alerts_mapper.js

@@ -31,7 +31,7 @@ App.alertsMapper = App.QuickDataMapper.create({
     last_hard_state_change: "last_hard_state_change",
     last_hard_state: "last_hard_state",
     last_time_ok: "last_time_ok",
-    last_wime_warning: "last_time_warning",
+    last_time_warning: "last_time_warning",
     last_time_unknown: "last_time_unknown",
     last_time_critical: "last_time_critical",
     is_flapping: "is_flapping",
@@ -54,14 +54,38 @@ App.alertsMapper = App.QuickDataMapper.create({
     }
   },
   update: function(json){
-    var alerts = App.Alert.find();
-    var result = [];
-    json.alerts.forEach(function (item) {
-      if (!alerts.filterProperty('title', item.service_description).length) {
-        result.push(this.parseIt(item, this.config));
+    var alertsList = App.Alert.find();
+    var titleToAlertMap = {};
+    alertsList.forEach(function(alert){
+      titleToAlertMap[alert.get('serviceType') + alert.get('title') + alert.get('message')] = alert;
+    });
+    var newRecords = [];
+    json.alerts.forEach(function(item){
+      var existAlert = titleToAlertMap[item.service_type + item.service_description + item.plugin_output];
+      if (existAlert == null) {
+        newRecords.push(this.parseIt(item, this.config));
+      } else {
+        // update record
+        existAlert.set('serviceType', item.service_type);
+        existAlert.set('date', DS.attr.transforms.date.from(item.last_hard_state_change));
+        existAlert.set('status', item.current_state);
+        existAlert.set('message', item.plugin_output);
+        existAlert.set('lastHardStateChange', item.last_hard_state_change);
+        existAlert.set('lastHardState', item.last_hard_state);
+        existAlert.set('lastTimeOk', item.last_time_ok);
+        existAlert.set('lastTimeWarning', item.last_time_warning);
+        existAlert.set('lastTimeUnknown', item.last_time_unknown);
+        existAlert.set('lastTimeCritical', item.last_time_critical);
+        existAlert.set('lastCheck', item.last_check);
+        existAlert.set('isFlapping', item.is_flapping);
+        delete titleToAlertMap[item.service_type + item.service_description + item.plugin_output];
       }
     }, this);
-    App.store.loadMany(this.get('model'), result);
-
+    for ( var e in titleToAlertMap) {
+      titleToAlertMap[e].deleteRecord();
+    }
+    if (newRecords.length > 0) {
+      App.store.loadMany(this.get('model'), newRecords); // Add new records
+    }
   }
 });

+ 8 - 0
ambari-web/app/models/alert.js

@@ -45,6 +45,7 @@ App.Alert = DS.Model.extend({
   lastTimeCritical: DS.attr('number'),
   isFlapping: DS.attr('number'),
   lastCheck: DS.attr('number'),
+
   /**
    * Used to show correct icon in UI
    */
@@ -52,6 +53,13 @@ App.Alert = DS.Model.extend({
     return this.get('status') == "0";
   }.property('status'),
 
+  /**
+   * Used to show correct icon in UI
+   */
+  isWarning: function () {
+    return this.get('status') == "1";
+  }.property('status'),
+
   /**
    * Provides how long ago this alert happened.
    * 

+ 4 - 0
ambari-web/app/styles/application.less

@@ -190,6 +190,10 @@ h1 {
   color: #5AB400;
 }
 
+.icon-warning-sign {
+  color: #FDB82F;
+}
+
 .icon-empty {
   height: 21px;
   display: inline-block;

+ 5 - 1
ambari-web/app/templates/main/service/info/summary_alert.hbs

@@ -22,7 +22,11 @@
           {{#if isOk}}
               <i class="icon-ok icon-large"></i>
           {{else}}
-              <i class="icon-remove icon-large"></i>
+	          {{#if isWarning}}
+	              <i class="icon-warning-sign icon-large"></i>
+	          {{else}}
+	              <i class="icon-remove icon-large"></i>
+	          {{/if}}
           {{/if}}
         </div>
         <div class="span11">