1 /* 2 * Copyright © [2008-2009] Novell, Inc. All Rights Reserved. 3 * 4 * USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE DEVELOPER LICENSE AGREEMENT 5 * OR OTHER AGREEMENT THROUGH WHICH NOVELL, INC. MAKES THE WORK AVAILABLE. THIS WORK 6 * MAY NOT BE ADAPTED WITHOUT NOVELL'S PRIOR WRITTEN CONSENT. 7 * 8 * NOVELL PROVIDES THE WORK "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, 9 * INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR 10 * A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. NOVELL, THE AUTHORS OF THE WORK, AND THE 11 * OWNERS OF COPYRIGHT IN THE WORK ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER 12 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, 13 * OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE WORK. 14 */ 15 16 /** 17 * @fileoverview 18 * This file defines the Action class, which represents the Action execution environment. 19 * It also defines the support Input class, which represents the input from correlation, 20 * and the IntegratorInstance class, which represents the Integrator. 21 * @name Action Class 22 */ 23 24 /** 25 * Creates an instance of the Action class. 26 * @class 27 * The Action class represents the Action runtime environment. 28 */ 29 function Action() { 30 31 /** 32 * Stores various runtime configuration options for the Action. 33 * <dl> 34 * <dt>instance.CONFIG.params</dt><dd>Parameters configured via the Sentinel UI</dd> 35 * </dl> 36 */ 37 this.CONFIG = {}; 38 this.CONFIG.params = {}; 39 40 // importPackage( java.util.logging ); 41 importClass( java.util.logging.Level ); 42 importClass( java.io.BufferedWriter ); 43 importClass( java.io.BufferedReader ); 44 importClass( java.io.FileWriter ); 45 importClass( java.io.FileReader ); 46 importClass( java.lang.System ); 47 importPackage( Packages.esecurity.db.object ); 48 49 // Create prototype input object - changes made to this object will be static 50 // and will be copied into the "current" object on each loop iteration 51 input = new Input(); 52 53 /** 54 * Flag which indicates that the Action should be executed after initial setup. 55 * You must set this once you've performed whatever initialization and setup 56 * necessary and are sure that you have the correct data to trigger the action. 57 */ 58 this.DO_ACTION=false; 59 } 60 61 /** 62 * Pauses the Action's execution for some number of seconds. 63 * @param {Number} sec Number of seconds to pause 64 * @return {void} 65 */ 66 Action.prototype.sleep = function(sec) { 67 var msec = sec * 1000; 68 try { 69 java.lang.Thread.sleep(msec); 70 } catch (e) { 71 log(e); 72 } 73 } 74 75 /** 76 * Creates an instance of the Integrator class and loads the Integrator API. 77 * @class 78 * The Integrator object represents a running instance of an Integrator in Sentinel. 79 * The Integrator provides a set of methods (loaded as an API on the Integrator class) 80 * that can be used to perform integration functions. 81 * <p>Key properties include: 82 * <dl> 83 * <dt>this.ID</dt> <dd>The name of the integrator as defined by Action parameters</dd> 84 * <dt> this.handle</dt> <dd>A handle to the Integrator instance so it can be controlled</dd> 85 * <dt>this.api</dt> <dd>A set of methods that can be called on the Integrator</dd> 86 * </dl> 87 * @constructor 88 * @see Action 89 */ 90 function IntegratorInstance() { 91 // First, fetch the Integrator ID from the Action parameter set. 92 this.ID = scriptEnv.getParameter("IntegratorId"); 93 94 // Fetch the running instance of the Integrator based on this ID 95 this.handle = Integrator.forId(this.ID); 96 97 // Now load the API for this Integrator 98 if (this.handle != null) { 99 this.api = this.handle.getAPI(); 100 if( this.api == null ) { 101 scriptEnv.log(Level.SEVERE,"Unable to find integrator API:{0}", [this.ID].toJava(java.lang.String)); 102 } 103 } else { 104 scriptEnv.log(Level.SEVERE,"Unable to find integrator descriptor:{0}" ,[this.ID].toJava(java.lang.String)); 105 } 106 } 107 108 109 /** 110 * The Input object represents the source events that caused the Action to be executed. 111 * @constructor 112 * @see Action 113 */ 114 function Input() { 115 return true; 116 } 117 118 /** 119 * The getEvents() method fetches the set of events associated with this action?? 120 */ 121 Input.prototype.getEvents = function(){ 122 123 function fromJavaMap(javaMap) 124 { 125 var ret = {}; 126 if (javaMap != null) 127 { 128 var entries = javaMap.entrySet().iterator(); 129 while (entries.hasNext()) 130 { 131 var entry = entries.next(); 132 ret[String(entry.key)] = String(entry.value); 133 } 134 } 135 136 return ret; 137 138 }; 139 140 var retArr = []; 141 142 // The getEventCollection() method retrieves events, correlated events, or 143 // incident events depending on where the action is executed. 144 var events = scriptEnv.getEventCollection(); 145 if ((events != null) && (events.size() > 0)) 146 { 147 var iter = events.iterator(); 148 while (iter.hasNext()) 149 { 150 var evt = iter.next(); 151 var jMap = evt.getAttributeMap(); 152 var jsMap = fromJavaMap(jMap); 153 retArr.push( jsMap); 154 } 155 } 156 157 return retArr; 158 159 } 160 161 /** 162 * The getIncident() method fetches the set of events associated with this action. 163 */ 164 Input.prototype.getIncident = function(){ 165 166 return scriptEnv.getIncident(); 167 168 } 169 170