<?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: Stats count use last event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-use-last-event/m-p/568444#M198101</link>
    <description>&lt;P&gt;You could possibly just stick a&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| head 1000&lt;/LI-CODE&gt;&lt;P&gt;or some other number right after the base search (before the first rex) and run it over a somewhat longer period (like 20 or 30 minutes in this case), if you had a reasonably predicable "count" you could go back to consistently.&lt;/P&gt;&lt;P&gt;How would you, as an actual person looking at the data, describe what you mean by "only showing the last data".&amp;nbsp; I mean, how would you do that if you had this data in excel?&amp;nbsp; What would define the "last data," and how would that be split apart from the data that came before?&lt;/P&gt;&lt;P&gt;I think with this answer we might be able to come up with something better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On a side note, this search looks both really fragile, and also could be faster and better.&lt;/P&gt;&lt;P&gt;Was the replace for 1H and 1E with UC1 skipped on purpose with the appendcols search?&lt;/P&gt;&lt;P&gt;I think if that was just an omission or isn't important, that you could do this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=centreon check_command="Cisco-SNMP-Interfaces-Global-Status" service_description="Status_All-Interfaces" src_interface!="Ethernet*.*" src_interface!="Vlan*" src_interface!="mgmt*" src_interface!="port*" src_interface!="Null*" src_interface!="loopback*" 
| head 1000
| rex field=host "ZSE-(?&amp;lt;loc&amp;gt;\w+)-(?&amp;lt;room&amp;gt;\w+).*"
| replace "1H" WITH "UC1"| replace "1E" WITH "UC1"| replace "2H" WITH "UC2"|replace "2F" WITH "UC2"| replace "6E" WITH "C6"| replace "6F" WITH "C6"| replace "6T" WITH "C6"| replace "4B" WITH "C4"| replace "4T" WITH "C4"| replace "4E" WITH "C4"
| eval site=loc+"-"+room
| stats count(src_interface) as tot_int, sum(eval(if(state_interface="up",1,0))) as tot_up by site
| eval tot_free = tot_int - tot_up&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure that probably needs tweaking, but the advantages in speed and non-duplicated SPL is very large - it's probably worth some time doing a thing like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Sep 2021 20:56:38 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2021-09-24T20:56:38Z</dc:date>
    <item>
      <title>Stats count use last event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-use-last-event/m-p/568344#M198049</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to make a report to count the number of interfaces available and used.&lt;/P&gt;&lt;P&gt;I found the query that matches my need.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=centreon check_command="Cisco-SNMP-Interfaces-Global-Status" service_description="Status_All-Interfaces" src_interface!="Ethernet*.*" src_interface!="Vlan*" src_interface!="mgmt*" src_interface!="port*" src_interface!="Null*" src_interface!="loopback*" 
