You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rz...@apache.org on 2017/04/12 21:34:30 UTC
ambari git commit: AMBARI-18423 - Support creating/editing alert
dispatch targets for script-based alert dispatchers by web wizard instead of
command line (Lei Yao via rzang)
Repository: ambari
Updated Branches:
refs/heads/trunk 5ef0c99a9 -> 68b7b5647
AMBARI-18423 - Support creating/editing alert dispatch targets for script-based alert dispatchers by web wizard instead of command line (Lei Yao via rzang)
Change-Id: I417451c88495be07bb68a940a14d37d14b74267f
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/68b7b564
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/68b7b564
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/68b7b564
Branch: refs/heads/trunk
Commit: 68b7b56479dbc22d16e96570e27616a59c96a98a
Parents: 5ef0c99
Author: Richard Zang <rz...@apache.org>
Authored: Wed Apr 12 14:32:53 2017 -0700
Committer: Richard Zang <rz...@apache.org>
Committed: Wed Apr 12 14:32:53 2017 -0700
----------------------------------------------------------------------
.../manage_alert_notifications_controller.js | 28 +++-
ambari-web/app/messages.js | 1 +
.../main/alerts/create_alert_notification.hbs | 12 ++
...anage_alert_notifications_controller_test.js | 165 ++++++++++++++++++-
4 files changed, 200 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/68b7b564/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 73c19c6..df15513 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
@@ -149,6 +149,11 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
value: '',
defaultValue: ''
},
+ scriptDispatchProperty: {
+ label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.scriptDispatchProperty'),
+ value: '',
+ defaultValue: ''
+ },
customProperties: Em.A([])
}),
@@ -167,7 +172,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
* used in Type combobox
* @type {Array}
*/
- methods: ['EMAIL', 'SNMP', 'Custom SNMP'],
+ methods: ['EMAIL', 'SNMP', 'Custom SNMP', 'Alert Script'],
/**
* List of available value for Severity Filter
@@ -283,7 +288,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
'mail.smtp.from',
'mail.smtp.host',
'mail.smtp.port',
- 'mail.smtp.starttls.enable'
+ 'mail.smtp.starttls.enable',
+ 'ambari.dispatch-property.script'
],
validationMap: {
@@ -332,7 +338,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
errorKey: 'hostError',
validator: 'hostsValidation'
}
- ]
+ ],
+ AlertScript:[]
},
/**
@@ -427,6 +434,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
inputFields.set('severityFilter.value', selectedAlertNotification.get('alertStates'));
inputFields.set('global.value', selectedAlertNotification.get('global'));
inputFields.set('allGroups.value', selectedAlertNotification.get('global') ? 'all' : 'custom');
+ inputFields.set('scriptDispatchProperty.value', properties['ambari.dispatch-property.script'] || '');
// not allow to edit global field
inputFields.set('global.disabled', true);
inputFields.set('description.value', selectedAlertNotification.get('description'));
@@ -478,6 +486,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
isCustomSNMPMethodSelected: Em.computed.equal('controller.inputFields.method.value', 'Custom SNMP'),
+ isAlertScriptMethodSelected: Em.computed.equal('controller.inputFields.method.value', 'Alert Script'),
+
methodObserver: function () {
var currentMethod = this.get('controller.inputFields.method.value'),
validationMap = self.get('validationMap');
@@ -557,7 +567,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
hostsValidation: function() {
var inputValue = this.get('controller.inputFields.host.value').trim(),
hostError = false;
- if (!this.get('isEmailMethodSelected')) {
+ if (!this.get('isEmailMethodSelected') && !this.get('isAlertScriptMethodSelected')) {
var array = inputValue.split(',');
hostError = array.some(function(hostname) {
return hostname && !validator.isHostname(hostname.trim());
@@ -757,7 +767,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
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');
- } else {
+ } else if(inputFields.get('method.value') === 'Custom SNMP') {
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('OIDs.value');
@@ -765,6 +775,10 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
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');
+ }else if (inputFields.get('method.value') === 'Alert Script') {
+ var scriptDispatchProperty = inputFields.get('scriptDispatchProperty.value').trim();
+ if( scriptDispatchProperty != '')
+ properties['ambari.dispatch-property.script'] = scriptDispatchProperty;
}
inputFields.get('customProperties').forEach(function (customProperty) {
properties[customProperty.name] = customProperty.value;
@@ -791,6 +805,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
notificationType = "SNMP";
} else if(notificationType === "SNMP") {
notificationType = "AMBARI_SNMP";
+ } else if(notificationType === "Alert Script"){
+ notificationType = "ALERT_SCRIPT";
}
return notificationType;
},
@@ -801,6 +817,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
notificationTypeText = "Custom SNMP";
} else if(notificationType === "AMBARI_SNMP") {
notificationTypeText = "SNMP";
+ } else if(notificationType === "ALERT_SCRIPT"){
+ notificationTypeText = "Alert Script";
}
return notificationTypeText;
},
http://git-wip-us.apache.org/repos/asf/ambari/blob/68b7b564/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index a2edf06..4513775 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -2547,6 +2547,7 @@ Em.I18n.translations = {
'alerts.actions.manage_alert_notifications_popup.confirmDeleteBody':'Are you sure you want to delete {0} notification?',
'alerts.actions.manage_alert_notifications_popup.error.name.empty': 'Notification name is required',
'alerts.actions.manage_alert_notifications_popup.error.name.existed': 'Notification name already exists',
+ 'alerts.actions.manage_alert_notifications_popup.scriptDispatchProperty':'Script Dispatch Property',
'hosts.host.add':'Add New Hosts',
'hosts.table.noHosts':'No hosts to display',
http://git-wip-us.apache.org/repos/asf/ambari/blob/68b7b564/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 5b40bca..7ec5b1e 100644
--- a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
+++ b/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
@@ -315,6 +315,18 @@
{{/if}}
{{! alert-notification Custom SNMP end }}
+ {{! alert-notification Alert Script }}
+ {{#if view.isAlertScriptMethodSelected}}
+ <div class="form-group">
+ <label class="control-label col-md-2">{{controller.inputFields.scriptDispatchProperty.label}}</label>
+
+ <div class="col-md-10">
+ {{view Em.TextField valueBinding="controller.inputFields.scriptDispatchProperty.value" class="form-control"}}
+ </div>
+ </div>
+ {{/if}}
+ {{! alert-notification Alert Script end}}
+
{{! alert-notification custom properties }}
{{#each customProperty in controller.inputFields.customProperties}}
<div class="form-group">
http://git-wip-us.apache.org/repos/asf/ambari/blob/68b7b564/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 31da561..0d58afa 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
@@ -336,6 +336,9 @@ describe('App.ManageAlertNotificationsController', function () {
port: {
value: ''
},
+ scriptDispatchProperty:{
+ value: ''
+ },
customProperties: [
{name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
{name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -401,6 +404,9 @@ describe('App.ManageAlertNotificationsController', function () {
value: 'test1@test.test, test2@test.test'
},
port: {},
+ scriptDispatchProperty:{
+ value: ''
+ },
customProperties: [
{name: 'customName', value: 'customValue', defaultValue: 'customValue'}
]
@@ -495,6 +501,9 @@ describe('App.ManageAlertNotificationsController', function () {
port: {
value: ''
},
+ scriptDispatchProperty:{
+ value: ''
+ },
customProperties: [
{name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
{name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -556,6 +565,9 @@ describe('App.ManageAlertNotificationsController', function () {
port: {
value: 161
},
+ scriptDispatchProperty:{
+ value: ''
+ },
customProperties: [
{name: 'customName', value: 'customValue', defaultValue: 'customValue'}
]
@@ -649,6 +661,9 @@ describe('App.ManageAlertNotificationsController', function () {
port: {
value: ''
},
+ scriptDispatchProperty:{
+ value: ''
+ },
customProperties: [
{name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
{name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -708,12 +723,160 @@ describe('App.ManageAlertNotificationsController', function () {
port: {
value: 161
},
+ scriptDispatchProperty:{
+ value: ''
+ },
customProperties: [
{name: 'customName', value: 'customValue', defaultValue: 'customValue'}
]
}));
- })
+ });
+
+ it("should map properties from selectedAlertNotification to inputFields - ALERT_SCRIPT", function () {
+
+ controller.set('selectedAlertNotification', Em.Object.create({
+ name: 'test_alert_script',
+ global: true,
+ description: 'test_description',
+ groups: ['test1', 'test2'],
+ type: 'ALERT_SCRIPT',
+ alertStates: ['OK', 'UNKNOWN'],
+ properties: {
+ 'ambari.dispatch-property.script': "com.mycompany.dispatch.syslog.script",
+ 'customName': 'customValue'
+ }
+ }));
+
+ 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: ''
+ },
+ community: {
+ value: ''
+ },
+ host: {
+ value: ''
+ },
+ port: {
+ value: ''
+ },
+ scriptDispatchProperty: {
+ 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_alert_script'
+ },
+ groups: {
+ value: ['test1', 'test2']
+ },
+ global: {
+ value: true,
+ disabled: true
+ },
+ allGroups: {
+ value: 'all'
+ },
+ method: {
+ value: 'Alert Script'
+ },
+ email: {
+ value: ''
+ },
+ severityFilter: {
+ value: ['OK', 'UNKNOWN']
+ },
+ description: {
+ value: 'test_description'
+ },
+ SMTPServer: {},
+ SMTPPort: {},
+ SMTPUseAuthentication: {
+ value: true
+ },
+ SMTPUsername: {},
+ SMTPPassword: {},
+ retypeSMTPPassword: {},
+ SMTPSTARTTLS: {
+ value: true
+ },
+ emailFrom: {},
+ version: {},
+ OIDs: {},
+ community: {},
+ host: {
+ value: ''
+ },
+ port: {},
+ scriptDispatchProperty: {
+ value: 'com.mycompany.dispatch.syslog.script'
+ },
+ customProperties: [
+ {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
+ ]
+ }));
+
+ });
});
describe("#showCreateEditPopup()", function () {