<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is there a way to use eval before the initial event search (sourcetype=xx)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189888#M54682</link>
    <description>&lt;P&gt;This works! My final version was &lt;CODE&gt;replace(tostring("".tostring($subid$, "hex").""),"x","")&lt;/CODE&gt; where I replace the 0x with just 0 as I need 8 digits with a 0-pad in front.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jan 2015 01:01:23 GMT</pubDate>
    <dc:creator>RMartinezDTV</dc:creator>
    <dc:date>2015-01-23T01:01:23Z</dc:date>
    <item>
      <title>Is there a way to use eval before the initial event search (sourcetype=xx)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189885#M54679</link>
      <description>&lt;P&gt;Hi, I'm trying to run a search for recent transactions based on a user ID. I need to convert the user ID to hex before I can use it as the event field contain the ID in hex. The idea here is to use a dashboard with a form input field for the decimal user ID.&lt;/P&gt;

&lt;P&gt;This is what I was thinking:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval userid_hex=tonumber("",16) | search index=xx sourcetype=xx userID=userid_hex | transaction maxevents=2 transactionID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which gives me no events returned. I've rearranged the location of the eval and get the same results.&lt;/P&gt;

&lt;P&gt;Obviously this works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=xx sourcetype=xx | eval userid_hex=tonumber("",16) | search userID=userid_hex | transaction maxevents=2 transactionID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it pull all events in the timewindow before filtering on userID. For 24 hours, I have approximately 3 million events so this is very inefficient.&lt;/P&gt;

&lt;P&gt;Is there a way to do evals before the initial search? Or am I missing some alternative method?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jan 2015 17:43:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189885#M54679</guid>
      <dc:creator>RMartinezDTV</dc:creator>
      <dc:date>2015-01-22T17:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to use eval before the initial event search (sourcetype=xx)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189886#M54680</link>
      <description>&lt;P&gt;You'll need an eval-based macro for that. And tonumber() is not the right function, you'll need tostring(). &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Create a Macro that has the eval-based definition checked (in Advanced Search | Macros)&lt;/LI&gt;
&lt;LI&gt;Call it in your search before the first pipe&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Macro Name: &lt;CODE&gt;toHex(1)&lt;/CODE&gt;&lt;BR /&gt;
Macro Definition: &lt;CODE&gt;tostring("\"".tostring($idDecimal$, "hex")."\"")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Usage:  index=xx sourcetype=xx `toHex(22)`&lt;/P&gt;

&lt;P&gt;In your form obviously you'd need to substitue 22 above with the userId token.  &lt;/P&gt;</description>
      <pubDate>Thu, 22 Jan 2015 18:18:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189886#M54680</guid>
      <dc:creator>_d_</dc:creator>
      <dc:date>2015-01-22T18:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to use eval before the initial event search (sourcetype=xx)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189887#M54681</link>
      <description>&lt;P&gt;You could do this with a simple subsearch (remember, subsearches get executed first):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=xx sourcetype=xx [|gentimes start=-1 | eval userID=tostring(yournumbergoeshere,"hex") | fields userID]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jan 2015 18:26:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189887#M54681</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-01-22T18:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to use eval before the initial event search (sourcetype=xx)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189888#M54682</link>
      <description>&lt;P&gt;This works! My final version was &lt;CODE&gt;replace(tostring("".tostring($subid$, "hex").""),"x","")&lt;/CODE&gt; where I replace the 0x with just 0 as I need 8 digits with a 0-pad in front.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 01:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-use-eval-before-the-initial-event-search/m-p/189888#M54682</guid>
      <dc:creator>RMartinezDTV</dc:creator>
      <dc:date>2015-01-23T01:01:23Z</dc:date>
    </item>
  </channel>
</rss>

