<?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: sum the number of events based on list of possible values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107251#M183350</link>
    <description>&lt;P&gt;Let's assume you have your list of possible values in the lookup named &lt;EM&gt;message_id_lookup&lt;/EM&gt;, your events sourceytpe is named &lt;EM&gt;messages&lt;/EM&gt; and you have the &lt;EM&gt;message_id&lt;/EM&gt; field in your events ant the lookup file looks like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;message_id
value1
value2
value3
value4
value5
value6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, you can use following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup message_id_lookup
| stats count by message_id
| eval count=count-1
| append [search sourcetype=messages | stats count by message_id ]
| stats sum(count) by message_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To raise an alert if the message_id doesn't appear in your events you can define the saved search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | inputlookup message_id_lookup 
 | search NOT [search sourcetype=messages | dedup message_id | fields message_id]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then build the alert on this search.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 14:27:07 GMT</pubDate>
    <dc:creator>dariusz_kwasny</dc:creator>
    <dc:date>2020-09-28T14:27:07Z</dc:date>
    <item>
      <title>sum the number of events based on list of possible values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107249#M183348</link>
      <description>&lt;P&gt;I have an event with a field = message_id. &lt;BR /&gt;
I have to count the number of occurrences of this id based on a input list of possible values eg. [value1,value2,value3]&lt;/P&gt;

&lt;P&gt;something like -&amp;gt; | stats count by message_id, but this doesn't take missing values into account.&lt;/P&gt;

&lt;P&gt;The result should be something like&lt;BR /&gt;
message_id               count&lt;BR /&gt;
value1                   10&lt;BR /&gt;
value2                   20&lt;BR /&gt;
value3                   0&lt;/P&gt;

&lt;P&gt;How can I do this ?&lt;/P&gt;

&lt;P&gt;Second part of the question is that I need to raise an alert if any value = 0&lt;/P&gt;

&lt;P&gt;Sorry for my noob questions&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2013 09:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107249#M183348</guid>
      <dc:creator>preben12</dc:creator>
      <dc:date>2013-07-26T09:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: sum the number of events based on list of possible values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107250#M183349</link>
      <description>&lt;P&gt;How is the search statement like this?&lt;/P&gt;

&lt;P&gt;･････| stats count(eval(message_id="VALUE1")) as VALUE1,count(eval(message_id="VALUE2")) as VALUE2,count(eval(message_id="VALUE3")) as VALUE3 | transpose |rename column as message_id,"row 1" as count&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:26:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107250#M183349</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2020-09-28T14:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: sum the number of events based on list of possible values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107251#M183350</link>
      <description>&lt;P&gt;Let's assume you have your list of possible values in the lookup named &lt;EM&gt;message_id_lookup&lt;/EM&gt;, your events sourceytpe is named &lt;EM&gt;messages&lt;/EM&gt; and you have the &lt;EM&gt;message_id&lt;/EM&gt; field in your events ant the lookup file looks like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;message_id
value1
value2
value3
value4
value5
value6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, you can use following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup message_id_lookup
| stats count by message_id
| eval count=count-1
| append [search sourcetype=messages | stats count by message_id ]
| stats sum(count) by message_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To raise an alert if the message_id doesn't appear in your events you can define the saved search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | inputlookup message_id_lookup 
 | search NOT [search sourcetype=messages | dedup message_id | fields message_id]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then build the alert on this search.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:27:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107251#M183350</guid>
      <dc:creator>dariusz_kwasny</dc:creator>
      <dc:date>2020-09-28T14:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: sum the number of events based on list of possible values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107252#M183351</link>
      <description>&lt;P&gt;nice even better to use a lookup table. Will try it out&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2013 05:51:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-the-number-of-events-based-on-list-of-possible-values/m-p/107252#M183351</guid>
      <dc:creator>preben12</dc:creator>
      <dc:date>2013-07-30T05:51:21Z</dc:date>
    </item>
  </channel>
</rss>

