Name
sn_grc.IndicatorEngineBase
Description
Engine for the indicator
Script
var IndicatorEngineBase = Class.create();
IndicatorEngineBase.prototype = {
initialize: function() {},
runAllIndicators: function() {
this._runAllIndicators();
},
runIndicator: function(indicatorRecord) {
return this._runIndicator(indicatorRecord);
},
_runAllIndicators: function() {
var minBatchSize = parseInt(gs.getProperty('sn_grc.indicator_min_batch_size'));
var maxEvents = parseInt(gs.getProperty('sn_grc.indicator_max_events'));
var isDefault = minBatchSize > 1 && maxEvents > 1 ? false : true;
var today = new GlideDateTime(new GlideDateTime().getLocalDate());
var currDate = new GlideDate();
currDate.setValue(today);
var indicator = new GlideRecord('sn_grc_indicator');
indicator.addActiveQuery();
indicator.addQuery('type', '!=', 'config_test');
indicator.addQuery('next_run_time', '<=', currDate);
indicator.query();
var query = indicator.getEncodedQuery();
var totalIndicators = indicator.getRowCount();
if (isDefault) {
while (indicator.next()) {
this.runIndicator(indicator);
this.updateNextDateTime(indicator,currDate.getTZOffset());
}
if (this.notifyMaxNumIndicatorTasksExceeded) {
new ManualIndicatorStrategy().notifyMaxNumIndicatorTasksExceeded();
}
} else {
var batch = minBatchSize;
var totalEvents = totalIndicators / minBatchSize;
if (totalEvents > maxEvents)
batch = totalIndicators / maxEvents;
var gr = new GlideRecord('sn_grc_indicator_batch');
while (indicator.hasNext()) {
var count = 0;
var indicators = [];
while (count++ < batch && indicator.next()) {
indicators.push(indicator.getUniqueValue());
}
gr.setValue('indicators', indicators.join());
gr.insert();
gs.eventQueue('sn_grc.indicator_batch', gr, gr.getUniqueValue(), currDate.getTZOffset());
}
}
},
updateNextDateTime: function(indicator,milliSeconds) {
// Update the next run time of the indicator record
var localDate=new GlideDateTime();
localDate.add(parseInt(milliSeconds));
var today = new GlideDate();
today.setValue(localDate);
indicator.next_run_time = new sn_grc.FrequencyUtils().computeNextDateTime(today, indicator);
//update next scheduled date of the indicator template
var template = new GlideRecord('sn_grc_indicator_template');
if (template.get(indicator.template) && !indicator.override_template) {
template.next_run_time = indicator.next_run_time;
template.update();
}
indicator.update();
},
_runIndicator: function(indicatorRecord) {
// An exception while running an indicator should not stop other's from running
try{
var strategy = this._getStrategy(indicatorRecord);
var resultId = strategy.run();
} catch(ex){
gs.error("Error while running indicator with sys_id: {0}",indicatorRecord.getUniqueValue());
gs.error(ex);
}
//if indicator's first run date is not populated then populate it
if (!indicatorRecord.getValue('first_run_date')) {
var todayDate = new GlideDateTime().getLocalDate();
indicatorRecord.setValue('first_run_date', todayDate.getValue());
indicatorRecord.update();
var template = new GlideRecord('sn_grc_indicator_template');
//if the template's first run date is not populated then populate it
if (indicatorRecord.getValue('template') && template.get(indicatorRecord.getValue('template')) && !template.first_run_date) {
template.first_run_date = indicatorRecord.first_run_date;
template.update();
}
}
if (resultId == 'exceed' && strategy.type == 'ManualIndicatorStrategy')
this.notifyMaxNumIndicatorTasksExceeded = true;
return resultId;
},
_getStrategy: function(indicatorRecord) {
switch (indicatorRecord.getValue("type")) {
case 'basic':
return new sn_grc.BasicIndicatorStrategy(indicatorRecord);
case 'manual':
return new sn_grc.ManualIndicatorStrategy(indicatorRecord);
case 'script':
return new sn_grc.ScriptIndicatorStrategy(indicatorRecord);
case 'pa_indicator':
return new sn_grc.PAIndicatorStrategy(indicatorRecord);
case 'config_test':
return new sn_compliance.ConfigurationTestIndicatorStrategy(indicatorRecord);
}
},
type: 'IndicatorEngineBase'
};
Sys ID
a8d84682d7320200d77c83e80e61031b