<?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 display a list of hosts which satisfies a condition? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341211#M101165</link>
    <description>&lt;P&gt;Take a look at the search you started with. I'm going to truncate it after the &lt;CODE&gt;eval/case&lt;/CODE&gt; statement:&lt;BR /&gt;
&lt;CODE&gt;| metadata type=hosts | search [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*" | rename "Device" as my_hostname | eval host=lower(my_hostname) | fields host ] | eval host=lower(host) | append [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*"| rename "Device" as my_hostname | eval host=lower(my_hostname) | eval recentTime=0, lastTime=0, host=lower(host) | fields host recentTime lastTime ] | dedup host | eval category=case(recentTime&amp;gt;=relative_time(now(), "-24h"), "Systems reported to Splunk in last 24 hours", (recentTime0), "Systems reported to Splunk more than 24 hours ago", recentTime=0, "Systems never reported to Splunk")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I copied that from your post. First, I'm going to point out that I believe there is a typo here - I don't think the &lt;CODE&gt;case&lt;/CODE&gt; statement should contain &lt;CODE&gt;"Systems reported to Splunk in last 24 hours", (recentTime0)&lt;/CODE&gt; but should rather contain &lt;CODE&gt;"Systems reported to Splunk in last 24 hours", (recentTime&amp;gt;0)&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;So dive into the &lt;CODE&gt;case&lt;/CODE&gt; statement itself. If you aren't familiar with it, here's a good place to start:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/ConditionalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/ConditionalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The statement is assigning a value to a field called &lt;CODE&gt;category&lt;/CODE&gt;, based on the value of the field &lt;CODE&gt;recentTime&lt;/CODE&gt;. If &lt;CODE&gt;recentTime&lt;/CODE&gt; is greater than the value of &lt;CODE&gt;relative_time(now(), "-24h")&lt;/CODE&gt; - which means it's looking for events with a timestamp in &lt;CODE&gt;recentTime&lt;/CODE&gt; that is within the last 24 hours - then the event will get &lt;CODE&gt;category="Systems reported to Splunk in last 24 hours"&lt;/CODE&gt;. If &lt;CODE&gt;recentTime&lt;/CODE&gt; isn't within the last 24 hours, then it will advance to the next option in the case statement - one that checks to see if &lt;CODE&gt;recentTime&amp;gt;0&lt;/CODE&gt;. Here it's looking for any valid (non-zero) timestamp in &lt;CODE&gt;recentTime&lt;/CODE&gt;, which indicates that the system logged some events at some time. Finally, it looks for events where &lt;CODE&gt;recentTime=0&lt;/CODE&gt;, which indicates that the system never checked in at all. &lt;/P&gt;

&lt;P&gt;So if you use this truncated version of your search and then just filter the events by category, you can output any of the categories you please:&lt;BR /&gt;
&lt;CODE&gt;| search category="Systems reported to Splunk in last 24 hours" | stats values(host) AS systems_seen_in_last_24_hours&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Moreover, if you are not looking to print the table for which you originally generated this query, you could do away with the category assignment entirely and narrow  your search to this:&lt;BR /&gt;
&lt;CODE&gt;| metadata type=hosts | search [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*" | rename "Device" as my_hostname | eval host=lower(my_hostname) | fields host ] | eval host=lower(host) | append [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*"| rename "Device" as my_hostname | eval host=lower(my_hostname) | eval recentTime=0, lastTime=0, host=lower(host) | fields host recentTime lastTime ] | dedup host | where recentTime&amp;gt;=relative_time(now(), "-24h") | stats values(host)&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2017 20:49:51 GMT</pubDate>
    <dc:creator>elliotproebstel</dc:creator>
    <dc:date>2017-11-01T20:49:51Z</dc:date>
    <item>
      <title>how to display a list of hosts which satisfies a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341208#M101162</link>
      <description>&lt;P&gt;I have a query as follows &lt;/P&gt;

&lt;P&gt;| metadata type=hosts | search [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*" | rename "Device" as my_hostname  | eval host=lower(my_hostname) | fields host ] | eval host=lower(host) | append [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*"| rename "Device" as my_hostname | eval host=lower(my_hostname) | eval recentTime=0, lastTime=0, host=lower(host) | fields host recentTime lastTime ] | dedup host | eval category=case(recentTime&amp;gt;=relative_time(now(), "-24h"), "Systems reported to Splunk in last 24 hours", (recentTime0), "Systems reported to Splunk more than 24 hours ago", recentTime=0, "Systems never reported to Splunk")  | stats dc(host) AS total_hosts BY category | addcoltotals labelfield=category label="Total" | eventstats max(total_hosts) AS all_totals | search NOT category="Total" | eval Percentage=tostring(round(total_hosts/all_totals*100,2))."%" | fields category total_hosts Percentage | rename total_hosts as "Host Count" &lt;/P&gt;

&lt;P&gt;Which gives the result as follows &lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/218659-today-pic.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Now instead of this. I want to modify my query to display only the list of hosts which are never reported to Splunk. It appears to be simple but when i tried to add the | search where category="Systems never reported to Splunk" .its not giving me any results. It would be great if anyone can help me to modify the query to display the results like below &lt;/P&gt;

&lt;P&gt;never_reported_systems&lt;/P&gt;

