# How to read XML logs

**URL:** https://discuss.elastic.co/t/how-to-read-xml-logs/104664
**Category:** Logstash
**Created:** [October 20, 2017, 7:43am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664 "2017-10-20T07:43:17Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![abhisek](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@abhisek](https://discuss.elastic.co/u/abhisek)
#### Post date: [October 20, 2017, 7:43am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/1 "2017-10-20T07:43:17Z")

</div>

Hi team,

My log file is "|" separated but two fields contains XML data. please let me know how can i read this.

---

<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 23, 2017, 5:18am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/2 "2017-10-23T05:18:32Z")

</div>

Please show an example.

---

<div class="post-metadata">

### Author: ![abhisek](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@abhisek](https://discuss.elastic.co/u/abhisek)
#### Post date: [October 23, 2017, 7:09am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/3 "2017-10-23T07:09:20Z")

</div>

My Xml file looks like:

`1000|121|2017-07-18 15:14:25.893024|0|xxx.xxx.net|read|'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.lookup.sdp.bharti.ibm.com"> <soapenv:Header/> <soapenv:Body> <web:getLookUpServiceDetails> <getLookUpService> <serviceRequester>iOBD</serviceRequester> <lineOfBusiness>mobility</lineOfBusiness> <lookupAttribute> <searchAttrValue>911425152231426</searchAttrValue> </lookupAttribute> </getLookUpService> </web:getLookUpServiceDetails> </soapenv:Body> </soapenv:Envelope>'|'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns:getLookUpServiceDetailsResponse xmlns:ns="http://webservices.lookup.sdp.bharti.ibm.com"> <getLookUpServiceReturn> <errorInfo> <ErrorCode>M136</ErrorCode> <ErrorMessage>While executing transform reformat for port out0: Index out of bounds in assignment for mapEntry.attributeValue. Index is 0 but vector has no elements. Source is the value "attribute_value_vec". </ErrorMessage> </errorInfo> <lookupResponseList/> </getLookUpServiceReturn> </ns:getLookUpServiceDetailsResponse> </soapenv:Body> </soapenv:Envelope> '|1500390865`

As you can see my log is "|" separated and it has two xml data below are field in which my log need to be mapped.

```
txn_cd - 1000
user_id - 121
start_time - 2017-07-18 15:14:25.893024
status - 0
host -xxx.xxx.net
ser_name - read
request - '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.lookup.sdp.bharti.ibm.com"> <soapenv:Header/> <soapenv:Body> <web:getLookUpServiceDetails> <getLookUpService> <serviceRequester>iOBD</serviceRequester> <lineOfBusiness>mobility</lineOfBusiness> <lookupAttribute> <searchAttrValue>911425152231426</searchAttrValue> </lookupAttribute> </getLookUpService> </web:getLookUpServiceDetails> </soapenv:Body> </soapenv:Envelope>'
response - '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns:getLookUpServiceDetailsResponse xmlns:ns="http://webservices.lookup.sdp.bharti.ibm.com"> <getLookUpServiceReturn> <errorInfo> <ErrorCode>M136</ErrorCode> <ErrorMessage>While executing transform reformat for port out0: Index out of bounds in assignment for mapEntry.attributeValue. Index is 0 but vector has no elements. Source is the value "attribute_value_vec". </ErrorMessage> </errorInfo> <lookupResponseList/> </getLookUpServiceReturn> </ns:getLookUpServiceDetailsResponse> </soapenv:Body> </soapenv:Envelope> '
txn_id -1500390865

```

please help me with the configuration file.

---

<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 23, 2017, 1:10pm UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/4 "2017-10-23T13:10:22Z")

</div>

You should be able to use a csv filter to split up the line into separate fields.

---

<div class="post-metadata">

### Author: ![abhisek](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@abhisek](https://discuss.elastic.co/u/abhisek)
#### Post date: [October 24, 2017, 9:58am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/5 "2017-10-24T09:58:39Z")

</div>

Used the below config file to split the line

```
input {
  file {
    path => "abc/abc.dat"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
      separator => "|"
      columns => ["txn_cd","usr_id","event_ts","status","host","service_name","request","response","txn_id"]
  }
   date{
match => ["event_ts", "yyyy-MM-dd HH:mm:ss.SSSSSS"]
target => "event_ts"
}
 mutate {convert => ["status", "integer"]}
}
output {
    elasticsearch {
        hosts => "http://abc:9200"
        index => "xml"
   }
    stdout {}
}

```

but the fields are not properly matched

---

<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 24, 2017, 1:12pm UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/6 "2017-10-24T13:12:05Z")

</div>

> but the fields are not properly matched

Please elaborate. What _do_ you get?

