hi here !
I am new to use logstash groking sepcially with xml. My task is parsing xml.I successfully wrote the GROK xml filter for a specific data XML format but then i came to know that data (XML) has different formats also.Like some sample data (XML) has new attributes which caused my parsing failure.I want to know two below thing.
1-First i want to know if i grok with match then my XML filter should run.
2-Is there a way in XML filter using xpath to check specific tag is exist or not.
My logstash conf file :
grok
{
match => ["message","%{LOGLEVEL:logtype}\s*%{TIMESTAMP_ISO8601:coffii_timestamp}\s*\[%{GREEDYDATA:task_descriptor}\]\s*\[%{WORD:service_name},%{NUMBER:invocation_id},%{GREEDYDATA:jms_message_id},%{GREEDYDATA:esb_conversation_id}\]\s*%{GREEDYDATA:coffii_message}"]
match => ["message","%{LOGLEVEL:logtype}\s*%{TIMESTAMP_ISO8601:coffii_timestamp}\s*\[%{GREEDYDATA:task_descriptor}\]\s*\[%{WORD:service_name}?,%{NUMBER:invocation_id}?,%{GREEDYDATA:jms_message_id}?,%{GREEDYDATA:esb_conversation_id}?\]\s*%{GREEDYDATA:coffii_message}\]"]
match => ["message","%{LOGLEVEL:logtype}\s*%{TIMESTAMP_ISO8601:coffii_timestamp}\s*\[%{GREEDYDATA:task_descriptor}\]\s*\[%{WORD:service_name}?,%{NUMBER:invocation_id}?,%{GREEDYDATA:jms_message_id}?,%{GREEDYDATA:esb_conversation_id}?\]\s*"]
}
grok
{
match => ["coffii_message", "(?<inxmldata><env:Envelope(.|\r|\n)*)"]
}
xml
{
source => ["inxmldata"]
target => "parsed_xml"
store_xml => true
remove_namespaces => "true"
xpath => ["/Envelope/Header/Body/ConfirmScheduleRequest/Location_ID/text()","location_id"]
force_array => false
}
mutate
{
add_field => {
Location_ID => "%{[parsed_xml][Body][ConfirmScheduleRequest][Location_ID]}"
Reservation_ID => "%{[parsed_xml][Body][ConfirmScheduleRequest][Reservation_ID]}"
}
remove_field => ["inxmldata","parsed_xml"]
}
If You see my configuration file , First i groked
match => ["coffii_message", "(?<env:Envelope(.|\r|\n)*)"]
then i want to run XML filter but right now XML filter is running for every format of data (whether xml exist or not).
Secondary I have two xpath tree structure in the XML tags to fetch "Location_ID".
/Envelope/Header/Body/ConfirmScheduleRequest/Location_ID/
/Envelope/Header/Body/QueryScheduleRequest/Location_ID/
I want to know the way in XML grok filter, xpath to check if any tag exist or not.
Thanking in advance,
Kamran