We have written a logstash script to process an XMLfile and export contents to stdout{}. We have verified the script works when the input is specified as stdin{}
However, when we specify a file as the input, the XML does not process as expected and we get errors like: Error parsing xml with XmlSimple
Config file contents are:
input {
file {
path => "D:/logstash-7.4.1/conf/geoserver_audit_20191030_2.log"
sincedb_path => "nul"
start_position => "beginning"
type => "xml"
codec => multiline {
pattern => "Request>"
negate => true
what => "previous"
}
}
}
filter {
xml
{
source => "message"
xpath => [
"/Requests/Request/Service/text()", "service",
"/Requests/Request/Version/text()", "version",
"/Requests/Request/Operation/text()", "operation",
"/Requests/Request/SubOperation/text()", "sub_operation",
"/Requests/Request/Resources/text()", "resources",
"/Requests/Request/Path/text()", "path",
"/Requests/Request/QueryString/text()", "query_string",
"/Requests/Request/Body/text()", "body",
"/Requests/Request/HttpMethod/text()", "http_method",
"/Requests/Request/StartTime/text()", "start_time",
"/Requests/Request/EndTime/text()", "end_time",
"/Requests/Request/TotalTime/text()", "total_time",
"/Requests/Request/RemoteAddr/text()", "remote_addr",
"/Requests/Request/RemoteHost/text()", "remote_host",
"/Requests/Request/Host/text()", "host",
"/Requests/Request/RemoteUser/text()", "remote_host",
"/Requests/Request/ResponseStatus/text()", "response_status",
"/Requests/Request/ResponseLength/text()", "response_length",
"/Requests/Request/ResponseContentType/text()", "response_content_type",
"/Requests/Request/CacheResult/text()", "cache_result",
"/Requests/Request/MissReason/text()", "miss_reason",
"/Requests/Request/Failed/text()", "failed"
]
target => "xml_value"
}
#mutate {
#remove_field => [tags, host, message, xml_value]
#}
}
output {
stdout {}
}
XML contents are:
>?xml version="1.0" encoding="UTF-8" ?>
>Requests>>Request id="34">
>Service>>/Service>
>Version>>/Version>
>Operation>>/Operation>
>SubOperation>>/SubOperation>
>Resources>>/Resources>
>Path>null>/Path>
>QueryString>>/QueryString>
>Body>
>/Body>
>HttpMethod>GET>/HttpMethod>
>StartTime>2019-10-30T22:50:39.107Z>/StartTime>
>EndTime>2019-10-30T22:50:43.55Z>/EndTime>
>TotalTime>4,443>/TotalTime>
>RemoteAddr>10.2.142.1>/RemoteAddr>
>RemoteHost>10.2.142.1>/RemoteHost>
>Host>dev-alta-geo04.altalisdev.com>/Host>
>RemoteUser>anonymous>/RemoteUser>
>ResponseStatus>200>/ResponseStatus>
>ResponseLength>0>/ResponseLength>
>ResponseContentType>>/ResponseContentType>
>CacheResult>>/CacheResult>
>MissReason>>/MissReason>
>Failed>false>/Failed>
>/Request>
>Request id="35">
>Service>>/Service>
>Version>>/Version>
>Operation>>/Operation>
>SubOperation>>/SubOperation>
>Resources>>/Resources>
>Path>/index.html>/Path>
>QueryString>>/QueryString>
>Body>
>/Body>
>HttpMethod>GET>/HttpMethod>
>StartTime>2019-10-30T22:50:43.581Z>/StartTime>
>EndTime>2019-10-30T22:50:43.612Z>/EndTime>
>TotalTime>31>/TotalTime>
>RemoteAddr>10.2.142.1>/RemoteAddr>
>RemoteHost>10.2.142.1>/RemoteHost>
>Host>dev-alta-geo04.altalisdev.com>/Host>
>RemoteUser>anonymous>/RemoteUser>
>ResponseStatus>200>/ResponseStatus>
>ResponseLength>697>/ResponseLength>
>ResponseContentType>text/html;charset=UTF-8>/ResponseContentType>
>CacheResult>>/CacheResult>
>MissReason>>/MissReason>
>Failed>false>/Failed>
>/Request>
>/Requests>