# Trying to fetch values from xml and feed into influxdb

**URL:** <https://discuss.elastic.co/t/trying-to-fetch-values-from-xml-and-feed-into-influxdb/102988>\
**Category:** Logstash\
**Created:** [October 6, 2017, 9:59am UTC](https://discuss.elastic.co/t/trying-to-fetch-values-from-xml-and-feed-into-influxdb/102988 "2017-10-06T09:59:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niranjan\_kaup](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@Niranjan\_kaup](https://discuss.elastic.co/u/Niranjan_kaup)\
**Post date:** [October 6, 2017, 9:59am UTC](https://discuss.elastic.co/t/trying-to-fetch-values-from-xml-and-feed-into-influxdb/102988/1 "2017-10-06T09:59:14Z")

</div>

Sample xml file:

Tove Jani Reminder Don't forget me this weekend!

Below is the configuration:

input {

file {  
path =\> "/mnt/users.xml"  
start\_position =\> "beginning"  
type =\> xml  
}  
}  
filter {

```
xml {
    source => "message"
    store_xml => "false"
    xpath => [
        "/note/to/text()","id"
    ]
}

```

}  
output {  
stdout {}  
}

and below is the output which I am getting curently

2017-10-06T09:52:07.006Z localhost.localdomain \>  
2017-10-06T09:52:19.024Z localhost.localdomain   
2017-10-06T09:52:19.025Z localhost.localdomain Tove  
2017-10-06T09:52:19.026Z localhost.localdomain Jani  
2017-10-06T09:52:19.029Z localhost.localdomain Reminder  
2017-10-06T09:52:19.030Z localhost.localdomain Don't forget me this weekend!  
2017-10-06T09:52:19.030Z localhost.localdomain

But, I expect it should be in "id" -\> "Tove" is the result so that I can feed into influxdb.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 10, 2017, 5:33am UTC](https://discuss.elastic.co/t/trying-to-fetch-values-from-xml-and-feed-into-influxdb/102988/2 "2017-10-10T05:33:09Z")

</div>

As you can see from your post it doesn't contain a shred of XML. Format XML snippets as preformatted text to avoid the de-HTMLificiation performed by the posting software.

The file input is line-oriented so if you want to read a file into a single event you'll have to use the multiline codec. Examples of this has been posted in the past.

---

<div class="post-metadata">

**Author:** ![Niranjan\_kaup](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@Niranjan\_kaup](https://discuss.elastic.co/u/Niranjan_kaup)\
**Post date:** [October 10, 2017, 5:52am UTC](https://discuss.elastic.co/t/trying-to-fetch-values-from-xml-and-feed-into-influxdb/102988/3 "2017-10-10T05:52:54Z")

</div>

Thanks for your reply:

I got that option and seems working. But, one issue is when it is getting parsed it stores null value at variable. Below is the configuration and codebug output:

input {

file {  
path =\> "/mnt/users.xml"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
codec =\> multiline {  
pattern =\> "\<repositories"  
negate =\> "true"  
what =\> "previous"  
auto\_flush\_interval =\> 1  
}  
}  
}  
filter {

```
xml {
    source => "message"
    store_xml => "true"
    target => "influxdb"
    force_array => false
    xpath => [
        "/repositories-item/resourceURI/text()","resourceURI"
    ]
}

```

}

output {  
influxdb {  
host =\> localhost  
retention\_policy =\> autogen

# use\_event\_fields\_for\_data\_points =\> true

data\_points =\> {  
"resourceURI" =\> "%{resourceURI}"  
}  
}  
stdout { codec =\> rubydebug }  
#stdout {}  
}

Output:

{  
"path" =\> "/mnt/users.xml",  
"@timestamp" =\> 2017-10-10T05:44:10.913Z,  
"@version" =\> "1",  
"host" =\> "localhost.localdomain",  
"resourceURI" =\> [  
[0] "[http://localhost:8081/nexus/service/local/repositories/thirdparty](http://localhost:8081/nexus/service/local/repositories/thirdparty)"  
],  
"message" =\> " \n [http://localhost:8081/nexus/service/local/repositories/thirdparty](http://localhost:8081/nexus/service/local/repositories/thirdparty)\n [http://localhost:8081/nexus/content/repositories/thirdparty](http://localhost:8081/nexus/content/repositories/thirdparty)\n thirdparty\n 3rd party\n hosted\n RELEASE\n maven2\n org.sonatype.nexus.proxy.repository.Repository\n maven2\n true\n true\n file:/opt/sonatype-work/nexus/storage/thirdparty/\n ",  
"influxdb" =\> {  
"effectiveLocalStorageUrl" =\> "file:/opt/sonatype-work/nexus/storage/thirdparty/",  
"providerRole" =\> "org.sonatype.nexus.proxy.repository.Repository",  
"format" =\> "maven2",  
"resourceURI" =\> "[http://localhost:8081/nexus/service/local/repositories/thirdparty](http://localhost:8081/nexus/service/local/repositories/thirdparty)",  
"repoType" =\> "hosted",  
"contentResourceURI" =\> "[http://localhost:8081/nexus/content/repositories/thirdparty](http://localhost:8081/nexus/content/repositories/thirdparty)",  
"provider" =\> "maven2",  
"name" =\> "3rd party",  
"exposed" =\> "true",  
"repoPolicy" =\> "RELEASE",  
"id" =\> "thirdparty",  
"userManaged" =\> "true"  
},  
"tags" =\> [  
[0] "multiline"  
]  
}  
{  
"@version" =\> "1",  
"host" =\> "localhost.localdomain",  
"path" =\> "/mnt/users.xml",  
"@timestamp" =\> 2017-10-10T05:44:10.802Z,  
"message" =\> "\n ",  
"tags" =\> [  
[0] "multiline",  
[1] "\_xmlparsefailure"  
]  
}  
{  
"path" =\> "/mnt/users.xml",  
"@timestamp" =\> 2017-10-10T05:44:10.807Z,  
"@version" =\> "1",  
"host" =\> "localhost.localdomain",  
"resourceURI" =\> [  
[0] "[http://localhost:8081/nexus/service/local/repositories/snapshots](http://localhost:8081/nexus/service/local/repositories/snapshots)"  
],  
"message" =\> " \n [http://localhost:8081/nexus/service/local/repositories/snapshots](http://localhost:8081/nexus/service/local/repositories/snapshots)\n [http://localhost:8081/nexus/content/repositories/snapshots](http://localhost:8081/nexus/content/repositories/snapshots)\n snapshots\n Snapshots\n hosted\n SNAPSHOT\n maven2\n org.sonatype.nexus.proxy.repository.Repository\n maven2\n true\n true\n file:/opt/sonatype-work/nexus/storage/snapshots/\n ",  
"influxdb" =\> {  
"effectiveLocalStorageUrl" =\> "file:/opt/sonatype-work/nexus/storage/snapshots/",  
"providerRole" =\> "org.sonatype.nexus.proxy.repository.Repository",  
"format" =\> "maven2",  
"resourceURI" =\> "[http://localhost:8081/nexus/service/local/repositories/snapshots](http://localhost:8081/nexus/service/local/repositories/snapshots)",  
"repoType" =\> "hosted",  
"contentResourceURI" =\> "[http://localhost:8081/nexus/content/repositories/snapshots](http://localhost:8081/nexus/content/repositories/snapshots)",  
"provider" =\> "maven2",  
"name" =\> "Snapshots",  
"exposed" =\> "true",  
"repoPolicy" =\> "SNAPSHOT",  
"id" =\> "snapshots",  
"userManaged" =\> "true"  
},  
"tags" =\> [  
[0] "multiline"  
]  
}

---

<div class="post-metadata">

**Author:** ![Niranjan\_kaup](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@Niranjan\_kaup](https://discuss.elastic.co/u/Niranjan_kaup)\
**Post date:** [October 10, 2017, 5:55am UTC](https://discuss.elastic.co/t/trying-to-fetch-values-from-xml-and-feed-into-influxdb/102988/4 "2017-10-10T05:55:53Z")

</div>

How to make sure null values will be ignored when we are sending to influxdb ?

---

<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:** [November 7, 2017, 5:56am UTC](https://discuss.elastic.co/t/trying-to-fetch-values-from-xml-and-feed-into-influxdb/102988/5 "2017-11-07T05:56:19Z")

</div>

Closed on November 7, 2017, 5:56am UTC

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