---

<div class="post-metadata">

### Author: ![abhisek](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@abhisek](https://discuss.elastic.co/u/abhisek)
#### Post date: [October 25, 2017, 10:38am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/7 "2017-10-25T10:38:54Z")

</div>

My output looks like this in kibana after loading

```
 @timestamp October 25th 2017, 16:02:31.500
t @version 1
t _id AV9Rk1UH8A4YAHFNXmUV
t _index xml
# _score - 
t _type logs
t host abc.abc.net
t message ||2017-07-18 15:40:16.836493|1|abc,abc.net|read|'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.lookup.sdp.bharti.ibm.com"> <soapenv:Header/> <soapenv:Body> <web:getLookUpServiceDetails> <getLookUpService> <serviceRequester>iOBD</serviceRequester> <lineOfBusiness>mobility</lineOfBusiness> <lookupAttribute> <searchAttrValue>911425152231426</searchAttrValue> </lookupAttribute> </getLookUpService> </web:getLookUpServiceDetails> </soapenv:Body> </soapenv:Envelope>'|'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns:getLookUpServiceDetailsResponse xmlns:ns="http://webservices.lookup.sdp.bharti.ibm.com"> <getLookUpServiceReturn> <errorInfo> <ErrorCode/> <ErrorMessage/> </errorInfo> <lookupResponseList> <mapEntry> <attributeName>region</attributeName> <attributeValue>["VIVO", "VIVO", "OPPO", "OPPO", "OPPO", "OPPO"]</attributeValue> </mapEntry> <mapEntry> <attributeName>msisdn</attributeName> <attributeValue>"Maharashtra"</attributeValue> </mapEntry> <mapEntry> <attributeName>imei</attributeName> <attributeValue>"917756870222"</attributeValue> </mapEntry> <mapEntry> <attributeName>imsi</attributeName> <attributeValue>"911425152231426"</attributeValue> </mapEntry> <mapEntry> <attributeName>device_vendor</attributeName> <attributeValue>"404909092353805"</attributeValue> </mapEntry> <mapEntry> <attributeName>device_type</attributeName> <attributeValue>"E311"</attributeValue> </mapEntry> <mapEntry> <attributeName>device_version</attributeName> <attributeValue>"T2222"</attributeValue> </mapEntry> <mapEntry> <attributeName>g3</attributeName> <attributeValue>"Yes"</attributeValue> </mapEntry> <mapEntry> <attributeName>mms</attributeName> <attributeValue>"Yes"</attributeValue> </mapEntry> <mapEntry> <attributeName>gprs</attributeName> <attributeValue>"Yes"</attributeValue> </mapEntry> <mapEntry> <attributeName>streaming</attributeName> <attributeValue>"Yes"</attributeValue> </mapEntry> <mapEntry> <attributeName>ota</attributeName> <attributeValue>"Yes"</attributeValue> </mapEntry> <mapEntry> <attributeName>wap</attributeName> <attributeValue>"Yes"</attributeValue> </mapEntry> <mapEntry> <attributeName>os</attributeName> <attributeValue>"Google"</attributeValue> </mapEntry> <mapEntry> <attributeName>version</attributeName> <attributeValue>"4.4.2"</attributeValue> </mapEntry> <mapEntry> <attributeName>camera</attributeName> <attributeValue>"Yes"</attributeValue> </mapEntry> <mapEntry> <attributeName>apn</attributeName> <attributeValue>""AIRTELGPRS.COM,AIRTELMMS.COM""</attributeValue> </mapEntry> </lookupResponseList> </getLookUpServiceReturn> </ns:getLookUpServiceDetailsResponse> </soapenv:Body> </soapenv:Envelope> '|1500392416
t path /abc/abc
t tags _csvparsefailure

```

Fields are not mapping according to the configuration file

---

<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 25, 2017, 10:40am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/8 "2017-10-25T10:40:05Z")

</div>

As the `_csvparsefailure` tag indicates something goes wrong with the CSV parsing. The Logstash log should contain more information.

---

<div class="post-metadata">

### Author: ![abhisek](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@abhisek](https://discuss.elastic.co/u/abhisek)
#### Post date: [October 25, 2017, 11:16am UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/9 "2017-10-25T11:16:54Z")

</div>

Could you please help me on what extra information that need to be put in ?

---

<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 25, 2017, 12:05pm UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/10 "2017-10-25T12:05:53Z")

</div>

I meant that you should read the Logstash log file and look for clues about the CSV parse failure.

---

<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 22, 2017, 12:07pm UTC](https://discuss.elastic.co/t/how-to-read-xml-logs/104664/11 "2017-11-22T12:07:27Z")

</div>

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