<?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: Search for event X and Y, but only Y during business hours? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38544#M8761</link>
    <description>&lt;P&gt;Stats and eval.  Elegant weapons for a more civilized age. Have fun.  You're just at the beginning. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Feb 2013 19:10:27 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2013-02-21T19:10:27Z</dc:date>
    <item>
      <title>Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38537#M8754</link>
      <description>&lt;P&gt;Hey Guys, This is my current search (It looks for SQL I/O delays) =&lt;/P&gt;

&lt;P&gt;sourcetype="WinEventLog:Application" MSSQLSERVER "requests taking longer than"&lt;/P&gt;

&lt;P&gt;But there are few DEV servers where we don't want to hear about I/O delays after hours.. So I figured out how to limit the time search. This returns 9-5pm:&lt;/P&gt;

&lt;P&gt;sourcetype="WinEventLog:Application" MSSQLSERVER earliest=-1d@d latest=@d | addinfo | where _time &amp;gt; (info_max_time-54000) AND _time &amp;lt; (info_max_time-25200) &lt;/P&gt;

&lt;P&gt;But how do I make it search all servers all the time except DEV servers outside of business hours? been racking my brain all day.&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:21:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38537#M8754</guid>
      <dc:creator>johnpof</dc:creator>
      <dc:date>2020-09-28T13:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38538#M8755</link>
      <description>&lt;P&gt;if your date has date_hour extracted (which it generally will),  then you can use those as searchterms. &lt;/P&gt;

&lt;P&gt;I'm not sure what your searchterms are for production vs dev so I'm going to invent two searchterms - "PRODUCTION" and "DEV" to be my placeholders. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="WinEventLog:Application" MSSQLSERVER ( PRODUCTION OR ( DEV date_hour&amp;gt;08 date_hour&amp;lt;17 ) )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that if by chance the time values splunk is getting its timestamps from,  are themselves in epochtime format,  (ie if the times in your events are the number of seconds since 1/1/1970),  then there's a weird bug in Splunk where it &lt;EM&gt;will&lt;/EM&gt; create date_hour fields for all those events,  however the values it computes for the date_hour fields will be the hours as they would be calculated if your server were in the GMT timezone.    This means that unless GMT also happens to be the timezone your server is in,  all of the date_hour values will all be off by a constant.   If this is the case you can of course use the &lt;CODE&gt;eval&lt;/CODE&gt; command and it's &lt;CODE&gt;strftime&lt;/CODE&gt; function to make yourself reliable hour_of_day fields.  The drawback is they wont be search-time fields and you'll have to get all of the DEV events off disk and filter them in a subsequent &lt;CODE&gt;search&lt;/CODE&gt; or &lt;CODE&gt;where&lt;/CODE&gt; clause, and this wont be as fast as using date_hour in the initial search clause. &lt;/P&gt;

&lt;P&gt;UPDATE:   &lt;/P&gt;

&lt;P&gt;Sorry I didn't know that WinEventLog:Application didn't have date_* fields by default.  So if you have to make yourself fields with eval and strftime, here's how it would work.   The _time field exists on all events, and it's epochtime-valued,  meaning it's the number of seconds elapsed since 1/1/1970.   This is easy to confused because whenever an epochtime-valued field called "_time" appears in the Splunk UI,  it will actually appear as a readable text timestamp.  However remember for the purposes of eval and stats and everything else, it's just a big number of seconds.    &lt;/P&gt;

&lt;P&gt;Thus. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search terms | eval hour_of_day=strftime(_time,"%H") | eval day_of_week=strftime(_time,"%u") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(you could use another strftime constant to get "Monday" vs "Sunday" but %u will give you integers from 0 to 7 and I find it easier to work with. &lt;/P&gt;

&lt;P&gt;So here's your search to match all Production events, and Dev events but only on weekdays during business hours. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search terms | eval hour_of_day=strftime(_time,"%H") | eval day_of_week=strftime(_time,"%u") | search ( PRODUCTION OR ( DEV hour_of_day&amp;gt;9 hour_of_day&amp;lt;18 day_of_week&amp;gt;0 day_of_week&amp;lt;6) )
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:21:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38538#M8755</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2020-09-28T13:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38539#M8756</link>
      <description>&lt;P&gt;the traditional date hour type search won't work in WinEventLog, hense my info_max_time search. I'm a week into splunk so quite green.&lt;BR /&gt;
Can you elaborate on how would I use eval / strftime to make hour_of_day fields? If I understand correctly, what I am doing for the time works but it's offset. What do you mean by date_hour extracted? &lt;BR /&gt;
For most of my queries I use: ( date_wday=monday OR date_wday=tuesday OR date_wday=wednesday OR date_wday=thursday OR date_wday=friday ) AND ( date_hour &amp;gt; 9 AND date_hour &amp;lt; 18 )&lt;BR /&gt;
But that doesn't work for WinEvents&lt;BR /&gt;
I appreciate the response.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:21:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38539#M8756</guid>
      <dc:creator>johnpof</dc:creator>
      <dc:date>2020-09-28T13:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38540#M8757</link>
      <description>&lt;P&gt;OK. Gotcha. I'll update my answer above.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2013 01:31:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38540#M8757</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-02-21T01:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38541#M8758</link>
      <description>&lt;P&gt;This makes sense, but it's not working and I know i'm close. Production is basically database or in this case computers named DB and the ones i'd like to keep quiet are DEV servers. This returns no results:&lt;/P&gt;

&lt;P&gt;sourcetype="WinEventLog:Application" MSSQLSERVER "requests taking longer than" eval hour_of_day=strftime(_time,"%H") | eval day_of_week=strftime(_time,"%u") | search ( ComputerName="DB*" OR ( ComputerName="dev*" hour_of_day&amp;gt;9 hour_of_day&amp;lt;18 day_of_week&amp;gt;0 day_of_week&amp;lt;6) )&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:22:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38541#M8758</guid>
      <dc:creator>johnpof</dc:creator>
      <dc:date>2020-09-28T13:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38542#M8759</link>
      <description>&lt;P&gt;eval is a different search command, so you need a pipe before it.  &lt;CODE&gt;sourcetype="WinEventLog:Application" MSSQLSERVER "requests taking longer than" | eval hour_of_day=strftime(_time,"%H") | eval day_of_week=strftime(_time,"%u") | search ( ComputerName="DB" OR ( ComputerName="dev" hour_of_day&amp;gt;9 hour_of_day&amp;lt;18 day_of_week&amp;gt;0 day_of_week&amp;lt;6) )&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2013 18:20:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38542#M8759</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-02-21T18:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38543#M8760</link>
      <description>&lt;P&gt;Brilliant this works! thanks a lot&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2013 18:56:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38543#M8760</guid>
      <dc:creator>johnpof</dc:creator>
      <dc:date>2013-02-21T18:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Search for event X and Y, but only Y during business hours?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38544#M8761</link>
      <description>&lt;P&gt;Stats and eval.  Elegant weapons for a more civilized age. Have fun.  You're just at the beginning. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2013 19:10:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-for-event-X-and-Y-but-only-Y-during-business-hours/m-p/38544#M8761</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-02-21T19:10:27Z</dc:date>
    </item>
  </channel>
</rss>

