From: KIRAN KASHALKAR Date: Wed, 19 Oct 2016 20:14:50 +0000 (-0400) Subject: RIFT-14856: launchpad UI - Logging - default category severity X-Git-Tag: v1.0.1~10^2~7^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F49%2F549%2F1;p=osm%2FUI.git RIFT-14856: launchpad UI - Logging - default category severity Signed-off-by: KIRAN KASHALKAR --- diff --git a/skyquake/plugins/logging/api/logging.js b/skyquake/plugins/logging/api/logging.js index 00cd1d63c..a3bc18221 100644 --- a/skyquake/plugins/logging/api/logging.js +++ b/skyquake/plugins/logging/api/logging.js @@ -322,6 +322,34 @@ Config.deleteDefaultSeverity = function(req) { } +// NOTE: In rel_4.3 we are going to affect syslog sink category by default + +Config.setDefaultSyslogSeverity = function(req) { + // TODO: verify there is one key at root of data: 'default-severity' + // OR just filter on the request body + return handlePutRequest(req, APIVersion + '/api/config/logging/sink/syslog'); +} + +Config.deleteDefaultSyslogSeverity = function(req) { + // TODO: verify there is one key at root of data: 'default-severity' + // OR just filter on the request body + var Categories = req.body; + return new Promise(function(resolve, reject) { + var promises = Categories.map(function(categoryName) { + return handleDeleteRequest(req, APIVersion + '/api/config/logging/sink/syslog/filter/category/' + categoryName); + }); + return Promise.all(promises).then( + function(data) { + resolve(data[0]); + }, + function(data) { + reject(data); + } + ) + }) + +} + /* get body of forms diff --git a/skyquake/plugins/logging/routes.js b/skyquake/plugins/logging/routes.js index af410c2e8..6c6df7860 100644 --- a/skyquake/plugins/logging/routes.js +++ b/skyquake/plugins/logging/routes.js @@ -64,6 +64,16 @@ var loggingRoutes = [ endpoint: '/api/config/default-severity', apiHandler: loggingAPI['config'].deleteDefaultSeverity }, + { + method: 'PUT', + endpoint: '/api/config/default-syslog-severity', + apiHandler: loggingAPI['config'].setDefaultSyslogSeverity + }, + { + method: 'DELETE', + endpoint: '/api/config/default-syslog-severity', + apiHandler: loggingAPI['config'].deleteDefaultSyslogSeverity + }, { method: 'PUT', endpoint: '/api/config/allow-duplicate-events', diff --git a/skyquake/plugins/logging/src/categorySeverityGrid.jsx b/skyquake/plugins/logging/src/categorySeverityGrid.jsx index 86a42c166..12cb99cdf 100644 --- a/skyquake/plugins/logging/src/categorySeverityGrid.jsx +++ b/skyquake/plugins/logging/src/categorySeverityGrid.jsx @@ -27,17 +27,29 @@ export default class CategorySeverityGrid extends React.Component { generateRows(defaultSeverities, severityOptions) { let self = this; return defaultSeverities.map(function(catsev) { + // let dropList = (); let dropList = (); - return [catsev.category, dropList]; + onChange={self.onChangeSyslogSeverity(catsev.name)} />); + return [catsev.name, dropList]; }); } - onChangeSeverity (category) { + // onChangeSeverity (category) { + // return function(e) { + // LoggingStore.updateCategoryDefaultSeverity({ + // category: category, + // severity: e + // }); + // } + // } + + onChangeSyslogSeverity (name) { return function(e) { - LoggingStore.updateCategoryDefaultSeverity({ - category: category, + LoggingStore.updateCategoryDefaultSyslogSeverity({ + name: name, severity: e }); } @@ -60,7 +72,7 @@ export default class CategorySeverityGrid extends React.Component { CategorySeverityGrid.defaultProps = { cellLabels: [ - 'Category', 'Severity' + 'Name', 'Severity' ], columnClasses: [ 'category', 'severity' diff --git a/skyquake/plugins/logging/src/loggingGeneral.jsx b/skyquake/plugins/logging/src/loggingGeneral.jsx index dd04a57a7..7b50c7605 100644 --- a/skyquake/plugins/logging/src/loggingGeneral.jsx +++ b/skyquake/plugins/logging/src/loggingGeneral.jsx @@ -42,7 +42,7 @@ class DefaultCategorySeverityPanel extends React.Component { return ( + title="Syslog Category Severity"> @@ -223,45 +223,60 @@ export default class LoggingGeneral extends React.Component { isLoading: true }); LoggingStore.updateLoggingConfig( - this.collectNulledCategories( + /* this.collectNulledCategories( this.state.initialLoggingConfig, this.state.loggingConfig), - this.removeCategoryNulls( - this.state.loggingConfig - ) - ); + this.removeCategoryNulls( + this.state.loggingConfig */ + this.state.nulledCategories, + this.cleanupConfig( + this.state.loggingConfig + ) + ) } else { console.log("LoggingGeneral.handleSave failed validation"); } this.context.router.push({pathname: ''}); } - removeCategoryNulls(config) { + // removeCategoryNulls(config) { + // let cleanConfig = _.cloneDeep(config); + // let cleanSeverities = []; + // config.defaultSeverities.map(function(d) { + // if (d.severity) { + // cleanSeverities.push(d); + // } + // }); + // cleanConfig.defaultSeverities = cleanSeverities; + // return cleanConfig; + // } + cleanupConfig(config) { let cleanConfig = _.cloneDeep(config); let cleanSeverities = []; - config.defaultSeverities.map(function(d) { - if (d.severity) { - cleanSeverities.push(d); + cleanConfig.defaultSeverities && cleanConfig.defaultSeverities.map((defSev) => { + if (defSev.severity) { + cleanSeverities.push(defSev); } }); cleanConfig.defaultSeverities = cleanSeverities; + return cleanConfig; } - collectNulledCategories(oldCat, newCat) { - let nulledCategories = []; - let newSeverities = newCat.defaultSeverities; - let oldSeverities = oldCat.defaultSeverities; - newSeverities.map(function(c, i) { - if(!c.severity) { - if(oldSeverities[i].severity) { - //verify that categories are the same - if(oldSeverities[i].category == c.category) { - nulledCategories.push({category: c.category}) - } - } - } - }); - return nulledCategories; - } + // collectNulledCategories(oldCat, newCat) { + // let nulledCategories = []; + // let newSeverities = newCat.defaultSeverities; + // let oldSeverities = oldCat.defaultSeverities; + // newSeverities.map(function(c, i) { + // if(!c.severity) { + // if(oldSeverities[i].severity) { + // //verify that categories are the same + // if(oldSeverities[i].category == c.category) { + // nulledCategories.push({category: c.category}) + // } + // } + // } + // }); + // return nulledCategories; + // } validateData() { function isEventIdValid(eventID) { @@ -341,6 +356,25 @@ export default class LoggingGeneral extends React.Component { let syslogViewerURL = this.state.loggingConfig.syslogviewer; let defaultSeverities = this.state.loggingConfig.defaultSeverities; + // NOTE: There are modifications to original code here + // for RIFT-14856 so that default severities map to syslog sink + + // Find first syslog sink with (WTF - no type on sinks!) name syslog. + let syslogSink = this.state.loggingConfig.sinks && _.find(this.state.loggingConfig.sinks, { + name: 'syslog' + }); + let defaultSyslogSeverities = []; + + this.state.loggingConfig && this.state.loggingConfig.defaultSeverities && this.state.loggingConfig.defaultSeverities.map((defaultSeverity) => { + // Mapping between default categories and names inside a sink + let syslogFilterCategory = (syslogSink.filter && syslogSink.filter.category && _.find(syslogSink.filter.category, { + name: defaultSeverity.category + })) || { + name: defaultSeverity.category, + severity: null + }; + defaultSyslogSeverities.push(syslogFilterCategory); + }); let severities = this.state.loggingConfig.severities; let allowDuplicateEvents = this.state.loggingConfig.allowDuplicateEvents; let denyEventIDs = this.state.loggingConfig.denyEventIDs; @@ -361,7 +395,10 @@ export default class LoggingGeneral extends React.Component { {errorMessage}
- */} + 0) { remove = $.ajax({ - url: apiUrl('api/config/default-severity'), + // url: apiUrl('api/config/default-severity'), + url: apiUrl('api/config/default-syslog-severity'), type: 'DELETE', beforeSend: Utils.addAuthorizationStub, - data: { - 'default-severity' : nulledCategories - }, + data: nulledCategories, success: function(data) { resolve(data); }, @@ -100,6 +101,7 @@ export default { }); promises.push(remove); } + */ Promise.all(promises).then(function(data){ diff --git a/skyquake/plugins/logging/src/loggingStore.js b/skyquake/plugins/logging/src/loggingStore.js index 860ff9fc9..d8f0d70a6 100644 --- a/skyquake/plugins/logging/src/loggingStore.js +++ b/skyquake/plugins/logging/src/loggingStore.js @@ -26,10 +26,12 @@ class LoggingStore { this.loggingConfig = {}; // initialLoggingConfig is the saved state this.initialLoggingConfig = {}; + this.nulledCategories = []; this.bindActions(LoggingActions); this.registerAsync(LoggingSource); this.exportPublicMethods({ updateCategoryDefaultSeverity: this.updateCategoryDefaultSeverity, + updateCategoryDefaultSyslogSeverity: this.updateCategoryDefaultSyslogSeverity, updateAllowDuplicateEvents: this.updateAllowDuplicateEvents, addDenyEvent: this.addDenyEvent, updateDenyEvent: this.updateDenyEvent, @@ -97,6 +99,60 @@ class LoggingStore { } } + updateCategoryDefaultSyslogSeverity = (catsev) => { + console.log("LoggingStore.updateCategoryDefaultSyslogSeverity:", catsev); + // find the category (name) in the syslog sink + + let self = this; + let loggingConfig = _.cloneDeep(this.loggingConfig); + let syslogSinkIndex = -1; + let nulledCategories = this.nulledCategories; + + loggingConfig.sinks && loggingConfig.sinks.map((sink, sinkIndex) => { + if (sink.name == 'syslog') { + if (sink.filter) { + if (sink.filter.category) { + let catIndex = _.findIndex(sink.filter.category, { + name: catsev.name + }); + if (catIndex != -1) { + // found it + if (catsev.severity == "") { + // blank was selected + nulledCategories.push(catsev.name); + this.setState({ + nulledCategories: nulledCategories + }); + // TODO/NOTE: Can't delete from model as sending a top-level payload with + // missing elements is not allowed! + // When backend supports it, in loggingSource change the order of operations + // Delete first followed by save/put. + // _.remove(loggingConfig.sinks[sinkIndex].filter.category, { + // name: catsev.name + // }); + } else { + sink.filter.category[catIndex] = catsev; + } + } else { + sink.filter.category.push(catsev); + } + } else { + sink.filter.category = []; + sink.filter.category.push(catsev); + } + } else { + sink.filter = {}; + sink.filter.category = []; + sink.filter.category.push(catsev); + } + } + }); + + this.setState({ + loggingConfig: loggingConfig + }); + } + updateAllowDuplicateEvents = (allowFlag) => { console.log("LoggingStore.updateAllowDuplicateEvents called. allowFlag=", allowFlag); const loggingConfig = this.loggingConfig;