You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/04/09 15:53:07 UTC

ambari git commit: AMBARI-10299. Unable to save SNMPv1 and SNMPv2c notifications (alexantonenko)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.0 70ff2b27f -> 116d577a5


AMBARI-10299. Unable to save SNMPv1 and SNMPv2c notifications (alexantonenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/116d577a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/116d577a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/116d577a

Branch: refs/heads/branch-2.0.0
Commit: 116d577a504e7848b2ef11c72862dd5e8b8a9a2b
Parents: 70ff2b2
Author: Alex Antonenko <hi...@gmail.com>
Authored: Thu Apr 9 16:53:01 2015 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Thu Apr 9 16:53:01 2015 +0300

----------------------------------------------------------------------
 .../manage_alert_notifications_controller.js    |  59 ++++--
 ambari-web/app/messages.js                      |   5 +
 .../main/alerts/create_alert_notification.hbs   |  48 +++--
 ...anage_alert_notifications_controller_test.js | 184 ++++++++++++++++++-
 4 files changed, 271 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/116d577a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
index 995f2ae..d415036 100644
--- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
+++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
@@ -126,11 +126,26 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       value: '',
       defaultValue: ''
     },
+    OIDSubject: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.OIDSubject'),
+      value: '',
+      defaultValue: ''
+    },
+    OIDBody: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.OIDBody'),
+      value: '',
+      defaultValue: ''
+    },
     community: {
       label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.community'),
       value: '',
       defaultValue: ''
     },
+    host: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.host'),
+      value: '',
+      defaultValue: ''
+    },
     port: {
       label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.port'),
       value: '',
@@ -207,6 +222,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     'ambari.dispatch.recipients',
     'ambari.dispatch.snmp.community',
     'ambari.dispatch.snmp.oids.trap',
+    'ambari.dispatch.snmp.oids.subject',
+    'ambari.dispatch.snmp.oids.body',
     'ambari.dispatch.snmp.port',
     'ambari.dispatch.snmp.version',
     'mail.smtp.auth',
@@ -298,7 +315,11 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     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('OIDSubject.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.oids.subject']);
+    inputFields.set('OIDBody.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.oids.body']);
     inputFields.set('community.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.community']);
+    inputFields.set('host.value', selectedAlertNotification.get('properties')['ambari.dispatch.recipients'] ?
+      selectedAlertNotification.get('properties')['ambari.dispatch.recipients'].join(', ') : '');
     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'));
@@ -342,6 +363,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
           this.emailToValidation();
           this.emailFromValidation();
           this.smtpPortValidation();
+          this.hostsValidation();
           this.portValidation();
           this.retypePasswordValidation();
         },
@@ -384,17 +406,12 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         }.observes('controller.inputFields.name.value'),
 
         emailToValidation: function () {
-          var inputValue = this.get('controller.inputFields.email.value').trim(),
-              emailsTo = inputValue.split(','),
-              emailToError = false,
-              i = emailsTo.length,
-              emailTo;
-          while (i--) {
-            emailTo = emailsTo[i];
-            if (emailTo && !validator.isValidEmail(emailTo.trim())) {
-              emailToError = true;
-              break;
-            }
+          var emailToError = false;
+          if (this.get('isEmailMethodSelected')) {
+            var inputValues = this.get('controller.inputFields.email.value').trim().split(',');
+            emailToError = inputValues.some(function(emailTo) {
+              return emailTo && !validator.isValidEmail(emailTo.trim());
+            })
           }
           this.set('emailToError', emailToError);
           this.set('controller.inputFields.email.errorMsg', emailToError ? Em.I18n.t('alerts.notifications.error.email') : null);
@@ -422,6 +439,19 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
           }
         }.observes('controller.inputFields.SMTPPort.value'),
 
