<?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 find count of events by host from inputlookup? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606054#M210749</link>
    <description>&lt;P&gt;The first query&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|inputlookup file.csv | stats count by host&lt;/LI-CODE&gt;&lt;P&gt;is counting how many times each host name appears in the lookup file.&amp;nbsp; That's why the results are only '1'.&lt;/P&gt;&lt;P&gt;The second query look for all hosts in the default indexes and joins those results with the lookup file.&amp;nbsp; Hosts not in an index will have a null count, but that can be fixed with the &lt;FONT face="courier new,courier"&gt;fillnull&lt;/FONT&gt; command.&amp;nbsp; To help ensure more hosts are found, specify &lt;FONT face="courier new,courier"&gt;index=*&lt;/FONT&gt; in the &lt;FONT face="courier new,courier"&gt;tstats&lt;/FONT&gt; command.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|inputlookup file.csv 
| join type=left host [|tstats count where index=* by host] 
| fillnull value=0 host&lt;/LI-CODE&gt;&lt;P&gt;I've seen host names fail to match if the lookup contains a host name, but the events contain a FQDN or vice versa.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jul 2022 21:09:23 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2022-07-18T21:09:23Z</dc:date>
    <item>
      <title>How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606047#M210745</link>
      <description>&lt;P&gt;I have a lookup table with only one field, named host. The table contains a list of hostnames.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to find a way to get a count of events by host using this lookup table as the input (i.e. the hosts I want a count for).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried a variety of approaches. For example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;|inputlookup file.csv | stats count by host&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Every host returns a count of 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;|inputlookup file.csv | join type=left host [|tstats count by host] &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About a dozen hosts return counts; the rest return null values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Complicating this problem seems to be case. If I crunch all the hosts to upper or lowercase, I get different results, but neither returns a complete result set. That seems super odd given that field values aren't case sensitive. I've tried crunching case with eval as well as in the lookup table itself, to no avail.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We're stumped. What is the best approach to use a lookup table of hostnames to get an event count by host?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 20:23:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606047#M210745</guid>
      <dc:creator>whar_garbl</dc:creator>
      <dc:date>2022-07-18T20:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606054#M210749</link>
      <description>&lt;P&gt;The first query&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|inputlookup file.csv | stats count by host&lt;/LI-CODE&gt;&lt;P&gt;is counting how many times each host name appears in the lookup file.&amp;nbsp; That's why the results are only '1'.&lt;/P&gt;&lt;P&gt;The second query look for all hosts in the default indexes and joins those results with the lookup file.&amp;nbsp; Hosts not in an index will have a null count, but that can be fixed with the &lt;FONT face="courier new,courier"&gt;fillnull&lt;/FONT&gt; command.&amp;nbsp; To help ensure more hosts are found, specify &lt;FONT face="courier new,courier"&gt;index=*&lt;/FONT&gt; in the &lt;FONT face="courier new,courier"&gt;tstats&lt;/FONT&gt; command.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|inputlookup file.csv 
| join type=left host [|tstats count where index=* by host] 
| fillnull value=0 host&lt;/LI-CODE&gt;&lt;P&gt;I've seen host names fail to match if the lookup contains a host name, but the events contain a FQDN or vice versa.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 21:09:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606054#M210749</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-07-18T21:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606063#M210754</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Thanks. I did start out using index=* as well, but I forgot about it. I still get null values for way too many hosts, but I can search for them directly using the same syntax (i.e. index=* and short hostname as found in the inputlookup) and get many thousands of events. It's making me nuts because it seems like it should be super straightforward!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 18 Jul 2022 21:56:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606063#M210754</guid>
      <dc:creator>whar_garbl</dc:creator>
      <dc:date>2022-07-18T21:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606071#M210761</link>
      <description>&lt;P&gt;You could do this, just using the inputlookup as a subsearch&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where [ | inputlookup file.csv ] by host&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 18 Jul 2022 23:27:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606071#M210761</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-07-18T23:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606220#M210830</link>
      <description>&lt;P&gt;This was close to what I want to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where [ | inputlookup file.csv ],index=* by host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it doesn't include hosts from the lookup that have no events, which I want to include. Adding a fillnull afterward doesn't do it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 19:30:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606220#M210830</guid>
      <dc:creator>whar_garbl</dc:creator>
      <dc:date>2022-07-19T19:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606241#M210839</link>
      <description>&lt;P&gt;In order to show the hosts where there is no data, your search should look like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where [ | inputlookup file.csv ],index=* by host