&lt;P&gt;kjhkj&lt;BR /&gt;
fkjhk&lt;BR /&gt;
vkjhk&lt;BR /&gt;
bkljhk&lt;BR /&gt;
nkljhk&lt;BR /&gt;
nkjh&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:32:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341208#M101162</guid>
      <dc:creator>pavanae</dc:creator>
      <dc:date>2020-09-29T16:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to display a list of hosts which satisfies a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341209#M101163</link>
      <description>&lt;P&gt;Well, if you have just been adding a search clause to the end of the existing search, you will never get hostnames out, because the earlier transforming commands have discarded them. There's probably some optimization you could do, but this will likely suffice for a start:&lt;BR /&gt;
&lt;CODE&gt;| metadata type=hosts | search [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*" | rename "Device" as my_hostname | eval host=lower(my_hostname) | fields host ] | eval host=lower(host) | append [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*"| rename "Device" as my_hostname | eval host=lower(my_hostname) | eval recentTime=0, host=lower(host) | fields host recentTime ] | dedup host | where recentTime=0 | stats values(host) AS never_reported_systems&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 15:50:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341209#M101163</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-11-01T15:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to display a list of hosts which satisfies a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341210#M101164</link>
      <description>&lt;P&gt;thanks for the answer @elliotproebstel. what if I want to display the "Systems reported to Splunk in last 24 hours"?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 18:54:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341210#M101164</guid>
      <dc:creator>pavanae</dc:creator>
      <dc:date>2017-11-01T18:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to display a list of hosts which satisfies a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341211#M101165</link>
      <description>&lt;P&gt;Take a look at the search you started with. I'm going to truncate it after the &lt;CODE&gt;eval/case&lt;/CODE&gt; statement:&lt;BR /&gt;
&lt;CODE&gt;| metadata type=hosts | search [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*" | rename "Device" as my_hostname | eval host=lower(my_hostname) | fields host ] | eval host=lower(host) | append [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*"| rename "Device" as my_hostname | eval host=lower(my_hostname) | eval recentTime=0, lastTime=0, host=lower(host) | fields host recentTime lastTime ] | dedup host | eval category=case(recentTime&amp;gt;=relative_time(now(), "-24h"), "Systems reported to Splunk in last 24 hours", (recentTime0), "Systems reported to Splunk more than 24 hours ago", recentTime=0, "Systems never reported to Splunk")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I copied that from your post. First, I'm going to point out that I believe there is a typo here - I don't think the &lt;CODE&gt;case&lt;/CODE&gt; statement should contain &lt;CODE&gt;"Systems reported to Splunk in last 24 hours", (recentTime0)&lt;/CODE&gt; but should rather contain &lt;CODE&gt;"Systems reported to Splunk in last 24 hours", (recentTime&amp;gt;0)&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;So dive into the &lt;CODE&gt;case&lt;/CODE&gt; statement itself. If you aren't familiar with it, here's a good place to start:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/ConditionalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/ConditionalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The statement is assigning a value to a field called &lt;CODE&gt;category&lt;/CODE&gt;, based on the value of the field &lt;CODE&gt;recentTime&lt;/CODE&gt;. If &lt;CODE&gt;recentTime&lt;/CODE&gt; is greater than the value of &lt;CODE&gt;relative_time(now(), "-24h")&lt;/CODE&gt; - which means it's looking for events with a timestamp in &lt;CODE&gt;recentTime&lt;/CODE&gt; that is within the last 24 hours - then the event will get &lt;CODE&gt;category="Systems reported to Splunk in last 24 hours"&lt;/CODE&gt;. If &lt;CODE&gt;recentTime&lt;/CODE&gt; isn't within the last 24 hours, then it will advance to the next option in the case statement - one that checks to see if &lt;CODE&gt;recentTime&amp;gt;0&lt;/CODE&gt;. Here it's looking for any valid (non-zero) timestamp in &lt;CODE&gt;recentTime&lt;/CODE&gt;, which indicates that the system logged some events at some time. Finally, it looks for events where &lt;CODE&gt;recentTime=0&lt;/CODE&gt;, which indicates that the system never checked in at all. &lt;/P&gt;

&lt;P&gt;So if you use this truncated version of your search and then just filter the events by category, you can output any of the categories you please:&lt;BR /&gt;
&lt;CODE&gt;| search category="Systems reported to Splunk in last 24 hours" | stats values(host) AS systems_seen_in_last_24_hours&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Moreover, if you are not looking to print the table for which you originally generated this query, you could do away with the category assignment entirely and narrow  your search to this:&lt;BR /&gt;
&lt;CODE&gt;| metadata type=hosts | search [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*" | rename "Device" as my_hostname | eval host=lower(my_hostname) | fields host ] | eval host=lower(host) | append [| inputlookup ABCD.csv | eval Device=mvindex(split(Device,"."),0) | search NOT "Device Type"="alys*"| rename "Device" as my_hostname | eval host=lower(my_hostname) | eval recentTime=0, lastTime=0, host=lower(host) | fields host recentTime lastTime ] | dedup host | where recentTime&amp;gt;=relative_time(now(), "-24h") | stats values(host)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 20:49:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-display-a-list-of-hosts-which-satisfies-a-condition/m-p/341211#M101165</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-11-01T20:49:51Z</dc:date>
    </item>
  </channel>
</rss>

