Jelajahi Sumber

AMBARI-8568. Alerts UI: Need alert-notification type specific UI fields. (akovalenko)

Aleksandr Kovalenko 10 tahun lalu
induk
melakukan
9cdd4e2448

+ 58 - 1
ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js

@@ -67,6 +67,41 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       value: '',
       defaultValue: ''
     },
+    SMTPServer: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.SMTPServer'),
+      value: '',
+      defaultValue: ''
+    },
+    SMTPPort: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.SMTPPort'),
+      value: '',
+      defaultValue: ''
+    },
+    emailFrom: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.emailFrom'),
+      value: '',
+      defaultValue: ''
+    },
+    version: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.version'),
+      value: '',
+      defaultValue: ''
+    },
+    OIDs: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.OIDs'),
+      value: '',
+      defaultValue: ''
+    },
+    community: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.community'),
+      value: '',
+      defaultValue: ''
+    },
+    port: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.port'),
+      value: '',
+      defaultValue: ''
+    },
     severityFilter: {
       label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.severityFilter'),
       value: [],
@@ -94,6 +129,12 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
    */
   severities: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN'],
 
+  /**
+   * List of available SNMP versions
+   * @type {Array}
+   */
+  SNMPVersions: ['SNMPv1', 'SNMPv2c', 'SNMPv3'],
+
   /**
    * List of all Alert Notifications
    * @type {App.AlertNotification[]}
@@ -126,7 +167,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
    * List custom property names that shouldn't be displayed on Edit page
    * @type {string[]}
    */
-  ignoredCustomProperties: ['ambari.dispatch.recipients'],
+  ignoredCustomProperties: ['ambari.dispatch.recipients', 'mail.smtp.host', 'mail.smtp.port', 'mail.smtp.from', 'ambari.dispatch.snmp.version',
+    'ambari.dispatch.snmp.oids.trap', 'ambari.dispatch.snmp.community', 'ambari.dispatch.snmp.port'],
 
   /**
    * Load all Alert Notifications from server
@@ -195,6 +237,13 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     inputFields.set('groups.value', selectedAlertNotification.get('groups').toArray());
     inputFields.set('email.value', selectedAlertNotification.get('properties')['ambari.dispatch.recipients'] ?
         selectedAlertNotification.get('properties')['ambari.dispatch.recipients'].join(', ') : '');
+    inputFields.set('SMTPServer.value', selectedAlertNotification.get('properties')['mail.smtp.host']);
+    inputFields.set('SMTPPort.value', selectedAlertNotification.get('properties')['mail.smtp.port']);
+    inputFields.set('emailFrom.value', selectedAlertNotification.get('properties')['mail.smtp.from']);
+    inputFields.set('version.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.version']);
+    inputFields.set('OIDs.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.oids.trap']);
+    inputFields.set('community.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.community']);
+    inputFields.set('port.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.port']);
     inputFields.set('severityFilter.value', selectedAlertNotification.get('alertStates'));
     inputFields.set('global.value', selectedAlertNotification.get('global'));
     // not allow to edit global field
@@ -310,6 +359,14 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     var clusterId = App.Cluster.find().objectAt(0).get('id');
     if (inputFields.get('method.value') === 'EMAIL') {
       properties['ambari.dispatch.recipients'] = inputFields.get('email.value').replace(/\s/g, '').split(',');
+      properties['mail.smtp.host'] = inputFields.get('SMTPServer.value');
+      properties['mail.smtp.port'] = inputFields.get('SMTPPort.value');
+      properties['mail.smtp.from'] = inputFields.get('emailFrom.value');
+    } else {
+      properties['ambari.dispatch.snmp.version'] = inputFields.get('version.value');
+      properties['ambari.dispatch.snmp.oids.trap'] = inputFields.get('OIDs.value');
+      properties['ambari.dispatch.snmp.community'] = inputFields.get('community.value');
+      properties['ambari.dispatch.snmp.port'] = inputFields.get('port.value');
     }
     inputFields.get('customProperties').forEach(function (customProperty) {
       properties[customProperty.name] = customProperty.value;

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

@@ -1862,7 +1862,14 @@ Em.I18n.translations = {
   'alerts.actions.manage_alert_notifications_popup.editHeader':'Edit Notification',
   'alerts.actions.manage_alert_notifications_popup.duplicateButton':'Duplicate Alert Notification',
   'alerts.actions.manage_alert_notifications_popup.method':'Method',
-  'alerts.actions.manage_alert_notifications_popup.email':'Email',
+  'alerts.actions.manage_alert_notifications_popup.email':'Email To',
+  'alerts.actions.manage_alert_notifications_popup.SMTPServer':'SMTP Server',
+  'alerts.actions.manage_alert_notifications_popup.SMTPPort':'SMTP Port',
+  'alerts.actions.manage_alert_notifications_popup.emailFrom':'Email From',
+  'alerts.actions.manage_alert_notifications_popup.version':'Version',
+  'alerts.actions.manage_alert_notifications_popup.OIDs':'OIDs',
+  'alerts.actions.manage_alert_notifications_popup.community':'Community',
+  'alerts.actions.manage_alert_notifications_popup.port':'Port',
   'alerts.actions.manage_alert_notifications_popup.global':'Global',
   'alerts.actions.manage_alert_notifications_popup.severityFilter':'Severity Filter',
   'alerts.actions.manage_alert_notifications_popup.clearAll':'Clear All',

+ 50 - 0
ambari-web/app/templates/main/alerts/create_alert_notification.hbs

@@ -87,6 +87,56 @@
           {{view Em.TextField valueBinding="controller.inputFields.email.value" id="inputEmail" class="input-xlarge"}}
         </div>
       </div>
+      <div class="control-group">
+        <label class="control-label">{{controller.inputFields.SMTPServer.label}}</label>
+
+        <div class="controls">
+          {{view Em.TextField valueBinding="controller.inputFields.SMTPServer.value" class="input-xlarge"}}
+        </div>
+      </div>
+      <div class="control-group">
+        <label class="control-label">{{controller.inputFields.SMTPPort.label}}</label>
+
+        <div class="controls">
+          {{view Em.TextField valueBinding="controller.inputFields.SMTPPort.value" class="input-xlarge"}}
+        </div>
+      </div>
+      <div class="control-group">
+        <label class="control-label">{{controller.inputFields.emailFrom.label}}</label>
+
+        <div class="controls">
+          {{view Em.TextField valueBinding="controller.inputFields.emailFrom.value" class="input-xlarge"}}
+        </div>
+      </div>
+    {{else}}
+      <div class="control-group">
+        <label class="control-label">{{controller.inputFields.version.label}}</label>
+
+        <div class="controls">
+          {{view Em.Select selectionBinding="controller.inputFields.version.value" contentBinding="controller.SNMPVersions" class="input-xlarge"}}
+        </div>
+      </div>
+      <div class="control-group">
+        <label class="control-label">{{controller.inputFields.OIDs.label}}</label>
+
+        <div class="controls">
+          {{view Em.TextField valueBinding="controller.inputFields.OIDs.value" class="input-xlarge"}}
+        </div>
+      </div>
+      <div class="control-group">
+        <label class="control-label">{{controller.inputFields.community.label}}</label>
+
+        <div class="controls">
+          {{view Em.TextField valueBinding="controller.inputFields.community.value" class="input-xlarge"}}
+        </div>
+      </div>
+      <div class="control-group">
+        <label class="control-label">{{controller.inputFields.port.label}}</label>
+
+        <div class="controls">
+          {{view Em.TextField valueBinding="controller.inputFields.port.value" class="input-xlarge"}}
+        </div>
+      </div>
     {{/if}}
 
     {{#each customProperty in controller.inputFields.customProperties}}

+ 30 - 2
ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js

@@ -207,6 +207,27 @@ describe('App.ManageAlertNotificationsController', function () {
         description: {
           value: ''
         },
+        SMTPServer: {
+          value: ''
+        },
+        SMTPPort: {
+          value: ''
+        },
+        emailFrom: {
+          value: ''
+        },
+        version: {
+          value: ''
+        },
+        OIDs: {
+          value: ''
+        },
+        community: {
+          value: ''
+        },
+        port: {
+          value: ''
+        },
         customProperties: [
           {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
           {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -238,6 +259,13 @@ describe('App.ManageAlertNotificationsController', function () {
         description: {
           value: 'test_description'
         },
+        SMTPServer: {},
+        SMTPPort: {},
+        emailFrom: {},
+        version: {},
+        OIDs: {},
+        community: {},
+        port: {},
         customProperties: [
           {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
         ]
@@ -321,7 +349,7 @@ describe('App.ManageAlertNotificationsController', function () {
 
       var result = controller.formatNotificationAPIObject();
 
-      expect(result).to.eql({
+      expect(JSON.stringify(result)).to.eql(JSON.stringify({
         AlertTarget: {
           name: 'test_name',
           description: 'test_description',
@@ -340,7 +368,7 @@ describe('App.ManageAlertNotificationsController', function () {
             'n2': 'v2'
           }
         }
-      });
+      }));
     });
 
   });