<?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: How to use wildcards with eval to create a field/value pair that is the direct value of a random field matching a pattern? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109723#M28654</link>
    <description>&lt;P&gt;This is getting me super close, but not quite there&lt;/P&gt;

&lt;P&gt;Your first example worked for one subset, but I think perhaps I did a bad job of explaining the whole problem:&lt;/P&gt;

&lt;P&gt;so I have one sourcetype that contains 2 types of events.&lt;/P&gt;

&lt;P&gt;One event looks like this:&lt;/P&gt;

&lt;P&gt;Job Id: 78172.queue01&lt;BR /&gt;
    Job_Name = bob&lt;BR /&gt;
    Job_Owner = bob@queue01&lt;BR /&gt;
    resources_used.cpupercent = 0&lt;BR /&gt;
    resources_used.cput = 00:00:24&lt;BR /&gt;
    resources_used.mem = 12356kb&lt;BR /&gt;
    resources_used.ncpus = 384&lt;BR /&gt;
    resources_used.vmem = 408076kb&lt;BR /&gt;
    resources_used.walltime = 00:00:21&lt;BR /&gt;
    job_state = R&lt;BR /&gt;
    queue = parallel&lt;BR /&gt;
    &lt;STRONG&gt;Resource_List.jg_n24_256_none_FEX_rd_a = 384&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;And another event will look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;resources_available.jg_n24_256_kepler_FEX_rd_a = 648
resources_available.jg_n24_256_kepler_FEX_rd_b = 0
resources_available.jg_n24_256_kepler_FEX_rd_c = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;resources_available.jg_n24_256_none_FEX_rd_a = 6384&lt;/STRONG&gt;&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_b = 9472&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_c = 1536&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_d = 0&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_e = 0&lt;/P&gt;

&lt;P&gt;The resource_list value is what is requested, the resources_available number is what is available and the stuff in between are sets of queues.    What I'm attempting to do is determine what percentage of the request event A is being used of whats available in event B.  &lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 19:17:47 GMT</pubDate>
    <dc:creator>mjones414</dc:creator>
    <dc:date>2020-09-28T19:17:47Z</dc:date>
    <item>
      <title>How to use wildcards with eval to create a field/value pair that is the direct value of a random field matching a pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109721#M28652</link>
      <description>&lt;P&gt;I have a dataset where each event will have a field that is the name of a particular group.  this field has a standard naming convention which makes it easy to pick out, but its value is a numerical value that can be different for each event.  I need to create an eval field that is the value of whatever particular field this is by matching on its naming convention, but eval doesn't seem to take wildcards very well.  &lt;/P&gt;

&lt;P&gt;e.g.&lt;BR /&gt;
event1&lt;BR /&gt;
coolfielda=12&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;event2&lt;BR /&gt;
coolfieldb=15&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;event3&lt;BR /&gt;
coolfielda=13&lt;/P&gt;

&lt;P&gt;eval coolfactor=match(coolfield%)&lt;/P&gt;

&lt;P&gt;or eval coolfactor=match(%oolfie%) &amp;lt;-- would be more the case based on the naming convention&lt;/P&gt;

&lt;P&gt;Any help is appreciated!.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2015 16:46:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109721#M28652</guid>
      <dc:creator>mjones414</dc:creator>
      <dc:date>2015-03-26T16:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to use wildcards with eval to create a field/value pair that is the direct value of a random field matching a pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109722#M28653</link>
      <description>&lt;P&gt;I think this might work for you, provided there's only one "cool field" per event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... your search ... | foreach *oolfie* [eval coolfactor='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This won't work if there's more than one such field per event because the &lt;CODE&gt;foreach&lt;/CODE&gt; clause will keep overwriting the &lt;CODE&gt;coolfactor&lt;/CODE&gt; field with all of the fields until the last one. But if you only have one per event, this should do the trick.&lt;/P&gt;

&lt;P&gt;Alternatively, if you know the names of the fields ahead of time, you can use &lt;CODE&gt;coalesce&lt;/CODE&gt; instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... your search ... | eval coolfactor=coalesce(coolfielda,coolfieldb,coolfieldc)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But you can't use &lt;CODE&gt;coalesce&lt;/CODE&gt; with a wildcard. Thus the &lt;CODE&gt;foreach&lt;/CODE&gt; construction above.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2015 18:23:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109722#M28653</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-03-26T18:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use wildcards with eval to create a field/value pair that is the direct value of a random field matching a pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109723#M28654</link>
      <description>&lt;P&gt;This is getting me super close, but not quite there&lt;/P&gt;

&lt;P&gt;Your first example worked for one subset, but I think perhaps I did a bad job of explaining the whole problem:&lt;/P&gt;

&lt;P&gt;so I have one sourcetype that contains 2 types of events.&lt;/P&gt;

&lt;P&gt;One event looks like this:&lt;/P&gt;

&lt;P&gt;Job Id: 78172.queue01&lt;BR /&gt;
    Job_Name = bob&lt;BR /&gt;
    Job_Owner = bob@queue01&lt;BR /&gt;
    resources_used.cpupercent = 0&lt;BR /&gt;
    resources_used.cput = 00:00:24&lt;BR /&gt;
    resources_used.mem = 12356kb&lt;BR /&gt;
    resources_used.ncpus = 384&lt;BR /&gt;
    resources_used.vmem = 408076kb&lt;BR /&gt;
    resources_used.walltime = 00:00:21&lt;BR /&gt;
    job_state = R&lt;BR /&gt;
    queue = parallel&lt;BR /&gt;
    &lt;STRONG&gt;Resource_List.jg_n24_256_none_FEX_rd_a = 384&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;And another event will look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;resources_available.jg_n24_256_kepler_FEX_rd_a = 648
resources_available.jg_n24_256_kepler_FEX_rd_b = 0
resources_available.jg_n24_256_kepler_FEX_rd_c = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;resources_available.jg_n24_256_none_FEX_rd_a = 6384&lt;/STRONG&gt;&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_b = 9472&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_c = 1536&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_d = 0&lt;BR /&gt;
    resources_available.jg_n24_256_none_FEX_rd_e = 0&lt;/P&gt;

&lt;P&gt;The resource_list value is what is requested, the resources_available number is what is available and the stuff in between are sets of queues.    What I'm attempting to do is determine what percentage of the request event A is being used of whats available in event B.  &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:17:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109723#M28654</guid>
      <dc:creator>mjones414</dc:creator>
      <dc:date>2020-09-28T19:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to use wildcards with eval to create a field/value pair that is the direct value of a random field matching a pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109724#M28655</link>
      <description>&lt;P&gt;Oh, well, that's something very different. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;You'll need some &lt;CODE&gt;rex&lt;/CODE&gt; commands in here to extract the string you want into its own field. You'll need two, one for the first kind and one for the second kind, something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "Resource_List\.(?&amp;lt;resname&amp;gt;\w+)\s+=\s+(?&amp;lt;num&amp;gt;\d+)" | rex "resources_available\.(?&amp;lt;resname&amp;gt;\w+)\s+=\s+(?&amp;lt;denom&amp;gt;\d+)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now you have an event with your resource name and numerator, and another event with the resource name and denominator. Then use &lt;CODE&gt;stats&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt; to get your percentage&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats sum(num) as num sum(denom) as denom by resname | eval percentage=(num*100/denom)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Mar 2015 14:16:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-wildcards-with-eval-to-create-a-field-value-pair-that/m-p/109724#M28655</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-03-27T14:16:47Z</dc:date>
    </item>
  </channel>
</rss>

