Name
sn_itom_pde.GetCommandsFromPattern
Description
This script populates the list of commands from Allow-List to be executed when a certain pattern is given as input.
Script
var GetCommandsFromPattern = Class.create();
GetCommandsFromPattern.prototype = {
initialize: function() {
this.commandList = [];
this.id = '';
},
fetch: function(patternSysId){
this.id = patternSysId+'';
this.getCommandsFromSharedLibrariesInsidePattern(this.id);
this.getCommandsFromExtensions();
return this.commandList;
},
getCommandsFromPattern: function(patternId){
//commandList will be pushed with each entry cmd||||cmdType||||cmdSysid
var delimiter = '||||';
var gr = new GlideRecord('pd_command_list');
gr.addQuery('pattern',patternId);
gr.query();
while(gr.next()){
this.commandList.push([gr.command+ delimiter +gr.command_type+ delimiter +gr.sys_id]);
}
},
//retrieve commands from pattern and nested shared libraries inside the pattern using DFS kind of approach
getCommandsFromSharedLibrariesInsidePattern: function(id){
var ga = new GlideRecord('pd_pattern_to_shared_library_mapping');
var lib = [];
lib.push(id);
while(lib.length > 0){
var parentId = lib.pop();
this.getCommandsFromPattern(parentId);
ga.addQuery('parent',parentId);
ga.query();
while(ga.next()){
lib.push(ga.pattern+'');
}
}
},
//retrieve commands from extensions and nested shared libraries inside the extension using DFS kind of approach
getCommandsFromExtensions: function(){
var gy = new GlideRecord('sa_pattern_extension');
var ext = [];
gy.addQuery('pattern', this.id);
gy.query();
while(gy.next()){
this.getCommandsFromSharedLibrariesInsidePattern(gy.extension+'');
}
},
type: 'GetCommandsFromPattern'
};
Sys ID
2b0f77e147c659107cb2e977746d4392