Search in sources :

Example 1 with ProcessingStatus

use of loghub.Tools.ProcessingStatus in project LogHub by fbacchella.

the class TestFileMap method testone.

@Test
public void testone() throws ProcessorException {
    URL ifpixurl = getClass().getResource("/ipfix-information-elements.csv");
    FileMap s = new FileMap();
    s.setMappingFile(ifpixurl.getFile());
    s.setCsvFormat("RFC4180");
    s.setKeyName("ElementID");
    s.setValueName("Name");
    s.configure(null);
    Mapper p = new Mapper();
    p.setField(new String[] { "type" });
    p.setLvalue(new String[] { "type" });
    p.setMap(s);
    Event e = Tools.getEvent();
    e.put("type", "1");
    ProcessingStatus ps = Tools.runProcessing(e, "main", Collections.singletonList(p));
    Event ep = ps.mainQueue.remove();
    Assert.assertEquals("octetDeltaCount", ep.get("type"));
}
Also used : Mapper(loghub.processors.Mapper) Event(loghub.Event) ProcessingStatus(loghub.Tools.ProcessingStatus) URL(java.net.URL) Test(org.junit.Test)

Example 2 with ProcessingStatus

use of loghub.Tools.ProcessingStatus in project LogHub by fbacchella.

the class ProcessorTest method test.

@Test
public void test() throws IOException, DecodeException, ProcessorException, InterruptedException {
    Processor p = new Processor();
    InputStream is = getClass().getResourceAsStream("/netflow/packets/ipfix.dat");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buffer = new byte[8 * 1024];
    for (int length; (length = is.read(buffer)) != -1; ) {
        out.write(buffer, 0, length);
    }
    ByteBuf bbuffer = Unpooled.wrappedBuffer(out.toByteArray());
    Decoder nfd = new NetflowDecoder();
    IpConnectionContext dummyctx = new IpConnectionContext(new InetSocketAddress(0), new InetSocketAddress(0), null);
    Map<String, Object> content = nfd.decode(dummyctx, bbuffer);
    Event e = Tools.getEvent();
    e.setTimestamp((Date) content.remove(Event.TIMESTAMPKEY));
    e.putAll(content);
    ProcessingStatus ps = Tools.runProcessing(e, "main", Collections.singletonList(p));
    logger.debug(ps.mainQueue.remove());
    logger.debug(ps.mainQueue.remove());
    logger.debug(ps.mainQueue.remove());
    logger.debug(ps.mainQueue.remove());
    logger.debug(ps.mainQueue.remove());
    logger.debug(ps.mainQueue.remove());
    logger.debug(ps.mainQueue.remove());
    logger.debug(ps.mainQueue.remove());
    Assert.assertTrue(ps.mainQueue.isEmpty());
}
Also used : InputStream(java.io.InputStream) InetSocketAddress(java.net.InetSocketAddress) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuf(io.netty.buffer.ByteBuf) Decoder(loghub.Decoder) IpConnectionContext(loghub.IpConnectionContext) Event(loghub.Event) ProcessingStatus(loghub.Tools.ProcessingStatus) Test(org.junit.Test)

Aggregations

Event (loghub.Event)2 ProcessingStatus (loghub.Tools.ProcessingStatus)2 Test (org.junit.Test)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 Decoder (loghub.Decoder)1 IpConnectionContext (loghub.IpConnectionContext)1 Mapper (loghub.processors.Mapper)1