1 // Javascript Collector Template 6.1 2 /* 3 * Copyright © [2008-2009] Novell, Inc. All Rights Reserved. 4 * 5 * USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE DEVELOPER LICENSE AGREEMENT 6 * OR OTHER AGREEMENT THROUGH WHICH NOVELL, INC. MAKES THE WORK AVAILABLE. THIS WORK 7 * MAY NOT BE ADAPTED WITHOUT NOVELL'S PRIOR WRITTEN CONSENT. 8 * 9 * NOVELL PROVIDES THE WORK "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, 10 * INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR 11 * A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. NOVELL, THE AUTHORS OF THE WORK, AND THE 12 * OWNERS OF COPYRIGHT IN THE WORK ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER 13 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, 14 * OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE WORK. 15 */ 16 17 // This Collector template guides the creation of Collectors to capture 18 // event data from a wide variety of sources and transform it into the 19 // normalized Sentinel schema. 20 // Refer to the Sentinel Collector SDK documentation at 21 // http://developer.novell.com/wiki/index.php/Developer_Home 22 // for complete information about this template, the API, and Sentinel in general. 23 24 // This file contains the master Collector control loop, e.g. read input, parse it 25 // and publish the data to Sentinel. 26 27 /** 28 * @fileoverview 29 * This file contains the actual control loop for the running Collector. 30 */ 31 var instance = new Collector(); 32 var conn = new Connector(); 33 instance.scriptInit(); 34 35 if (instance.CONFIG.params.ExecutionMode == "debug") { 36 // importClass( org.mozilla.javascript.debug.Debugger ); 37 38 // mydebug = new org.mozilla.javascript.debug.Debugger(); 39 // Context.setDebugger(mydebug); 40 } 41 42 if (!instance.initialize()) { 43 log("Collector failed to initialize; view recent error messages"); 44 throw "Collector failed to initialize"; 45 } 46 47 48 while (ScriptEngineUtil.keepRunning()) { 49 // Reset variables to empty state 50 instance.reset(); 51 52 // clone a copy of the prototype event 53 curEvt = new Event(instance.protoEvt); 54 55 // Get the next input record 56 conn.sendQuery(); 57 rec = conn.read(); 58 59 // Process the input (in case of any failures, just get the next record) 60 try { 61 if (!(rec.customPreparse(curEvt) && rec.preParse(curEvt))) { 62 continue; 63 } 64 if (!rec.parse(curEvt)) { 65 continue; 66 } 67 if (!(rec.normalize(curEvt) && rec.customParse(curEvt) && rec.postParse(curEvt))) { 68 continue; 69 } 70 if (instance.SEND_EVENT) { 71 // Send the event 72 curEvt.send(); 73 } 74 } catch(err) { 75 log("Parsing failed: " + err + "; input: " + rec.s_RXBufferString, 4, instance.LOG|instance.EVENT); 76 } 77 78 79 if (rec.CONNECTION_METHOD != "DATABASE" && rec.connectorData != null && rec.connectorData.offset != null) { 80 instance.CONFIG.scriptContext.setOffset(rec.s_RV24, rec.connectorData.offset); 81 } 82 83 // Send replies to the Connector if necessary 84 rec.reply(curEvt); 85 } 86 87 conn.cleanup(); 88 instance.cleanup(); 89