Splunk Search

How to search all the events consisting of a word that I get from a variable?

piece
Explorer

Consider I have 8 events.
1. txn started for fruit.mango
2. money paid for fruit.mango
3. received fruit.mango
4. txn completed for fruit.mango
5. cust wants to buy apple
6. getting money for apple
7. sending apple to cust
8. txn started for veegtable.carrot


I get a variable 'name' from my dashboard. This name is actually a string consisting of space separated words or just a single word. For ex. it could be either 'apple' or 'txn started for fruit.mango'.  What I want to do is first I want to extract the name of article then search the whole event space with that article name and then do further processing.

Ex. If I get $name$= 'txn started for fruit.mango'. I want to extract mango and then run the query such that I get all the events which have the word mango in it. After that i create a table of the steps the transaction took. I use 

 

 

index=.. $name | if(match($name, "\s"), mvindex(split($name, "."), 1), $name)

 

 

to extract the name but  then I get only a single event matching that is `txn started for fruit.mango`, other events which also has 'mango' in it like 'received fruit.mango' doesnt match.

How do I go about it? Any help will be much appreciated, thanks.

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
<form version="1.1">
  <label>Text parsing</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="name">
      <label>Select name</label>
      <choice value="txn started for fruit.mango">txn started for fruit.mango</choice>
      <change>
        <eval token="app">mvindex(split($name$,"."),1)</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>app is $app$</html>
    </panel>
  </row>
</form>

View solution in original post

piece
Explorer

@ITWhisperer Oh, in that case could you please help me to figure out how to use <eval> before <search> tag in xml.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Where is this "variable" coming from?

If it is from a SimpleXML input, you could include some change processing on the input to create a token which has split "mango" from the rest of the input token value, and use that token instead.

0 Karma

piece
Explorer

@ITWhisperer I can not make changes to the input variable 'name' as a lot of other things depend on it.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I am not saying to change 'name', I said to create a token (based on the contents of 'name')

0 Karma

piece
Explorer

@ITWhisperer Oh, in that case could you please help me determine how do I use <eval> tag to extract the value before the <search><query>My splunk query</query></search>

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
<form version="1.1">
  <label>Text parsing</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="name">
      <label>Select name</label>
      <choice value="txn started for fruit.mango">txn started for fruit.mango</choice>
      <change>
        <eval token="app">mvindex(split($name$,"."),1)</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>app is $app$</html>
    </panel>
  </row>
</form>
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!

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 ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...