Splunk Search

Xpath command is not giving result

jayadevanepSPL
New Member

I have a XML embedded in another XML with escape characters

<Audit>
<tracker>XXXXX123</tracker>
<Message>&lt?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>&ltABCxmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:qu=&quot;http://qqqq.xsd&quot; xmlns:v1=&quot;http://www&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;>
&ltRM>
&ltCode>111&lt/Code>
&ltState>Avilable&lt/State>
&lt/RM> 
&ltRM>
&ltCode>222&lt/Code>
&ltState>Not avilable&lt/State>
&lt/RM>
&ltRM>
&ltCode>333&lt/Code>
&ltState>Not sure&lt/State>
&lt/RM>
&lt/ABC>
</Message>
</Audit>

I am suing below command to extract and convert the embedded XML to correct format. This page is not allow to how escape characters so removed the ";"

| rex "\<Message\>(?<Message>.*)\<\/Message\>" 
| eval Message1 = replace (Message,"&lt","<")
| eval Message2 = replace (Message1,"&gt",">")
| eval Message3 = replace (Message2,"&quot","\"")

Message3 giving below output

<?xml version="1.0" encoding="UTF-8"?><ABC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:qu="http://qqqq.xsd" xmlns:v1="http://www" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RM>
<Code>111</Code>
<State>Avilable</State>
</RM>
<RM>
<Code>222</Code>
<State>Not avilable</State>
</RM>
<RM>
<Code>333</Code>
<State>Not sure</State>
</RM>
</ABC>

Now I want to get RM in to one veriable if state is = “Not available”. I am using below command for that.

| xpath field=Message3  "// ABC / RM [State=' Not available ']" outfield=NAV

But NAV is not giving any result. Can you please help to fix the issue ?

Tags (2)
0 Karma

somesoni2
Revered Legend

The value based filter is not supported in Splunk's spath. (see the spath documentation for supported functionalities). Something like this would work for your requirement (run anywhere example, first few lines are just to generate sample data).

| gentimes start=-1 | eval _raw="<Audit>
 <tracker>XXXXX123</tracker>
 <Message>&lt?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>&ltABCxmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:qu=&quot;http://qqqq.xsd&quot; xmlns:v1=&quot;http://www&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;>
 &ltRM>
 &ltCode>111&lt/Code>
 &ltState>Avilable&lt/State>
 &lt/RM>    
 &ltRM>
 &ltCode>222&lt/Code>
 &ltState>Not available&lt/State>
 &lt/RM>
 &ltRM>
 &ltCode>333&lt/Code>
 &ltState>Not sure&lt/State>
 &lt/RM>
 &lt/ABC>
 </Message>
 </Audit>" | table _raw | spath | rename Audit.Message as Message | eval Message1 = replace (Message,"&lt","<")
 | eval Message1 = replace (Message1,"&gt",">")
 | eval Message3 = replace (Message1,"&quot","\"") | eval Message4=replace(Message3,"^([^\>]+)","") | eval Message5=replace(Message4,"^\>([^\>]+)\>","") | table Message5 | spath input=Message5 | eval temp=mvzip('RM.Code','RM.State',"#") | eval temp=mvfilter(match(temp,"#Not available")) 
0 Karma

jayadevanepSPL
New Member

Is this because of the presence of name space ?

0 Karma

jayadevanepSPL
New Member

I am using splunk version 6.3.1

0 Karma

sundareshr
Legend
0 Karma

jayadevanepSPL
New Member

but it seems there is no condition i can put for Spath .. Can I ?

0 Karma

sundareshr
Legend
0 Karma
Get Updates on the Splunk Community!

Dashboard Studio Challenge - Learn New Tricks, Showcase Your Skills, and Win Prizes!

Reimagine what you can do with your dashboards. Dashboard Studio is Splunk’s newest dashboard builder to ...

Introducing Edge Processor: Next Gen Data Transformation

We get it - not only can it take a lot of time, money and resources to get data into Splunk, but it also takes ...

Take the 2021 Splunk Career Survey for $50 in Amazon Cash

Help us learn about how Splunk has impacted your career by taking the 2021 Splunk Career Survey. Last year’s ...