I am trying to load xml through logstash. I have an unwnated tag which needs to be removed from xml while parsing. Used remove_tag but not able to remove the tag while indexing to Elasticsearch
xml File
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Report" time="212.715" tests="7" failures="1" errors="3">
<testsuite name="Report" tests="7" failures="1" errors="3" time="212.715" skipped="0" timestamp="2023-02-23 16:45:10" id="Test Suites/Report">
<testcase name="Test Cases/01" time="34.627" classname="Test Cases/01" status="FAILED">
<system-err><![CDATA[2023-02-23 16:45:10 - [TEST_SUITE][FAILED] - Report: Test Cases/TC01 FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to scroll to object 'Object Repository/ScrollToEle'
]]></system-err>
</testcase>
<testcase name="Test Cases/02" time="34.627" classname="Test Cases/02" status="PASSED">
</testcase>
<system-err><![CDATA[2023-02-23 16:45:10 - [TEST_SUITE][FAILED] - Report: Test Cases/TC01 FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to scroll to object 'Object Repository/ScrollToEle'
]]></system-err>
</testsuite>
</testsuites>
logstash Conf file
input {
file
{
path => "C/log-sample.xml"
start_position => "beginning"
codec => multiline
{
pattern => "<testsuites>"
negate => true
what => "previous"
max_lines => 50000
}
sincedb_path => "NULL"
}
}
filter {
xml {
source => "message"
target => "theXML"
force_array => false
remove_field => ["message"]
}
mutate {remove_tag => ["[testsuites][testsuite][testcase][system-err]"]}
ruby {
code => '
event.get("theXML").each { |k, v|
event.set(k,v)
}
event.remove("theXML")
'
}
}
output
{
elasticsearch {
hosts => "localhost:9200"
index => "xml_testing"
}
stdout
{
codec => rubydebug
}
}
output I got. I still see system-err tag
{
"took": 13,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "xml_testing",
"_type": "_doc",
"_id": "v7GTnYYBhrMoCAz3NLRv",
"_score": 1,
"_source": {
"tags": [
"multiline"
],
"name": "Report",
"time": "212.715",
"tests": "7",
"host": "hdc3-l-JNRPMW2",
"path": "C:/Users/navya.krishna.voggu/Downloads/sample/sample.xml",
"failures": "1",
"@timestamp": "2023-03-01T14:28:33.127Z",
"@version": "1",
"errors": "3",
"testsuite": {
"skipped": "0",
"failures": "1",
"timestamp": "2023-02-23 16:45:10",
"testcase": [
{
"time": "34.627",
"classname": "Test Cases/01",
"status": "FAILED",
"system-err": "2023-02-23 16:45:10 - [TEST_SUITE][FAILED] - Report: Test Cases/TC01 FAILED.\nReason:\ncom.kms.katalon.core.exception.StepFailedException: Unable to scroll to object 'Object Repository/ScrollToEle'\n",
"name": "Test Cases/01"
},
{
"name": "Test Cases/02",
"time": "34.627",
"classname": "Test Cases/02",
"status": "PASSED",
"content": "\n \n "
}
],
"name": "Report",
"id": "Test Suites/Report",
"system-err": "2023-02-23 16:45:10 - [TEST_SUITE][FAILED] - Report: Test Cases/TC01 FAILED.\nReason:\ncom.kms.katalon.core.exception.StepFailedException: Unable to scroll to object 'Object Repository/ScrollToEle'\n",
"tests": "7",
"time": "212.715",
"errors": "3"
}
}
}
]
}
}