Splunk Search

Distinct values from XML array in timechart

jonathanoberhau
New Member

I am looking at an XML response from an API that contains an array of messages. I want to timechart the messages for a dashboard so we can see the count of each type of error message over time.

What is tripping me up is that sometimes a message in one response type can be included in another response type ( in addtion to other messages) and I am having a hard time separating them into distinct columns in the time chart

 index=best_index_ever  "message.location"="cancelContract"
    | spath input=message.data.responseBody output=ResponseMessages 
 path=soap:Envelope.soap:Body.CancelContractResponse.CancelContractResult.Messages.Message
    | mvexpand ResponseMessages
    | spath input=ResponseMessages
    | eval Text = case( like(Text,"%Cannot Cancel Contract.%") AND NOT like(Text,"Transaction%"),"Cannot Cancel Contract",
                        like(Text,"Transaction%"),"Transaction Deadlock",
                        1=1,Text
                      )
    | timechart limit=0 useother=false count by Text

That is what I have so far. I tried using a case with an eval, but that does not work. It still lumps the responses with a message "Transaction...deadlocked" into the "Cannot Cancel Contract" column as well as includes them in the "Transaction...deadlocked" column.

Here is an example of the XML array of messages.

Response example 1:

<Messages>
       <Message>
          <Type>1</Type>
          <Code/>
          <Text>Transaction (Process ID 75) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.</Text>
       </Message>
       <Message>
          <Type>1</Type>
          <Code>SAVEFAIL</Code>
          <Text>Cannot save record.</Text>
       </Message>
       <Message>
          <Type>1</Type>
          <Code>CONTRACT_CANCEL_FAIL</Code>
          <Text>Cannot Cancel Contract.</Text>
       </Message>
</Messages>

Response example 2:

<Messages>
       <Message>
          <Type>1</Type>
          <Code>CONTRACT_CANCEL_FAIL</Code>
          <Text>Cannot Cancel Contract.</Text>
       </Message>
</Messages>

You'll see that the Cannot Cancel Contract message is in both responses, but the first response also contains two other messages. I am trying to have the timechart represent responses that only contain the "Cannot Cancel Contract" message as mutually exclusive of the messages that contain "Cannot Cancel Contract" + other messages.

Tags (1)
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...