<?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: map not working with zero value data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23886#M4302</link>
    <description>&lt;P&gt;I'm not sure you're using &lt;CODE&gt;map&lt;/CODE&gt; correctly up there, but it sort of doesn't matter, because I'd suggest a different way below, and the "right" way (actually the way you're trying to make it work) would give you the same results as above anyway. It's just the same as &lt;CODE&gt;sourcetype=FW-LOG | stats count by rule&lt;/CODE&gt;. For the record, you'd need something like: &lt;CODE&gt;sourcetype=RULELIST | map search="search sourcetype=FW-LOG rule=$rule$" | stats count by rule&lt;/CODE&gt; or &lt;CODE&gt;sourcetype=RULELIST | map search="search sourcetype=FW-LOG rule=$rule$ | stats count by rule"&lt;/CODE&gt;. But for your data, it probably won't be different.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Aug 2010 10:50:30 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2010-08-02T10:50:30Z</dc:date>
    <item>
      <title>map not working with zero value data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23884#M4300</link>
      <description>&lt;P&gt;There is probably a better way to do this, but I am trying to catalog what rules are (and are not) used using the firewall log and a list of rules.  I came up with this search, but it does not show me rules that are matched zero times (even though the left hand side is the rule list):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=RULELIST | chart list(rule) | map search=search sourcetype=FW-LOG | stats count(rule) by rule 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;FW-LOG looks like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   date=11111 rule=2   
   date=11112 rule=3
   date=11113 rule=3  
   date=11114 rule=4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;RULELIST looks like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rule=1,ruledesc=rule1
rule=2,ruledesc=this is rule2
rule=3,ruledesc=some other rule
rule=4,ruledesc=blah
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I expect to see is this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rule          count
1               0
2               1
3               2
4               1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But instead, I see this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; rule          count
 2               1
 3               2
 4               1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I really want to know what rules are NOT getting used.  Maybe there is an option to map?  Any thoughts on this?  TIA&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2010 04:28:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23884#M4300</guid>
      <dc:creator>bfaber</dc:creator>
      <dc:date>2010-08-02T04:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: map not working with zero value data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23885#M4301</link>
      <description>&lt;P&gt;I would not write the search this way, and I would avoid &lt;CODE&gt;map&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=RULELIST OR sourcetype=FW-LOG 
| stats 
    count(eval(sourcetype!="RULELIST")) as count 
    first(ruledesc) as rulename 
  by rule
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will run much faster and scale up to much large data set sizes. This is a little tricky. Using &lt;CODE&gt;join&lt;/CODE&gt; is not as efficient as the above, but maybe more transparent:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=RULELIST 
| join type=left max=0 rule 
    [ search sourcetype=FW-LOG 
      | stats count by rule ] 
| eval count=coalesce(count,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And of course you can sort by &lt;CODE&gt;count&lt;/CODE&gt; or add &lt;CODE&gt;| where count=0&lt;/CODE&gt; to either, or change the final &lt;CODE&gt;eval&lt;/CODE&gt; clause of the latter to &lt;CODE&gt;| where isnull(count)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2010 10:19:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23885#M4301</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-08-02T10:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: map not working with zero value data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23886#M4302</link>
      <description>&lt;P&gt;I'm not sure you're using &lt;CODE&gt;map&lt;/CODE&gt; correctly up there, but it sort of doesn't matter, because I'd suggest a different way below, and the "right" way (actually the way you're trying to make it work) would give you the same results as above anyway. It's just the same as &lt;CODE&gt;sourcetype=FW-LOG | stats count by rule&lt;/CODE&gt;. For the record, you'd need something like: &lt;CODE&gt;sourcetype=RULELIST | map search="search sourcetype=FW-LOG rule=$rule$" | stats count by rule&lt;/CODE&gt; or &lt;CODE&gt;sourcetype=RULELIST | map search="search sourcetype=FW-LOG rule=$rule$ | stats count by rule"&lt;/CODE&gt;. But for your data, it probably won't be different.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2010 10:50:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23886#M4302</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-08-02T10:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: map not working with zero value data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23887#M4303</link>
      <description>&lt;P&gt;I appreciate the more efficient search, but it returns EXACTLY what my original does -- ie no zero values.  The second search you provide does not seem to work at all, but I'm still looking at it.&lt;/P&gt;

&lt;P&gt;Again, the end result needs to show EVERY left hand side value - even if the right hand size value is zero...&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2010 20:40:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23887#M4303</guid>
      <dc:creator>bfaber</dc:creator>
      <dc:date>2010-08-02T20:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: map not working with zero value data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23888#M4304</link>
      <description>&lt;P&gt;I just tried loading the exact data you had above. The first one above and it works fine for me, returning a 0 for rule 1. The second one works if you just add &lt;CODE&gt;| table rule,count,ruledesc&lt;/CODE&gt; to render it as a table with the selected columns. Not sure why the first one, in particular, wouldn't work for you.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2010 12:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23888#M4304</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-08-03T12:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: map not working with zero value data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23889#M4305</link>
      <description>&lt;P&gt;This works great -- I had a field naming issue that I didn't notice.  Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 07 Aug 2010 00:01:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/map-not-working-with-zero-value-data/m-p/23889#M4305</guid>
      <dc:creator>bfaber</dc:creator>
      <dc:date>2010-08-07T00:01:15Z</dc:date>
    </item>
  </channel>
</rss>

