<?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 Using external lookup and mstats together in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496442#M194666</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| mstats span=1d sum(_value) as "ClosedTime" WHERE index=metrics_prod metric_name=com.foo.timeClosed | eval ClosedTimeinMin = ((ClosedTime/1000)/60) | table _time ClosedTimeinMin
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It basically shows how long a device in a shop was closed (out of order) a day:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"_time",ClosedTimeinMin
"2019-09-25T00:00:00.000+0200","0.27218333333"
"2019-09-26T00:00:00.000+0200","528.49098333333"
"2019-09-27T00:00:00.000+0200","1077.4227000000"
"2019-09-30T00:00:00.000+0200","3410.40781666667"
"2019-10-01T00:00:00.000+0200","533.04851666667"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is that it contains those time periods as well when the shop was closed. When the shop is closed and the device is off it is not a problem so this time period should not be in the report. I can call a REST API which returns the opening hours of the shop. This Python script (which calls the REST API) is written according to the rules described here (external lookup): &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/Knowledge/Configureexternallookups"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/Knowledge/Configureexternallookups&lt;/A&gt;&lt;BR /&gt;
It was written by me so it can return the opening hours in any format. How could I use this script in the search in order to exclude the hours when the shop was closed? Can I use the "lookup" command together with "mstats" command? And if yes how should I phrase the query in order to achieve the desired result?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Ivan&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 07:53:45 GMT</pubDate>
    <dc:creator>zahorans</dc:creator>
    <dc:date>2019-10-01T07:53:45Z</dc:date>
    <item>
      <title>Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496442#M194666</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| mstats span=1d sum(_value) as "ClosedTime" WHERE index=metrics_prod metric_name=com.foo.timeClosed | eval ClosedTimeinMin = ((ClosedTime/1000)/60) | table _time ClosedTimeinMin
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It basically shows how long a device in a shop was closed (out of order) a day:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"_time",ClosedTimeinMin
"2019-09-25T00:00:00.000+0200","0.27218333333"
"2019-09-26T00:00:00.000+0200","528.49098333333"
"2019-09-27T00:00:00.000+0200","1077.4227000000"
"2019-09-30T00:00:00.000+0200","3410.40781666667"
"2019-10-01T00:00:00.000+0200","533.04851666667"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is that it contains those time periods as well when the shop was closed. When the shop is closed and the device is off it is not a problem so this time period should not be in the report. I can call a REST API which returns the opening hours of the shop. This Python script (which calls the REST API) is written according to the rules described here (external lookup): &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/Knowledge/Configureexternallookups"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/Knowledge/Configureexternallookups&lt;/A&gt;&lt;BR /&gt;
It was written by me so it can return the opening hours in any format. How could I use this script in the search in order to exclude the hours when the shop was closed? Can I use the "lookup" command together with "mstats" command? And if yes how should I phrase the query in order to achieve the desired result?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Ivan&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 07:53:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496442#M194666</guid>
      <dc:creator>zahorans</dc:creator>
      <dc:date>2019-10-01T07:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496443#M194667</link>
      <description>&lt;P&gt;I have the feeling that it is not even possible this way. Any other technique/extension/plugin/etc which might work?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 12:57:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496443#M194667</guid>
      <dc:creator>zahorans</dc:creator>
      <dc:date>2019-10-04T12:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496444#M194668</link>
      <description>&lt;P&gt;Hi zahorans,&lt;/P&gt;

&lt;P&gt;it should work like this and my apologies for using "meta-code" to sketch the idea:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| mstats span=1d sum(_value) as "ClosedTime" WHERE index=metrics_prod metric_name=com.foo.timeClosed
| &amp;lt;external.py returning fields openingTime, closingTime as epoch (integer)&amp;gt;    &amp;lt;&amp;lt;&amp;lt; Add the opening hours 
| where _time&amp;gt;=openingTime AND _time&amp;lt;=closingTime    &amp;lt;&amp;lt;&amp;lt; Select only the events that fall between open and close
| stats sum(ClosedTimeinMin) as TotalOutage &amp;lt;&amp;lt;&amp;lt; Sum up all outages to get the total Outage time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, you could add some additional parameter to the metrics, detailing the failed device/source and add a &lt;STRONG&gt;by&lt;/STRONG&gt; to the stats to get the outages per device.&lt;/P&gt;

&lt;P&gt;This is just a rough sketch. To make it perfect, you would rather test if the end of the outage was inside the opening hours, clipping the outage length to the openingTime whenever the outage started before store open. The same could be done for all outages that start while open: clip their length at shop close. It gets tricky if an outage spans several days... but you get the point.&lt;/P&gt;

&lt;P&gt;Hope it helps&lt;BR /&gt;
Oliver&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 14:59:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496444#M194668</guid>
      <dc:creator>ololdach</dc:creator>
      <dc:date>2019-10-04T14:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496445#M194669</link>
      <description>&lt;P&gt;Thanks Oliver,&lt;BR /&gt;
I am waiting for our Splunk admin to let me upload the script then I try what you suggested.&lt;BR /&gt;
Cheers,&lt;BR /&gt;
Ivan&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 08:17:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496445#M194669</guid>
      <dc:creator>zahorans</dc:creator>
      <dc:date>2019-10-07T08:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496446#M194670</link>
      <description>&lt;P&gt;Hi Oliver,&lt;BR /&gt;
Thanks for your answer. I am waiting for our Splunk admin to let me upload the script then I try what you suggested.&lt;BR /&gt;
Cheers,&lt;BR /&gt;
Ivan&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 08:20:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496446#M194670</guid>
      <dc:creator>zahorans</dc:creator>
      <dc:date>2019-10-07T08:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496447#M194671</link>
      <description>&lt;P&gt;I tried to use an already existing lookup though and it didn't work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | mstats span=1d sum(_value) as "ClosedTime" WHERE index=till_sre_metrics_prod metric_name=com.tesco.ui.prod.timeOnClosedPage | lookup store_lookup.csv host AS host OUTPUTNEW store_number AS store_number | fields store_number
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the "store_number" field doesn't appear. Why? "Host" field should be available even in case of stats.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 09:07:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496447#M194671</guid>
      <dc:creator>zahorans</dc:creator>
      <dc:date>2019-10-07T09:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496448#M194672</link>
      <description>&lt;P&gt;It might be because of this statement:  "You cannot use automatic lookups with metrics data."&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/Metrics/Search"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/Metrics/Search&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 09:35:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496448#M194672</guid>
      <dc:creator>zahorans</dc:creator>
      <dc:date>2019-10-07T09:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using external lookup and mstats together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496449#M194673</link>
      <description>&lt;P&gt;If this is true then I cannot really solve my original problem.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 09:40:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-external-lookup-and-mstats-together/m-p/496449#M194673</guid>
      <dc:creator>zahorans</dc:creator>
      <dc:date>2019-10-07T09:40:02Z</dc:date>
    </item>
  </channel>
</rss>

