org.apache.flume.interceptor
Class RegexExtractorInterceptor

java.lang.Object
  extended by org.apache.flume.interceptor.RegexExtractorInterceptor
All Implemented Interfaces:
Interceptor

public class RegexExtractorInterceptor
extends Object
implements Interceptor

Interceptor that extracts matches using a specified regular expression and appends the matches to the event headers using the specified serializers

Note that all regular expression matching occurs through Java's built in java.util.regex package

. Properties:

regex: The regex to use

serializers: Specifies the group the serializer will be applied to, and the name of the header that will be added. If no serializer is specified for a group the default RegexExtractorInterceptorPassThroughSerializer will be used

Sample config:

agent.sources.r1.channels = c1

agent.sources.r1.type = SEQ

agent.sources.r1.interceptors = i1

agent.sources.r1.interceptors.i1.type = REGEX_EXTRACTOR

agent.sources.r1.interceptors.i1.regex = (WARNING)|(ERROR)|(FATAL)

agent.sources.r1.interceptors.i1.serializers = s1 s2 agent.sources.r1.interceptors.i1.serializers.s1.type = com.blah.SomeSerializer agent.sources.r1.interceptors.i1.serializers.s1.name = warning agent.sources.r1.interceptors.i1.serializers.s2.type = org.apache.flume.interceptor.RegexExtractorInterceptorTimestampSerializer agent.sources.r1.interceptors.i1.serializers.s2.name = error agent.sources.r1.interceptors.i1.serializers.s2.dateFormat = yyyy-MM-dd

 Example 1:
 

EventBody: 1:2:3.4foobar5

Configuration: agent.sources.r1.interceptors.i1.regex = (\\d):(\\d):(\\d)

agent.sources.r1.interceptors.i1.serializers = s1 s2 s3 agent.sources.r1.interceptors.i1.serializers.s1.name = one agent.sources.r1.interceptors.i1.serializers.s2.name = two agent.sources.r1.interceptors.i1.serializers.s3.name = three

results in an event with the the following body: 1:2:3.4foobar5 headers: one=>1, two=>2, three=3 Example 2: EventBody: 1:2:3.4foobar5 Configuration: agent.sources.r1.interceptors.i1.regex = (\\d):(\\d):(\\d)

agent.sources.r1.interceptors.i1.serializers = s1 s2 agent.sources.r1.interceptors.i1.serializers.s1.name = one agent.sources.r1.interceptors.i1.serializers.s2.name = two

results in an event with the the following body: 1:2:3.4foobar5 headers: one=>1, two=>2


Nested Class Summary
static class RegexExtractorInterceptor.Builder
           
 
Method Summary
 void close()
          Perform any closing / shutdown needed by the Interceptor.
 void initialize()
          Any initialization / startup needed by the Interceptor.
 Event intercept(Event event)
          Interception of a single Event.
 List<Event> intercept(List<Event> events)
          Interception of a batch of events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initialize

public void initialize()
Description copied from interface: Interceptor
Any initialization / startup needed by the Interceptor.

Specified by:
initialize in interface Interceptor

close

public void close()
Description copied from interface: Interceptor
Perform any closing / shutdown needed by the Interceptor.

Specified by:
close in interface Interceptor

intercept

public Event intercept(Event event)
Description copied from interface: Interceptor
Interception of a single Event.

Specified by:
intercept in interface Interceptor
Parameters:
event - Event to be intercepted
Returns:
Original or modified event, or null if the Event is to be dropped (i.e. filtered out).

intercept

public List<Event> intercept(List<Event> events)
Description copied from interface: Interceptor
Interception of a batch of events.

Specified by:
intercept in interface Interceptor
Parameters:
events - Input list of events
Returns:
Output list of events. The size of output list MUST NOT BE GREATER than the size of the input list (i.e. transformation and removal ONLY). Also, this method MUST NOT return null. If all events are dropped, then an empty List is returned.


Copyright © 2009-2015 Apache Software Foundation. All Rights Reserved.