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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...