| append [
  | inputlookup file.csv
  | eval count=0
]
| stats max(count) as count by host&lt;/LI-CODE&gt;&lt;P&gt;so, you are first finding the data for the hosts that exist (tstats) and then adding all the hosts with count=0 to the end of the list, then finally aggregating the max count for all hosts, so that those hosts who have no data will then have 0 as their count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 22:02:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606241#M210839</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-07-19T22:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606246#M210843</link>
      <description>&lt;P&gt;Thanks. I've tried a very similar permutation today, but this brings back the problem I had at another point: I get about a third more results than I should, and they're duplicates (one uppercase, one lowercase).&lt;/P&gt;&lt;P&gt;If I cast the host field to upper or lowercase before the stats max command, I get the correct number of hosts but around 10% then erroneously return 0 events. E.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where [ | inputlookup file.csv ],index=* by host
| append [
  | inputlookup file.csv
  | eval count=0
]
| eval host=upper(host)
| dedup host
| stats max(count) as count by host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected result:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;host      count
HOST1     12345
HOST2     67890
HOST3     24680&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actual result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;host      count
HOST1     0
HOST2     67890
HOST3     24680&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I search for HOST1 or host1 manually, there are many thousands of events in the same time period. Since field values are supposed to be case-insensitive (IIRC), I'm stumped as to why case is relevant here. It's trivial to do the case-casting in the actual lookup file if appropriate, but I think there's one more piece missing somewhere.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 22:33:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606246#M210843</guid>
      <dc:creator>whar_garbl</dc:creator>
      <dc:date>2022-07-19T22:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606249#M210845</link>
      <description>&lt;P&gt;You should not do dedup - that's wrong. The whole point of stats is to do the aggregation of hosts, so you NEED both hosts (data value and 0 value from lookup) to exist, so the max(count) can work.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 22:43:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606249#M210845</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-07-19T22:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606251#M210847</link>
      <description>&lt;P&gt;Ah, I see what you mean. Righto. So, then I end up getting the same results as explained, with ~10% of hosts showing up with different-case duplicates - one with appropriate event counts, and one with zero. Any thoughts on what's going on there?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 23:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606251#M210847</guid>
      <dc:creator>whar_garbl</dc:creator>
      <dc:date>2022-07-19T23:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606271#M210855</link>
      <description>&lt;P&gt;No idea without seeing the data and not sure what you mean by different case duplicates - narrow it down to a single host and show what the data is and what should be expected.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 05:22:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606271#M210855</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-07-20T05:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606366#M210885</link>
      <description>&lt;P&gt;Expected:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;host       count
HOST1      11111
HOST2      22222
HOST3      33333&lt;/LI-CODE&gt;&lt;P&gt;Actual:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;host       count
HOST1      11111
HOST2      22222
HOST3      0
host1      0
host2      0
host3      33333&lt;/LI-CODE&gt;&lt;P&gt;Does that make sense? I get HOSTx and hostx (the lookups are all uppercased), and on one or the other there are zero events counted - but they're the same host.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 15:18:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606366#M210885</guid>
      <dc:creator>whar_garbl</dc:creator>
      <dc:date>2022-07-20T15:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606404#M210902</link>
      <description>&lt;P&gt;That's odd if you are doing&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval host=upper(host)&lt;/LI-CODE&gt;&lt;P&gt;before the stats command as there cannot be any lower case hosts in there any more&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 23:45:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606404#M210902</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-07-20T23:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to find count of events by host from inputlookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606526#M210954</link>
      <description>&lt;P&gt;Huh. It must be an issue of WHEN I crunch the case, because this does the trick and gets the results I expect. The only zero hosts now are true zeros. Success!&lt;/P&gt;&lt;P&gt;You're the best! Thanks so much for sticking with this and holding my hand through it. I'm going to accept the post with the main query as the answer for the next person. Cheers!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 14:45:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-count-of-events-by-host-from-inputlookup/m-p/606526#M210954</guid>
      <dc:creator>whar_garbl</dc:creator>
      <dc:date>2022-07-21T14:45:01Z</dc:date>
    </item>
  </channel>
</rss>

