<?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 do you exclude weekends from the calculation of expected end time? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453718#M128384</link>
    <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/160303"&gt;@louisawang&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;I would suggest to create one more field based on create_time_epoch which will tell you the day of ticket and based on that do the changes like below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index="test" sourcetype="incident_all_v3" 
     | eval check = strptime(strftime(_time , "%d/%m/%Y") , "%d/%m/%Y") 
     | eventstats max(check) as checktime 
     | where checktime = check 
     | dedup 1 ticket_id sortby -_time 
     | join ticket_id type=left 
         [ search index="test" sourcetype="incident_assigned" 
         | eval check = strptime(strftime(_time , "%d/%m/%Y") , "%d/%m/%Y") 
         | eventstats max(check) as checktime 
         | where checktime = check 
         | eval move_datetime = strptime(move_datetime, "%Y-%m-%d %H:%M:%S") 
         | dedup 1 ticket_id sortby -move_datetime 
         | eval move_datetime = strftime(move_datetime, "%Y-%m-%d %H:%M:%S") 
         | fields ticket_id move_datetime] 
     | eval realtime = if(isnotnull(move_datetime), move_datetime, create_time) 
     | eval create_time_epoch = strptime(realtime, "%Y-%m-%d %H:%M:%S") 
     | lookup app_name.csv queue_name output vendor, app_name 
     | search vendor = "Company" AND ticket_type = "Incident" AND app_name = "*" 
     | eval diff_seconds = now() - create_time_epoch 
     | eval diff_days = diff_seconds / 86400 
     | eval status = if (ticket_state="Closed" OR ticket_state="Completed" OR ticket_state="For Verification" OR ticket_state="Verified", "resolved" , "unresolved") 
     | where status = "unresolved" AND ticket_type = "Incident" 
     | eval SEVERITY = case ( SLA == "SLA Level 1", "1", SLA == "SLA Level 2", "2", SLA == "SLA Level 3", "3", SLA == "SLA Level 4", "4") 
     | eval SEVERITY = "Sev ".SEVERITY 
     | lookup sev_target.csv SEVERITY output TARGET 
     | eval SLA_DEADLINE = case(SEVERITY = "Sev 4", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 3", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 2", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 1", create_time_epoch + (TARGET*3600)) 

     | eval day_of_week= strftime(create_time_epoch, "%A")
     | eval sum= case(day_of_week=="Monday",0, (day_of_week=="Tuesday" OR day_of_week== "Sunday"), 86400, 1=1, 172800)
     | eval SLA_DEADLINE = if(SEVERITY = "Sev 4", SLA_DEADLINE + sum , SLA_DEADLINE)


     | eval SLA_DEADLINE = strftime(SLA_DEADLINE,"%Y-%m-%d %H:%M:%S") 
     | table *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 23:10:14 GMT</pubDate>
    <dc:creator>vishaltaneja070</dc:creator>
    <dc:date>2020-09-29T23:10:14Z</dc:date>
    <item>
      <title>How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453717#M128383</link>
      <description>&lt;P&gt;I am doing a support ticket with 4 levels of severity.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Level 1 expects the ticket to be resolved in 4 hours&lt;/LI&gt;
&lt;LI&gt;Level 2 expects the ticket to be resolved in 8 hours.&lt;/LI&gt;
&lt;LI&gt;Level 3 expects the ticket to be resolved in 72 hours aka 3 days.&lt;/LI&gt;
&lt;LI&gt;Level 4 expects the ticket to be resolved in 120 hours aka 5 days.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;I have the average response time, and the created time. But the response time includes weekends when calculating when the ticket is expected to be resolved.&lt;/P&gt;

&lt;P&gt;So when a ticket is raised on a &lt;STRONG&gt;Thursday&lt;/STRONG&gt; with &lt;STRONG&gt;level 4 severity&lt;/STRONG&gt;, it should be expected to be solved by &lt;STRONG&gt;Next Wednesday&lt;/STRONG&gt;. However, my code now included &lt;STRONG&gt;Saturday and Sunday&lt;/STRONG&gt; into the calculation, resulting it to be resolved by &lt;STRONG&gt;next Monday&lt;/STRONG&gt; instead.&lt;/P&gt;

&lt;P&gt;How do I exclude Saturday and Sunday out when calculating the expected time?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="test" sourcetype="incident_all_v3" 
    | eval check = strptime(strftime(_time , "%d/%m/%Y") , "%d/%m/%Y") 
    | eventstats max(check) as checktime 
    | where checktime = check 
    | dedup 1 ticket_id sortby -_time 
    | join ticket_id type=left 
        [ search index="test" sourcetype="incident_assigned" 
        | eval check = strptime(strftime(_time , "%d/%m/%Y") , "%d/%m/%Y") 
        | eventstats max(check) as checktime 
        | where checktime = check 
        | eval move_datetime = strptime(move_datetime, "%Y-%m-%d %H:%M:%S") 
        | dedup 1 ticket_id sortby -move_datetime 
        | eval move_datetime = strftime(move_datetime, "%Y-%m-%d %H:%M:%S") 
        | fields ticket_id move_datetime] 
    | eval realtime = if(isnotnull(move_datetime), move_datetime, create_time) 
    | eval create_time_epoch = strptime(realtime, "%Y-%m-%d %H:%M:%S") 
    | lookup app_name.csv queue_name output vendor, app_name 
    | search vendor = "Company" AND ticket_type = "Incident" AND app_name = "*" 
    | eval diff_seconds = now() - create_time_epoch 
    | eval diff_days = diff_seconds / 86400 
    | eval status = if (ticket_state="Closed" OR ticket_state="Completed" OR ticket_state="For Verification" OR ticket_state="Verified", "resolved" , "unresolved") 
    | where status = "unresolved" AND ticket_type = "Incident" 
    | eval SEVERITY = case ( SLA == "SLA Level 1", "1", SLA == "SLA Level 2", "2", SLA == "SLA Level 3", "3", SLA == "SLA Level 4", "4") 
    | eval SEVERITY = "Sev ".SEVERITY 
    | lookup sev_target.csv SEVERITY output TARGET 
    | eval SLA_DEADLINE = case(SEVERITY = "Sev 4", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 3", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 2", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 1", create_time_epoch + (TARGET*3600)) 
    | eval SLA_DEADLINE = strftime(SLA_DEADLINE,"%Y-%m-%d %H:%M:%S") 
    | table *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="SLA"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6509i9D44EF2B02413800/image-size/large?v=v2&amp;amp;px=999" role="button" title="SLA" alt="SLA" /&gt;&lt;/span&gt;&lt;BR /&gt;
So for this picture, on 2019-01-18(Friday), the Severity is level 4 and the Deadline is 2019-01-23, which is not what I wanted because it included Saturday and Sunday inside. It should be 2019-01-25 instead. &lt;/P&gt;

&lt;P&gt;This question took me days, and I still have not solved it yet. It would be great if someone could help me. The answers in the forum only filters out weekends, so if the ticket ends in a weekend, it will not show. This is not what i wanted.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 14:18:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453717#M128383</guid>
      <dc:creator>louisawang</dc:creator>
      <dc:date>2019-02-05T14:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453718#M128384</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/160303"&gt;@louisawang&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;I would suggest to create one more field based on create_time_epoch which will tell you the day of ticket and based on that do the changes like below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index="test" sourcetype="incident_all_v3" 
     | eval check = strptime(strftime(_time , "%d/%m/%Y") , "%d/%m/%Y") 
     | eventstats max(check) as checktime 
     | where checktime = check 
     | dedup 1 ticket_id sortby -_time 
     | join ticket_id type=left 
         [ search index="test" sourcetype="incident_assigned" 
         | eval check = strptime(strftime(_time , "%d/%m/%Y") , "%d/%m/%Y") 
         | eventstats max(check) as checktime 
         | where checktime = check 
         | eval move_datetime = strptime(move_datetime, "%Y-%m-%d %H:%M:%S") 
         | dedup 1 ticket_id sortby -move_datetime 
         | eval move_datetime = strftime(move_datetime, "%Y-%m-%d %H:%M:%S") 
         | fields ticket_id move_datetime] 
     | eval realtime = if(isnotnull(move_datetime), move_datetime, create_time) 
     | eval create_time_epoch = strptime(realtime, "%Y-%m-%d %H:%M:%S") 
     | lookup app_name.csv queue_name output vendor, app_name 
     | search vendor = "Company" AND ticket_type = "Incident" AND app_name = "*" 
     | eval diff_seconds = now() - create_time_epoch 
     | eval diff_days = diff_seconds / 86400 
     | eval status = if (ticket_state="Closed" OR ticket_state="Completed" OR ticket_state="For Verification" OR ticket_state="Verified", "resolved" , "unresolved") 
     | where status = "unresolved" AND ticket_type = "Incident" 
     | eval SEVERITY = case ( SLA == "SLA Level 1", "1", SLA == "SLA Level 2", "2", SLA == "SLA Level 3", "3", SLA == "SLA Level 4", "4") 
     | eval SEVERITY = "Sev ".SEVERITY 
     | lookup sev_target.csv SEVERITY output TARGET 
     | eval SLA_DEADLINE = case(SEVERITY = "Sev 4", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 3", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 2", create_time_epoch + (TARGET*3600), SEVERITY = "Sev 1", create_time_epoch + (TARGET*3600)) 

     | eval day_of_week= strftime(create_time_epoch, "%A")
     | eval sum= case(day_of_week=="Monday",0, (day_of_week=="Tuesday" OR day_of_week== "Sunday"), 86400, 1=1, 172800)
     | eval SLA_DEADLINE = if(SEVERITY = "Sev 4", SLA_DEADLINE + sum , SLA_DEADLINE)


     | eval SLA_DEADLINE = strftime(SLA_DEADLINE,"%Y-%m-%d %H:%M:%S") 
     | table *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:10:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453718#M128384</guid>
      <dc:creator>vishaltaneja070</dc:creator>
      <dc:date>2020-09-29T23:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453719#M128385</link>
      <description>&lt;P&gt;Hello, Thank you, it worked, partially. If the ticket is raised on a Monday, the SLA deadline is on a Saturday. How do i make it to be on Monday instead? So for a create_time of 28/1/2019, it ends at 2/2/2019, which is a Saturday. How do i skip the 2 weekends? For the rest of the days, it works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
And another question to add on to this, is it possible to make it to business hours as well? The business hours is 8am to 8pm ( 12 hours). so for SLA level 4, 120 hours actually means 10 days instead of 5 days.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 06:57:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453719#M128385</guid>
      <dc:creator>louisawang</dc:creator>
      <dc:date>2019-02-06T06:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453720#M128386</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/160303"&gt;@louisawang&lt;/a&gt; &lt;/P&gt;

&lt;P&gt;| eval sum= case(day_of_week=="Monday",0, (day_of_week=="Tuesday" OR day_of_week== "Sunday"), 86400, 1=1, 172800)  &lt;/P&gt;

&lt;P&gt;This is setting which is added. So For monday i have set not to change. Can you give me list,&lt;BR /&gt;
like Monday ----&amp;gt; SLA end ----&amp;gt; Sat&lt;/P&gt;

&lt;P&gt;I will change it accordingly. &lt;/P&gt;

&lt;P&gt;For SLA based on business hours, you can change it as well. The numbers 86400, 172800 is seconds, which you can change based on your requirement.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:10:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453720#M128386</guid>
      <dc:creator>vishaltaneja070</dc:creator>
      <dc:date>2020-09-29T23:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453721#M128387</link>
      <description>&lt;P&gt;Thank you for your help, so for a create_time of 28/1/2019, it ends at 2/2/2019, which is a Saturday.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 07:14:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453721#M128387</guid>
      <dc:creator>louisawang</dc:creator>
      <dc:date>2019-02-06T07:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453722#M128388</link>
      <description>&lt;P&gt;oh and for the Business hours, i will elaborate a bit more. Sometimes, a ticket is raised on a weekend, but the start date is a monday, 8am. For example, a ticket is raised on saturday 10am, the SLA timing should start from Monday 8am.&lt;BR /&gt;
Also, sometimes the ticket is raised outside of business hours(business hours is 8am to 8pm). Some tickets are raised at 9pm. So how do i start the SLA from next day 8am? Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 07:18:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453722#M128388</guid>
      <dc:creator>louisawang</dc:creator>
      <dc:date>2019-02-06T07:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453723#M128389</link>
      <description>&lt;P&gt;Try to use this then:&lt;BR /&gt;
    | eval sum= case( (day_of_week=="Tuesday" OR day_of_week== "Sunday"), 86400, 1=1, 172800) &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:10:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453723#M128389</guid>
      <dc:creator>vishaltaneja070</dc:creator>
      <dc:date>2020-09-29T23:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do you exclude weekends from the calculation of expected end time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453724#M128390</link>
      <description>&lt;P&gt;thank you! it works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
So for the rest of the SLA, i just have to add&lt;BR /&gt;
| eval SLA_DEADLINE = if(SEVERITY = "Sev 3", SLA_DEADLINE + sum , SLA_DEADLINE)&lt;BR /&gt;
| eval SLA_DEADLINE = if(SEVERITY = "Sev 2", SLA_DEADLINE + sum , SLA_DEADLINE)&lt;BR /&gt;&lt;BR /&gt;
| eval SLA_DEADLINE = if(SEVERITY = "Sev 1", SLA_DEADLINE + sum , SLA_DEADLINE) ?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:10:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-exclude-weekends-from-the-calculation-of-expected-end/m-p/453724#M128390</guid>
      <dc:creator>louisawang</dc:creator>
      <dc:date>2020-09-29T23:10:26Z</dc:date>
    </item>
  </channel>
</rss>

