# XML Filter Share value between events

**URL:** <https://discuss.elastic.co/t/xml-filter-share-value-between-events/163360>\
**Category:** Logstash\
**Created:** [January 8, 2019, 12:04pm UTC](https://discuss.elastic.co/t/xml-filter-share-value-between-events/163360 "2019-01-08T12:04:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anabella\_Cristaldi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anabella_cristaldi/32/23612_2.png) [@Anabella\_Cristaldi](https://discuss.elastic.co/u/Anabella_Cristaldi)\
**Post date:** [January 8, 2019, 12:04pm UTC](https://discuss.elastic.co/t/xml-filter-share-value-between-events/163360/1 "2019-01-08T12:04:45Z")

</div>

Hi all,  
I need to ingest XML files which are the output of a Nessus scanner.  
The XML has this structure

```
?xml version="1.0" ?>
<NessusClientData_v2>
<Report name="host1" xmlns:cm="http://www.nessus.org/cm">
<ReportHost name="Host1">
<HostProperties>
....
</HostProperties>
<ReportItem port="80" svc_name="www" protocol="tcp" severity="2" pluginID="45411" pluginName="SSL" pluginFamily="General">
	<tag1>value1</tag1>
	<tag2>value2</tag2>
	<tag3>value3</tag3>
</ReportItem>

<ReportItem port="8081" svc_name="www" protocol="tcp" severity="2" pluginID="45411" pluginName="SSL" pluginFamily="General">
	<tag1>value1</tag1>
	<tag2>value2</tag2>
	<tag3>value3</tag3>
</ReportItem>

<ReportItem port="8083" svc_name="www" protocol="tcp" severity="2" pluginID="45411" pluginName="SSL" pluginFamily="General">
	<tag1>value1</tag1>
	<tag2>value2</tag2>
	<tag3>value3</tag3>
</ReportItem>
<ReportHost name="Host2">
<HostProperties>
....
</HostProperties>
<ReportItem port="80" svc_name="www" protocol="tcp" severity="2" pluginID="45411" pluginName="SSL" pluginFamily="General">
	<tag1>value1</tag1>
	<tag2>value2</tag2>
	<tag3>value3</tag3>
</ReportItem>

<ReportItem port="8081" svc_name="www" protocol="tcp" severity="2" pluginID="45411" pluginName="SSL" pluginFamily="General">
	<tag1>value1</tag1>
	<tag2>value2</tag2>
	<tag3>value3</tag3>
</ReportItem>

<ReportItem port="8083" svc_name="www" protocol="tcp" severity="2" pluginID="45411" pluginName="SSL" pluginFamily="General">
	<tag1>value1</tag1>
	<tag2>value2</tag2>
	<tag3>value3</tag3>
</ReportItem>
</Report name>
</NessusClientData_v2>

```

I need to have one document per ReportItem but I want to add each document a new field containing the host information.  
Is it possible to share the name of the tah ReportHost in the preceding ReportItems events?  
I have tried something like the configuration below, with no luck  
How can I carry the hostname between events until a new ReportHost appears?  
Thank you!  
Regards  
Ana

```
input {
  file {
    path => "/data/nessus/nessus.xml"
    sincedb_path => "/dev/null"
    start_position => "beginning"
    codec => multiline {
      pattern => "^<ReportItem |^<ReportHost"
      auto_flush_interval => 1
      negate => "true"
      what => "previous"
      max_lines => 1000000000
     max_bytes => "50 MiB"

    }
      tags => "xml_test"
      type => "xml_test"
  }
}

filter {
  ##interpret the message as XML
        if [message] =~ "^<ReportHost*" {
                xml{
                        source => "message"
                        store_xml => "false"
                        force_array => "false"
                        xpath => ["ReportHost/@name", name]
                }
                ruby {
                        init => "@asset = event.get('name')"
                }
        }

        if [message] =~ "^<ReportItem*" {
                xml{
                        source => "message"
                        store_xml => "false"
                        force_array => "false"
                        xpath => ["ReportItem/@tag1", plugin_name]
                        xpath => ["ReportItem/@tag2", plugin_id]
                        xpath => ["ReportItem/@tag3", risk_score]
                }

                ruby {
                code => "
                          event.set('asset', @asset')
                "
                }
        }
}
```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 8, 2019, 3:01pm UTC](https://discuss.elastic.co/t/xml-filter-share-value-between-events/163360/2 "2019-01-08T15:01:04Z")

</div>

If your XML is actually valid (e.g. it does not contain constructs such as " \</Report name\>") then if you ingest the entire file as a single event you can use something like

```
    xml { source => "message" target => theXML }
    split { field => "[theXML][Report][0][ReportHost]" }
    split { field => "[theXML][Report][0][ReportHost][ReportItem]" }

```

then you can mutate+rename to give the fields more useable names.

---

<div class="post-metadata">

**Author:** ![Anabella\_Cristaldi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anabella_cristaldi/32/23612_2.png) [@Anabella\_Cristaldi](https://discuss.elastic.co/u/Anabella_Cristaldi)\
**Post date:** [January 11, 2019, 2:35pm UTC](https://discuss.elastic.co/t/xml-filter-share-value-between-events/163360/3 "2019-01-11T14:35:30Z")

</div>

Thank you @Badger.  
The XML is ok (I put a fragment of the XML in the message and I forgot to remove the /Report name tag).  
It took me a while to understand the solution, but finally It worked  
Thanks a lot!  
Regards  
Ana

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 8, 2019, 2:49pm UTC](https://discuss.elastic.co/t/xml-filter-share-value-between-events/163360/4 "2019-02-08T14:49:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