+        hostsValidation: function() {
+          var inputValue = this.get('controller.inputFields.host.value').trim(),
+            hostError = false;;
+          if (!this.get('isEmailMethodSelected')) {
+            var array = inputValue.split(',');
+            hostError = array.some(function(hostname) {
+              return hostname && !validator.isHostname(hostname.trim());
+            });
+            hostError = hostError || inputValue==='';
+          }
+          this.set('hostError', hostError);
+          this.set('controller.inputFields.host.errorMsg', hostError ? Em.I18n.t('alerts.notifications.error.host') : null);
+        }.observes('controller.inputFields.host.value'),
         portValidation: function () {
           var value = this.get('controller.inputFields.port.value');
           if (value && (!validator.isValidInt(value) || value < 0)) {
@@ -447,9 +477,9 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
 
         setParentErrors: function () {
           var hasErrors = this.get('nameError') || this.get('emailToError') || this.get('emailFromError') ||
-            this.get('smtpPortError') || this.get('portError') || this.get('passwordError');
+            this.get('smtpPortError') || this.get('hostError') || this.get('portError') || this.get('passwordError');
           this.set('parentView.hasErrors', hasErrors);
-        }.observes('nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'portError', 'passwordError'),
+        }.observes('nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'passwordError'),
 
 
         groupsSelectView: Em.Select.extend({
@@ -586,7 +616,10 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     } else {
       properties['ambari.dispatch.snmp.version'] = inputFields.get('version.value');
       properties['ambari.dispatch.snmp.oids.trap'] = inputFields.get('OIDs.value');
+      properties['ambari.dispatch.snmp.oids.subject'] = inputFields.get('OIDSubject.value');
+      properties['ambari.dispatch.snmp.oids.body'] = inputFields.get('OIDBody.value');
       properties['ambari.dispatch.snmp.community'] = inputFields.get('community.value');
+      properties['ambari.dispatch.recipients'] = inputFields.get('host.value').replace(/\s/g, '').split(',');
       properties['ambari.dispatch.snmp.port'] = inputFields.get('port.value');
     }
     inputFields.get('customProperties').forEach(function (customProperty) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/116d577a/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 97adb7a..67c0bcd 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -890,6 +890,8 @@ Em.I18n.translations = {
 
   'alerts.notifications.error.email': 'Must be a valid email address',
   'alerts.notifications.error.integer': 'Must be an integer',
+  'alerts.notifications.error.host': 'Hosts must be a valid Fully Qualified Domain Name (FQDN)',
+
   'alerts.notifications.error.retypePassword': 'Password confirmation must match password',
 
   'alerts.notifications.addCustomPropertyPopup.header': 'Add Property',
@@ -1921,7 +1923,10 @@ Em.I18n.translations = {
   '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.OIDSubject':'OID Subject',
+  'alerts.actions.manage_alert_notifications_popup.OIDBody':'OID Body',
   'alerts.actions.manage_alert_notifications_popup.community':'Community',
+  'alerts.actions.manage_alert_notifications_popup.host':'Hosts',
   'alerts.actions.manage_alert_notifications_popup.port':'Port',
   'alerts.actions.manage_alert_notifications_popup.global':'Global',
   'alerts.actions.manage_alert_notifications_popup.noDescription':'<i>No description</i>',

http://git-wip-us.apache.org/repos/asf/ambari/blob/116d577a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs b/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
index 00ba20e..e38d216 100644
--- a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
+++ b/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
@@ -194,11 +194,25 @@
       </div>
 
       <div class="control-group">
-        <label class="control-label">{{controller.inputFields.OIDs.label}}</label>
+          <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 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.OIDSubject.label}}</label>
+
+          <div class="controls">
+            {{view Em.TextField valueBinding="controller.inputFields.OIDSubject.value" class="input-xlarge"}}
+          </div>
+      </div>
+      <div class="control-group">
+          <label class="control-label">{{controller.inputFields.OIDBody.label}}</label>
+
+          <div class="controls">
+            {{view Em.TextField valueBinding="controller.inputFields.OIDBody.value" class="input-xlarge"}}
+          </div>
       </div>
 
       <div class="control-group">
@@ -209,16 +223,28 @@
         </div>
       </div>
 
+      <div {{bindAttr class=":control-group controller.inputFields.host.errorMsg:error"}}>
+          <label class="control-label">{{controller.inputFields.host.label}}</label>
+
+          <div class="controls">
+            {{view Em.TextField valueBinding="controller.inputFields.host.value" class="input-xlarge"}}
+          </div>
+
+          <div class="controls error-msg">
+            {{controller.inputFields.host.errorMsg}}
+          </div>
+      </div>
+
       <div {{bindAttr class=":control-group controller.inputFields.port.errorMsg:error"}}>
-        <label class="control-label">{{controller.inputFields.port.label}}</label>
+          <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 class="controls">
+            {{view Em.TextField valueBinding="controller.inputFields.port.value" class="input-xlarge"}}
+          </div>
 
-        <div class="controls error-msg">
-          {{controller.inputFields.port.errorMsg}}
-        </div>
+          <div class="controls error-msg">
+            {{controller.inputFields.port.errorMsg}}
+          </div>
       </div>
     {{/if}}
     {{! alert-notification email end }}

http://git-wip-us.apache.org/repos/asf/ambari/blob/116d577a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
index b6cbc39..4d3f68d 100644
--- a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
+++ b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
@@ -169,7 +169,7 @@ describe('App.ManageAlertNotificationsController', function () {
 
   describe('#fillEditCreateInputs()', function () {
 
-    it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored)", function () {
+    it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored) - EMAIL", function () {
 
       controller.set('selectedAlertNotification', Em.Object.create({
         name: 'test_name',
@@ -249,9 +249,18 @@ describe('App.ManageAlertNotificationsController', function () {
         OIDs: {
           value: ''
         },
+        OIDSubject: {
+          value: ''
+        },
+        OIDBody: {
+          value: ''
+        },
         community: {
           value: ''
         },
+        host: {
+          value: ''
+        },
         port: {
           value: ''
         },
@@ -315,7 +324,12 @@ describe('App.ManageAlertNotificationsController', function () {
         },
         version: {},
         OIDs: {},
+        OIDSubject: {},
+        OIDBody: {},
         community: {},
+        host: {
+          value: 'test1@test.test, test2@test.test'
+        },
         port: {},
         customProperties: [
           {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
@@ -324,6 +338,174 @@ describe('App.ManageAlertNotificationsController', function () {
 
     });
 
+    it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored) - SNMP", function () {
+
+      controller.set('selectedAlertNotification', Em.Object.create({
+        name: 'test_SNMP_name',
+        global: true,
+        description: 'test_description',
+        groups: ['test1', 'test2'],
+        type: 'SNMP',
+        alertStates: ['OK', 'UNKNOWN'],
+        properties: {
+          'ambari.dispatch.recipients': [
+            'c6401.ambari.apache.org',
+            'c6402.ambari.apache.org'
+          ],
+          'customName': 'customValue',
+          'ambari.dispatch.snmp.version': 'SNMPv1',
+          'ambari.dispatch.snmp.oids.trap': '1',
+          'ambari.dispatch.snmp.oids.subject': 'OID Subject',
+          'ambari.dispatch.snmp.oids.body': 'OID Body',
+          'ambari.dispatch.snmp.community': 'snmp',
+          'ambari.dispatch.snmp.port': 161
+
+        }
+      }));
+
+      controller.set('inputFields', Em.Object.create({
+        name: {
+          value: ''
+        },
+        groups: {
+          value: []
+        },
+        global: {
+          value: false
+        },
+        allGroups: {
+          value: false
+        },
+        method: {
+          value: ''
+        },
+        email: {
+          value: ''
+        },
+        severityFilter: {
+          value: []
+        },
+        description: {
+          value: ''
+        },
+        SMTPServer: {
+          value: ''
+        },
+        SMTPPort: {
+          value: ''
+        },
+        SMTPUseAuthentication: {
+          value: ''
+        },
+        SMTPUsername: {
+          value: ''
+        },
+        SMTPPassword: {
+          value: ''
+        },
+        retypeSMTPPassword: {
+          value: ''
+        },
+        SMTPSTARTTLS: {
+          value: ''
+        },
+        emailFrom: {
+          value: ''
+        },
+        version: {
+          value: ''
+        },
+        OIDs: {
+          value: ''
+        },
+        OIDSubject: {
+          value: ''
+        },
+        OIDBody: {
+          value: ''
+        },
+        community: {
+          value: ''
+        },
+        host: {
+          value: ''
+        },
+        port: {
+          value: ''
+        },
+        customProperties: [
+          {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
+          {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
+        ]
+      }));
+
+      controller.fillEditCreateInputs();
+
+      expect(JSON.stringify(controller.get('inputFields'))).to.equal(JSON.stringify({
+        name: {
+          value: 'test_SNMP_name'
+        },
+        groups: {
+          value: ['test1', 'test2']
+        },
+        global: {
+          value: true,
+          disabled: true
+        },
+        allGroups: {
+          value: 'all'
+        },
+        method: {
+          value: 'SNMP'
+        },
+        email: {
+          value: 'c6401.ambari.apache.org, c6402.ambari.apache.org'
+        },
+        severityFilter: {
+          value: ['OK', 'UNKNOWN']
+        },
+        description: {
+          value: 'test_description'
+        },
+        SMTPServer: {},
+        SMTPPort: {},
+        SMTPUseAuthentication: {
+          value: true
+        },
+        SMTPUsername: {},
+        SMTPPassword: {},
+        retypeSMTPPassword: {},
+        SMTPSTARTTLS: {
+          value: true
+        },
+        emailFrom: {},
+        version: {
+          value:'SNMPv1'
+        },
+        OIDs: {
+          value: '1'
+        },
+        OIDSubject: {
+          value: 'OID Subject'
+        },
+        OIDBody: {
+          value:'OID Body'
+        },
+        community: {
+          value: 'snmp'
+        },
+        host: {
+          value: 'c6401.ambari.apache.org, c6402.ambari.apache.org'
+        },
+        port: {
+          value: 161
+        },
+        customProperties: [
+          {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
+        ]
+      }));
+
+    })
   });
 
   describe("#showCreateEditPopup()", function () {