<?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 set default count=0 when the search result is null in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213217#M62543</link>
    <description>&lt;P&gt;Strictly speaking you don't need a lookup table - you could do all this with eval, but I find a lookup table petter practice for his sort of thing. &lt;/P&gt;</description>
    <pubDate>Wed, 04 Jan 2017 14:27:16 GMT</pubDate>
    <dc:creator>jplumsdaine22</dc:creator>
    <dc:date>2017-01-04T14:27:16Z</dc:date>
    <item>
      <title>how to set default count=0 when the search result is null</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213215#M62541</link>
      <description>&lt;P&gt;When the search result is null with the special filter, how to show it with count =0 instead of no record?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app  sourcetype=ELP99 host="CHeapp*" source="C:\\TPFiles\\LogFile*.log" sourcetype="etp99" 
msgId=LS-* OR msgId=LAS-* OR msgId=LSP-* OR msgId=LRS-*
| rex field=msgId "(?&amp;lt;msgId_short&amp;gt;.*)-"
| stats dc(serverName) as ServerInRotation  by msgId_short
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;msgId_short     ServerInRotation  
LS                              4
LSP                            5
LRS                            1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But no records about LAS, I want to display row LAS|0. How to do it?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 03:44:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213215#M62541</guid>
      <dc:creator>Freya_X</dc:creator>
      <dc:date>2017-01-04T03:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to set default count=0 when the search result is null</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213216#M62542</link>
      <description>&lt;P&gt;You'll need to a combination of &lt;CODE&gt;join type=left&lt;/CODE&gt; and an &lt;CODE&gt;inputlookup&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;First, create a lookup table with just the field msgId and all the values you want to capture. &lt;/P&gt;

&lt;P&gt;Now your initial search can look like this (this isn't actually neccessary, but since you went to the trouble of creating the lookup table you can use this!): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app sourcetype=ELP99 host="CHeapp*" source="C:\\TPFiles\\LogFile*.log" sourcetype="etp99"  [| inputlookup msgID.csv] 
| rex field=msgId "(?&amp;lt;msgId_short&amp;gt;.*)-"
| stats dc(serverName) as ServerInRotation by msgId_short
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next  we'll join it to another invocation of the lookup, but the main search will actually become a subsearch  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup msgID.csv  | rex field=msgId "(?&amp;lt;msgId_short&amp;gt;.*)-"  fillnull value=0 ServerInRotation  
| join type=left msgId_short [ 
    index=app sourcetype=ELP99 host="CHeapp*" source="C:\\TPFiles\\LogFile*.log" sourcetype="etp99"  [| inputlookup msgID.csv] 
| rex field=msgId "(?&amp;lt;msgId_short&amp;gt;.*)-"
| stats dc(serverName) as ServerInRotation by msgId_short
]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm having a guess at your regex - if you want to include special characters in a post you need a newline and indent 4 spaces.&lt;/P&gt;

&lt;P&gt;Anyhow, give it a go. See here for more on join: &lt;A href="https://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Join"&gt;https://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Join&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 14:26:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213216#M62542</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-01-04T14:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to set default count=0 when the search result is null</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213217#M62543</link>
      <description>&lt;P&gt;Strictly speaking you don't need a lookup table - you could do all this with eval, but I find a lookup table petter practice for his sort of thing. &lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 14:27:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213217#M62543</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-01-04T14:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to set default count=0 when the search result is null</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213218#M62544</link>
      <description>&lt;P&gt;Hi Freya_X, &lt;/P&gt;

&lt;P&gt;Seems the rex syntax in your search was incorrect. You must supply a field name to which to assign the regex-captured group value. For example, if the new field name is msg_prefix, then the search should be: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app sourcetype=ELP99 host="CHeapp*" source="C:\\TPFiles\\LogFile*.log" sourcetype="etp99"
msgId=LS- OR msgId=LAS- OR msgId=LSP- OR msgId=LRS-
| rex field=msgId "(?&amp;lt;msg_prefix&amp;gt;.*)-"
| stats dc(serverName) as ServerInRotation by msgId_short
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please update your search and try again. Thanks! &lt;BR /&gt;
Hunter&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 14:47:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213218#M62544</guid>
      <dc:creator>hunters_splunk</dc:creator>
      <dc:date>2017-01-04T14:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to set default count=0 when the search result is null</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213219#M62545</link>
      <description>&lt;P&gt;Give this a try (adding dummy rows with 0 count for all msgId_short that you may get, then taking the max count. Anything missing in main search result will show 0 count)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app  sourcetype=ELP99 host="CHeapp*" source="C:\\TPFiles\\LogFile*.log" sourcetype="etp99" 
 msgId=LS-* OR msgId=LAS-* OR msgId=LSP-* OR msgId=LRS-*
 | rex field=msgId "(?&amp;lt;msgId_short&amp;gt;.*)-"
 | stats dc(serverName) as ServerInRotation  by msgId_short
| append [| gentimes start=-1 | eva msgId_short="LAS LSP LRS" | table msgId_short | makemv msgId_short | mvexpand msgId_short | eval ServerInRotation=0 ]
| stats max(ServerInRotation) as ServerInRotation by msgId_short
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Jan 2017 16:21:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-set-default-count-0-when-the-search-result-is-null/m-p/213219#M62545</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-01-04T16:21:57Z</dc:date>
    </item>
  </channel>
</rss>

