/**
 * 
 */
package com.boundary.sdk.event.snmp;

import java.io.File;
import java.util.Date;
import java.util.Vector;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.component.snmp.SnmpMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.snmp4j.PDU;
import org.snmp4j.smi.Variable;
import org.snmp4j.smi.VariableBinding;

import com.boundary.sdk.event.RawEvent;
import com.boundary.sdk.event.Severity;
import com.boundary.sdk.event.Status;


/**
 * @author davidg
 * 
 */
public class SNMPToEventProcessor implements Processor {
	
    private static final Logger LOG = LoggerFactory.getLogger(SNMPToEventProcessor.class);
    
    SmiSupport smi;
	
    /**
     * 
     * @param repositoryPath Path to compiled MIBs
     * @param license SNMP4J-SMI license from <a href="http://www.snmp4j.org">http://www.snmp4j.org</a>
     */
	public SNMPToEventProcessor(String repositoryPath,String license) {
		smi = new SmiSupport();
		
		smi.setLicense(license);
		File mibDirectory = new File(repositoryPath);
		smi.setRepository(mibDirectory.getAbsolutePath());
		smi.initialize();
		smi.loadModules();
	}

	/**
	 * Returns the current path to the MIB repository
	 * 
	 * @return {@link String}
	 */
	public String getMibRepository() {
		return smi.getRepository();
	}
	
	/*
	 * Returns the current SNMP4J-SMI license
	 */
	public String getLicense() {
		return smi.getLicense();
	}
	
	@Override
	public void process(Exchange exchange) throws Exception {
		
		Message message = exchange.getIn();
		SnmpMessage snmpMessage = message.getBody(SnmpMessage.class);
		PDU pdu = snmpMessage.getSnmpMessage();
		
		// Create our event so that we can populate with the Syslog data
		RawEvent event = new RawEvent();
		
		// Get the type of trap received either: TRAP (v2) or TRAPV1 (v1)
		String trapType = PDU.getTypeString(pdu.getType());
		
		// Get the variable bindings from the trap and create properties in the event
		Vector<? extends VariableBinding> varBinds = pdu.getVariableBindings();
		for (VariableBinding var : varBinds) {
			event.addProperty(var.getOid().toString(),var.toValueString());
			event.addFingerprintField(var.getOid().toString());
		}
		event.addProperty("error_status", pdu.getErrorStatusText());
		
		// Address is in the form of X.X.X.X/port if IPV4
		String hostname = snmpMessage.getHeader("peerAddress").toString();

		//TBD, Set title using the trap type and hostname
		event.setTitle(trapType + " from " + hostname);
		
		event.addProperty("type", trapType == "TRAP" ? "v2c" : "v1");
		
		//TBD, What should the message field be set to by default??
		event.setMessage(pdu.getErrorStatusText());
		
		//TBD, set the severity based on content of the trap
		event.setSeverity(Severity.WARN);
		
		//TBD Set status based on severity??
		event.setStatus(Status.OPEN);

		event.getSource().setRef(hostname);
		event.getSource().setType("host");
//		event.setMessage(message.getBody().toString());
//		event.putProperty("message",message.getBody().toString());
//		event.putFingerprintField("@title");
		
		// Assign the RawEvent to the body
		message.setBody(event, RawEvent.class);
	}
}

@@ -85,77 +85,16 @@
 til.
-Date;%0Aimport java.util.Vector;%0A%0Aimport org.apache.camel.CamelContext;
+Vector;%0A
 %0Aimp
@@ -328,40 +328,8 @@
 DU;%0A
-import org.snmp4j.smi.Variable;%0A
 impo
@@ -488,16 +488,136 @@
 ;%0A%0A%0A/**%0A
+ * Implements %7B@link Processor%7D interface and is responsible for converting%0A * a %7B@link PDU%7D to a %7B@link RawEvent%7D.%0A * %0A
  * @auth
@@ -1755,24 +1755,55 @@
 ssage();%0A%09%09%0A
+%09%09LOG.debug(%22PDU: %7B%7D%22,pdu);%0A%09%09%0A
 %09%09// Create 
@@ -3057,161 +3057,43 @@
 %22);%0A
-//%09%09event.setMessage(message.getBody().toString());%0A//%09%09event.putProperty(%22message%22,message.getBody().toString());%0A//%09%09event.putFingerprintField(%22@title%22
+%09%09%0A%09%09LOG.debug(%22RawEvent: %7B%7D%22,event
 );%0A%09

Remove commented out code. Add class javadoc. Remove unused imports