Name
global.ISCReportUtil
Description
This script include will be used to adjust report filtering for ISC export metrics.
Script
var ISCReportUtil = Class.create();
ISCReportUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
constants: new ISCConstants(),
/**
* This function will filter the export metrics by the date specified and classification
* @return {string} - comma separated sys_id values of records from isc_export_event
*/
getUserExportTrends: function() {
var userId = gs.getUserID();
// Fetch user export setting
var exportSetting = this._getUserExportSetting(userId);
// Build query
if (exportSetting) {
// Get date and classification settings
var date = exportSetting.date;
var classifications = exportSetting.classification_metric.toString().split(",");
// Build encoded query
var query = '';
// If there are no classifications selected, show all data without classifications
if (classifications != null && classifications[0] === '') {
query = 'classificationISEMPTY';
} else {
for (var i = 0; i < classifications.length; i++) {
classifications[i] = 'classificationLIKE' + classifications[i];
}
query = classifications.join('^OR');
}
// Add date
query += '^sys_created_on>=' + gs.daysAgoStart(date);
// Fetch all records under this date and classification setting to display on report
return this._getExportRecords(query);
} else {
return '';
}
},
/**
* This function will filter the export metrics for all exports by the date specified
* @return {string} - comma separated sys_id values of records from isc_export_event
*/
getAllExportTrends: function() {
var userId = gs.getUserID();
// Fetch user export setting
var exportSetting = this._getUserExportSetting(userId);
if (exportSetting) {
// Fetch user date setting
var date = exportSetting.date;
// Build encoded query
var query = 'sys_created_on>=' + gs.daysAgoStart(date);
// Fetch all records under this date setting to display on report
return this._getExportRecords(query);
} else {
return '';
}
},
/**
* This function will fetch the export setting record for the user
* @param {string} userId - sys_id of current user
* @return {GlideRecord} - the user export setting GlideRecord
*/
_getUserExportSetting: function(userId) {
var userExpSettingGr = new GlideRecord(this.constants.tables.ISC_EXP_SETTING);
userExpSettingGr.addQuery('user', userId);
userExpSettingGr.query();
return userExpSettingGr.next() && (gs.hasRole("admin") || gs.hasRole("security_dashboard_user")) ? userExpSettingGr : '';
},
/**
* This function will fetch the export records from the export events table
* @param {string} encodedQuery - encoded query for export table
*/
_getExportRecords: function(encodedQuery) {
var records = [];
var exportGr = new GlideRecord(this.constants.tables.ISC_EXPORT);
exportGr.addEncodedQuery(encodedQuery);
exportGr.query();
while (exportGr.next() && (gs.hasRole("admin") || gs.hasRole("security_dashboard_user"))) {
records.push(exportGr.sys_id.toString());
}
return records;
},
type: 'ISCReportUtil'
});
Sys ID
12bcd3e40f826010b25fea12ff767eb8