public class Parser extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Parser.EventTooOldException
Indicates the extracted event timestamp was too old
|
Modifier and Type | Field and Description |
---|---|
static String[] |
onlyStackdriverTypes
If a Stackdriver log message contains any strings present in this array in the @type field, we
assume no other encapsulation is present in the parser
|
static String |
SYSLOG_TS_RE |
Constructor and Description |
---|
Parser()
Create new parser instance with default configuration
|
Parser(ParserCfg cfg)
Create new parser instance with specified configuration
|
Modifier and Type | Method and Description |
---|---|
String |
applyProxyXFFAddressSelector(String input,
Boolean proxyPipeline)
Applies proxy xff selector
|
String |
applyXffAddressSelector(String input)
Apply any configured XFF address selector to the specified input string
|
static <T,U> HashMap<T,U> |
convertJsonToMap(String input)
Utility function to convert a JSON string into the desired map type
|
static <T,U> HashMap<T,U> |
convertJsonToMap(String input,
com.fasterxml.jackson.databind.ObjectMapper mapper)
Utility function to convert a JSON string into the desired map type
|
com.maxmind.geoip2.model.CityResponse |
geoIp(String ip)
Resolve GeoIP information from IP address string
|
com.maxmind.geoip2.model.IspResponse |
geoIpIsp(String ip)
Resolve GeoIP ISP information from IP address string
|
IdentityManager |
getIdentityManager()
Get any configured identity manager from the parser
|
static org.joda.time.DateTime |
getLatestTimestamp(Iterable<Event> events)
Given an interable of events, return the latest timestamp
|
Event |
parse(String input)
Parse an event
|
static org.joda.time.DateTime |
parseAndCorrectSyslogTs(String in,
Event e)
Parse syslog timestamp date time string and return a
DateTime object using parseSyslogTs(String) , and then correct the year if the parsed timestamp is further than
three days from the event timestamp. |
static org.joda.time.DateTime |
parseISO8601(String in)
Parse an ISO8601 date string and return a
DateTime object. |
static org.joda.time.DateTime |
parseSyslogTs(String in)
Parse syslog timestamp date time string and return a
DateTime object. |
static String[] |
parseXForwardedFor(String in)
Process the value of an X-Forwarded-For header, returning an array of each address in the
header or null if invalid
|
void |
setIdentityManager(IdentityManager idmanager)
Set an identity manager in the parser that can be used for lookups
|
Boolean |
shouldUseXff()
Returns true if using an XFF header is enabled in the parser
|
public static final String SYSLOG_TS_RE
public static final String[] onlyStackdriverTypes
public Parser(ParserCfg cfg)
cfg
- ParserCfg
public Parser()
public static org.joda.time.DateTime getLatestTimestamp(Iterable<Event> events)
events
- Event listpublic static org.joda.time.DateTime parseSyslogTs(String in)
DateTime
object.in
- Input stringDateTime
, null if string could not be parsedpublic static org.joda.time.DateTime parseAndCorrectSyslogTs(String in, Event e)
DateTime
object using parseSyslogTs(String)
, and then correct the year if the parsed timestamp is further than
three days from the event timestamp.in
- Input stringe
- Event
DateTime
, null if string could not be parsedpublic static org.joda.time.DateTime parseISO8601(String in)
DateTime
object.in
- Input stringDateTime
, null if string could not be parsedpublic String applyXffAddressSelector(String input) throws IllegalArgumentException
If no XFF address selector has been configured in the parser configuration, and the input contains multiple XFF style addresses, the last address is returned.
input
- Input stringIllegalArgumentException
public Boolean shouldUseXff()
public String applyProxyXFFAddressSelector(String input, Boolean proxyPipeline)
input
- input to apply selector toproxyPipeline
- whether this is marked as through the proxypublic static <T,U> HashMap<T,U> convertJsonToMap(String input)
T
- TU
- Uinput
- Input JSONpublic static <T,U> HashMap<T,U> convertJsonToMap(String input, com.fasterxml.jackson.databind.ObjectMapper mapper)
T
- TU
- Uinput
- Input JSONmapper
- ObjectMapperpublic static String[] parseXForwardedFor(String in)
in
- Input stringpublic com.maxmind.geoip2.model.CityResponse geoIp(String ip)
GeoIP resolution must be enabled in the parser, or this function will always return null.
ip
- IP address stringCityResponse
, or null if lookup failspublic com.maxmind.geoip2.model.IspResponse geoIpIsp(String ip)
GeoIP resolution must be enabled in the parser with the ISP database, or this function will always return null.
ip
- IP address stringIspResponse
, or null if lookup failspublic void setIdentityManager(IdentityManager idmanager)
idmanager
- Initialized IdentityManager
public IdentityManager getIdentityManager()
IdentityManager
or null if no manager has been set in the parserpublic Event parse(String input) throws Parser.EventTooOldException
input
- Input stringEvent
or null if the event should be ignoredParser.EventTooOldException
- EventTooOldExceptionCopyright © 2022. All rights reserved.