| rex field=host "ZSE-(?&amp;lt;loc&amp;gt;\w+)-(?&amp;lt;room&amp;gt;\w+).*"
| replace "1H" WITH "UC1"| replace "1E" WITH "UC1"| replace "2H" WITH "UC2"|replace "2F" WITH "UC2"| replace "6E" WITH "C6"| replace "6F" WITH "C6"| replace "6T" WITH "C6"| replace "4B" WITH "C4"| replace "4T" WITH "C4"| replace "4E" WITH "C4"
| eval site=loc+"-"+room
| stats count(src_interface) as tot_int by site
| appendcols
[search index=centreon check_command="Cisco-SNMP-Interfaces-Global-Status" service_description="Status_All-Interfaces" src_interface!="Ethernet*.*" src_interface!="Vlan*" src_interface!="mgmt*" src_interface!="port*" src_interface!="Null*" src_interface!="loopback*" state_interface="up" 
| rex field=host "ZSE-(?&amp;lt;loc&amp;gt;\w+)-(?&amp;lt;room&amp;gt;\w+).*"
| replace "1H" WITH "UC1"| replace "1E" WITH "UC1"|replace "2H" WITH "UC2"|replace "2F" WITH "UC2"| replace "6E" WITH "C6"| replace "6F" WITH "C6"| replace "6T" WITH "C6"| replace "4B" WITH "C4"| replace "4T" WITH "C4"| replace "4E" WITH "C4"
| eval site=loc+"-"+room
| stats count(state_interface) as tot_up by site]
| eval tot_free=tot_int-tot_up&lt;/LI-CODE&gt;&lt;P&gt;My concern is the frequency of data reception by SPLUNK is not stable (plus or minus 10 minutes)&lt;/P&gt;&lt;P&gt;How to make so that my dream is based only on the last events received?&lt;/P&gt;&lt;P&gt;Thank's&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 09:07:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-use-last-event/m-p/568344#M198049</guid>
      <dc:creator>yoan</dc:creator>
      <dc:date>2021-09-24T09:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count use last event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-use-last-event/m-p/568444#M198101</link>
      <description>&lt;P&gt;You could possibly just stick a&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| head 1000&lt;/LI-CODE&gt;&lt;P&gt;or some other number right after the base search (before the first rex) and run it over a somewhat longer period (like 20 or 30 minutes in this case), if you had a reasonably predicable "count" you could go back to consistently.&lt;/P&gt;&lt;P&gt;How would you, as an actual person looking at the data, describe what you mean by "only showing the last data".&amp;nbsp; I mean, how would you do that if you had this data in excel?&amp;nbsp; What would define the "last data," and how would that be split apart from the data that came before?&lt;/P&gt;&lt;P&gt;I think with this answer we might be able to come up with something better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On a side note, this search looks both really fragile, and also could be faster and better.&lt;/P&gt;&lt;P&gt;Was the replace for 1H and 1E with UC1 skipped on purpose with the appendcols search?&lt;/P&gt;&lt;P&gt;I think if that was just an omission or isn't important, that you could do this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=centreon check_command="Cisco-SNMP-Interfaces-Global-Status" service_description="Status_All-Interfaces" src_interface!="Ethernet*.*" src_interface!="Vlan*" src_interface!="mgmt*" src_interface!="port*" src_interface!="Null*" src_interface!="loopback*" 
| head 1000
| rex field=host "ZSE-(?&amp;lt;loc&amp;gt;\w+)-(?&amp;lt;room&amp;gt;\w+).*"
| replace "1H" WITH "UC1"| replace "1E" WITH "UC1"| replace "2H" WITH "UC2"|replace "2F" WITH "UC2"| replace "6E" WITH "C6"| replace "6F" WITH "C6"| replace "6T" WITH "C6"| replace "4B" WITH "C4"| replace "4T" WITH "C4"| replace "4E" WITH "C4"
| eval site=loc+"-"+room
| stats count(src_interface) as tot_int, sum(eval(if(state_interface="up",1,0))) as tot_up by site
| eval tot_free = tot_int - tot_up&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure that probably needs tweaking, but the advantages in speed and non-duplicated SPL is very large - it's probably worth some time doing a thing like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 20:56:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-use-last-event/m-p/568444#M198101</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2021-09-24T20:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count use last event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-use-last-event/m-p/568460#M198110</link>
      <description>&lt;P&gt;If I understand you correctly, you're periodicaly getting a "dump" of a state of some gizmo. Each dump consists of several events. And you want to do a report only from the latest dump.&lt;/P&gt;&lt;P&gt;If the whole dump is "condensed" in terms of time (starts at some point in time and all subsequent events come at the same time or in a short period from the start), you can use a subsearch to find latest run of your dump and run the search with thus generated time limit.&lt;/P&gt;&lt;P&gt;Something like that:&lt;/P&gt;&lt;PRE&gt;&amp;lt;&amp;lt;your search&amp;gt;&amp;gt; [&lt;BR /&gt;  | tstats max(_time) as latest where index=your_index &lt;BR /&gt;  | eval earliest=latest-15 ] &lt;BR /&gt;| &amp;lt;&amp;lt;rest of your search&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;You might want to add timerange constraints to tstats (I don't remember if it's needed)&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 07:38:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-use-last-event/m-p/568460#M198110</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-09-25T07:38:42Z</dc:date>
    </item>
  </channel>
</rss>

