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 // This file contains the master Collector control loop, e.g. read input, parse it
 24 // and publish the data to Sentinel.
 25 /**
 26  * @fileoverview This file contains the actual control loop for the running Collector.
 27  */
 28 var instance = new Collector();
 29 var conn = new Connector();
 30 instance.scriptInit();
 31 
 32 if (!instance.initialize()) {
 33 	log("Collector failed to initialize; view recent error messages");
 34 	throw "Collector failed to initialize";
 35 }
 36 instance.customInit(); // Custom local initialization
 37 
 38 while (ScriptEngineUtil.keepRunning()) {
 39 	instance.reset(); // Reset variables to empty state
 40 	curEvt = new Event(instance.protoEvt); // clone a copy of the prototype event
 41 
 42 	// Get the next input record
 43 	conn.sendQuery();
 44 	rec = conn.read();
 45 
 46 	// Process the input (in case of any failures, just get the next record)
 47 	try {
 48 		if (!(rec.customPreparse(curEvt) && rec.preParse(curEvt))) { continue; }
 49 		if (!rec.parse(curEvt)) { continue;	}
 50 		if (!(rec.normalize(curEvt) && rec.customParse(curEvt) && rec.postParse(curEvt))) { continue; }
 51 		if (instance.SEND_EVENT) { curEvt.send(); } // Send the event
 52 	} catch (err) {
 53 		log("Parsing failed: " + err + "; input: " + rec.s_RXBufferString, 4, instance.LOG | instance.EVENT);
 54 	}
 55 
 56 	if (rec.CONNECTION_METHOD != "DATABASE" && rec.connectorData != null && rec.connectorData.offset != null) {
 57 		instance.CONFIG.scriptContext.setOffset(rec.s_RV24,	rec.connectorData.offset);
 58 	}
 59 
 60 	// Send replies to the Connector if necessary
 61 	rec.reply(curEvt);
 62 }
 63 
 64 conn.cleanup();
 65 instance.cleanup();
 66