use of loghub.Event in project LogHub by fbacchella.
the class SnmpTrap method processPdu.
@Override
public void processPdu(CommandResponderEvent trap) {
try {
PDU pdu = trap.getPDU();
Address localaddr = trap.getTransportMapping().getListenAddress();
Address remoteaddr = trap.getPeerAddress();
ConnectionContext ctx = ConnectionContext.EMPTY;
if (localaddr instanceof TransportIpAddress && remoteaddr instanceof TransportIpAddress) {
InetSocketAddress localinetaddr = getSA((TransportIpAddress) localaddr);
InetSocketAddress remoteinetaddr = getSA((TransportIpAddress) remoteaddr);
ctx = new IpConnectionContext(localinetaddr, remoteinetaddr, null);
}
Event event = emptyEvent(ctx);
if (pdu instanceof PDUv1) {
PDUv1 pduv1 = (PDUv1) pdu;
String enterprise = (String) convertVar(pduv1.getEnterprise());
event.put("enterprise", enterprise);
event.put("agent_addr", pduv1.getAgentAddress().getInetAddress());
if (pduv1.getGenericTrap() != PDUv1.ENTERPRISE_SPECIFIC) {
event.put("generic_trap", GENERICTRAP.values()[pduv1.getGenericTrap()].toString());
} else {
String resolved = formatter.format(pduv1.getEnterprise(), new Integer32(pduv1.getSpecificTrap()), true);
event.put("specific_trap", resolved);
}
event.put("time_stamp", 1.0 * pduv1.getTimestamp() / 100.0);
}
@SuppressWarnings("unchecked") Enumeration<VariableBinding> vbenum = (Enumeration<VariableBinding>) pdu.getVariableBindings().elements();
for (VariableBinding i : Collections.list(vbenum)) {
OID vbOID = i.getOid();
Object value = convertVar(i.getVariable());
smartPut(event, vbOID, value);
}
send(event);
} catch (Exception e) {
logger.error(e.getMessage());
logger.catching(e);
} finally {
trap.setProcessed(true);
}
}
use of loghub.Event in project LogHub by fbacchella.
the class FireEvent method process.
@Override
public boolean process(Event event) throws ProcessorException {
Event newEvent = Event.emptyEvent(ConnectionContext.EMPTY);
for (Map.Entry<String[], Expression> e : expressions.entrySet()) {
Object value = e.getValue().eval(event, Collections.emptyMap());
newEvent.applyAtPath((i, j, k) -> i.put(j, k), e.getKey(), value);
}
return newEvent.inject(pipeDestination, mainQueue);
}
use of loghub.Event in project LogHub by fbacchella.
the class Forker method fork.
public void fork(Event event) {
Event newEvent = event.duplicate();
if (newEvent == null) {
return;
}
newEvent.inject(pipeDestination, mainQueue);
}
use of loghub.Event in project LogHub by fbacchella.
the class TestFire method test.
@Test
public void test() throws ProcessorException, InterruptedException, ConfigException, IOException {
Properties conf = Tools.loadConf("fire.conf");
for (Pipeline pipe : conf.pipelines) {
Assert.assertTrue("configuration failed", pipe.configure(conf));
}
Event sent = Tools.getEvent();
sent.put("count", 2);
Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
Event old = conf.mainQueue.remove();
Event newevent = conf.mainQueue.remove();
Assert.assertEquals("Not matching old event", old.get("count"), 2);
Assert.assertEquals("Event not fired", 6, newevent.get("c"));
}
use of loghub.Event in project LogHub by fbacchella.
the class TestGeoip2 method testProcess.
@Test
public void testProcess() throws ProcessorException {
Properties props = new Properties(Collections.emptyMap());
Geoip2 geoip = new Geoip2();
geoip.setField("ip");
geoip.setDestination("geoip");
Geoip2.LocationType[] types = Geoip2.LocationType.values();
String[] typesNames = new String[types.length];
for (int i = 0; i < types.length; i++) {
typesNames[i] = types[i].name().toLowerCase();
}
geoip.setTypes(typesNames);
geoip.setLocale("en");
geoip.configure(props);
Event e = Tools.getEvent();
e.put("ip", "8.8.8.8");
geoip.process(e);
@SuppressWarnings("unchecked") Map<Object, Object> geoinfos = (Map<Object, Object>) e.get("geoip");
assertEquals("not enough elements", 7, geoinfos.size());
}
Aggregations