<?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 How to search for last 6 months for event indexed every month? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-last-6-months-for-event-indexed-every-month/m-p/560573#M159319</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a summary index which gets indexed once in a month. I have a query which runs based on current month looks back at last 6 months and provides me a report.&amp;nbsp; Is it possible to rewrite a query to show a trend which can go over each months' event and look back 6months of data for each month and provide a report?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the query which looks back at last 6 months from current month. I would like to do the same for all months (look back from each month) and provide a trend&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=summary source=sre_slo_BE_qlatency_permodule_monthly 
| where _time&amp;gt;=relative_time(now(),"-6mon@mon")
| eval Month=Month + "-" + Year
| chart values(p90Latency) as P90Latency by  Month, Module useother=f limit=10000 
| eval MonthYear=Month, Year=substr(Month,5,4), Month=substr(Month,0,3) 
| fields - Year 
| table MonthYear * 
| transpose 20 header_field=MonthYear, column_name=Module
| foreach *20*
     [ eval Max=case(Max&amp;gt;=if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),0,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),Max,true(),if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),0,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))]
| where Max&amp;gt;30000
| foreach *20*
    [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=ROUND(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')/1000,2)]
| fields - Max
| rename Module as MainModule 
| eval RequestType="Business Event"
| lookup SLOHighToleranceLookup RequestType OUTPUTNEW Module | eval Module=if(isnull(Module), "null", Module) 
| where MainModule != Module
| fields - Module, RequestType
| rename MainModule as Module
| eval ViolationCount=0, LastViolatedMonth="", LastViolatedResponse=0, TotalViolationCount=0
| foreach *-2020 or *-2021
[ | eval LastViolatedMonth = if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;30,"&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", LastViolatedMonth)
       , LastViolatedMonthNumber = substr(LastViolatedMonth, 0, 2)
       , ViolationCount=if(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;30), ViolationCount+1, ViolationCount)
       , LastViolatedResponse=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;30,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', LastViolatedResponse)
       , Deviation=case(LastViolatedResponse&amp;gt;30,round(((LastViolatedResponse-30)/30)*100,1))
       , Priority = case(
                        (Deviation &amp;gt;= 100 AND ViolationCount &amp;gt;=1), "P1"
                      , ((Deviation &amp;gt;= 75 AND Deviation &amp;lt; 100) AND ViolationCount &amp;gt;=3), "P1"
                      , ((Deviation &amp;gt;= 75 AND Deviation &amp;lt; 100) AND (ViolationCount &amp;gt;= 0 AND ViolationCount &amp;lt; 3)), "P2" 
                      , ((Deviation &amp;gt;= 50 AND Deviation &amp;lt; 75) AND ViolationCount &amp;gt;= 3), "P2"
                      , ((Deviation &amp;gt;= 50 AND Deviation &amp;lt; 75) AND (ViolationCount &amp;gt;= 0 AND ViolationCount &amp;lt; 3)), "P3"
                      , ((Deviation &amp;gt;= 25 AND Deviation &amp;lt; 50) AND ViolationCount &amp;gt;= 3), "P3"
                      , ((Deviation &amp;gt;= 25 AND Deviation &amp;lt; 50) AND (ViolationCount &amp;gt;= 1 AND ViolationCount &amp;lt; 3)), "P4"
                      , ((Deviation &amp;gt; 0 AND Deviation &amp;lt; 25) AND ViolationCount &amp;gt;= 0), "P4"
                      )]
| eval LastViolatedMonthNumber = substr(LastViolatedMonth, 0, 2)
     , LastViolatedMonthYear = substr(LastViolatedMonth, 4, 4)
| eval LastViolatedMonth = case(LastViolatedMonthNumber==01, "Jan", LastViolatedMonthNumber==02, "Feb", LastViolatedMonthNumber==3, "Mar", LastViolatedMonthNumber==4, "Apr", LastViolatedMonthNumber==5, "May", LastViolatedMonthNumber==6, "Jun", LastViolatedMonthNumber==7, "Jul", LastViolatedMonthNumber==8, "Aug", LastViolatedMonthNumber==9, "Sep", LastViolatedMonthNumber==10, "Oct", LastViolatedMonthNumber==11, "Nov", LastViolatedMonthNumber==12, "Dec")  
| eval LastViolatedMonth=LastViolatedMonth + "-" + LastViolatedMonthYear
| fields Module, LastViolatedMonth, LastViolatedResponse, ViolationCount, Deviation, Priority, LastViolatedMonthNumber, LastViolatedMonthYear
| sort - LastViolatedResponse
| rename LastViolatedMonth as "Last Violation Month", LastViolatedResponse as "Last Violation p90ResponseTime (s)", Deviation as "Deviation (%)", ViolationCount as "Missed Count"
| eval CurrentMonth = strftime(now(), "%m"), CurrentYear= strftime(now(), "%Y"), ViolationMonthDifference=if(CurrentYear&amp;gt;LastViolatedMonthYear, (12-LastViolatedMonthNumber)+CurrentMonth, CurrentMonth-LastViolatedMonthNumber)
| where ViolationMonthDifference&amp;lt;=3
| eval Priority = if(Priority=="P1" AND LastViolatedMonthNumber != CurrentMonth-1 , "P2", Priority)
| fields - LastViolatedMonthNumber, LastViolatedMonthYear, CurrentMonth, CurrentYear, ViolationMonthDifference&lt;/LI-CODE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jul 2021 08:15:54 GMT</pubDate>
    <dc:creator>sangs8788</dc:creator>
    <dc:date>2021-07-23T08:15:54Z</dc:date>
    <item>
      <title>How to search for last 6 months for event indexed every month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-last-6-months-for-event-indexed-every-month/m-p/560573#M159319</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a summary index which gets indexed once in a month. I have a query which runs based on current month looks back at last 6 months and provides me a report.&amp;nbsp; Is it possible to rewrite a query to show a trend which can go over each months' event and look back 6months of data for each month and provide a report?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the query which looks back at last 6 months from current month. I would like to do the same for all months (look back from each month) and provide a trend&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=summary source=sre_slo_BE_qlatency_permodule_monthly 
| where _time&amp;gt;=relative_time(now(),"-6mon@mon")
| eval Month=Month + "-" + Year
| chart values(p90Latency) as P90Latency by  Month, Module useother=f limit=10000 
| eval MonthYear=Month, Year=substr(Month,5,4), Month=substr(Month,0,3) 
| fields - Year 
| table MonthYear * 
| transpose 20 header_field=MonthYear, column_name=Module
| foreach *20*
     [ eval Max=case(Max&amp;gt;=if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),0,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),Max,true(),if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),0,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))]
| where Max&amp;gt;30000
| foreach *20*
    [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=ROUND(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')/1000,2)]
| fields - Max
| rename Module as MainModule 
| eval RequestType="Business Event"
| lookup SLOHighToleranceLookup RequestType OUTPUTNEW Module | eval Module=if(isnull(Module), "null", Module) 
| where MainModule != Module
| fields - Module, RequestType
| rename MainModule as Module
| eval ViolationCount=0, LastViolatedMonth="", LastViolatedResponse=0, TotalViolationCount=0
| foreach *-2020 or *-2021
[ | eval LastViolatedMonth = if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;30,"&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", LastViolatedMonth)
       , LastViolatedMonthNumber = substr(LastViolatedMonth, 0, 2)
       , ViolationCount=if(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;30), ViolationCount+1, ViolationCount)
       , LastViolatedResponse=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;30,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', LastViolatedResponse)
       , Deviation=case(LastViolatedResponse&amp;gt;30,round(((LastViolatedResponse-30)/30)*100,1))
       , Priority = case(
                        (Deviation &amp;gt;= 100 AND ViolationCount &amp;gt;=1), "P1"
                      , ((Deviation &amp;gt;= 75 AND Deviation &amp;lt; 100) AND ViolationCount &amp;gt;=3), "P1"
                      , ((Deviation &amp;gt;= 75 AND Deviation &amp;lt; 100) AND (ViolationCount &amp;gt;= 0 AND ViolationCount &amp;lt; 3)), "P2" 
                      , ((Deviation &amp;gt;= 50 AND Deviation &amp;lt; 75) AND ViolationCount &amp;gt;= 3), "P2"
                      , ((Deviation &amp;gt;= 50 AND Deviation &amp;lt; 75) AND (ViolationCount &amp;gt;= 0 AND ViolationCount &amp;lt; 3)), "P3"
                      , ((Deviation &amp;gt;= 25 AND Deviation &amp;lt; 50) AND ViolationCount &amp;gt;= 3), "P3"
                      , ((Deviation &amp;gt;= 25 AND Deviation &amp;lt; 50) AND (ViolationCount &amp;gt;= 1 AND ViolationCount &amp;lt; 3)), "P4"
                      , ((Deviation &amp;gt; 0 AND Deviation &amp;lt; 25) AND ViolationCount &amp;gt;= 0), "P4"
                      )]
| eval LastViolatedMonthNumber = substr(LastViolatedMonth, 0, 2)
     , LastViolatedMonthYear = substr(LastViolatedMonth, 4, 4)
| eval LastViolatedMonth = case(LastViolatedMonthNumber==01, "Jan", LastViolatedMonthNumber==02, "Feb", LastViolatedMonthNumber==3, "Mar", LastViolatedMonthNumber==4, "Apr", LastViolatedMonthNumber==5, "May", LastViolatedMonthNumber==6, "Jun", LastViolatedMonthNumber==7, "Jul", LastViolatedMonthNumber==8, "Aug", LastViolatedMonthNumber==9, "Sep", LastViolatedMonthNumber==10, "Oct", LastViolatedMonthNumber==11, "Nov", LastViolatedMonthNumber==12, "Dec")  
| eval LastViolatedMonth=LastViolatedMonth + "-" + LastViolatedMonthYear
| fields Module, LastViolatedMonth, LastViolatedResponse, ViolationCount, Deviation, Priority, LastViolatedMonthNumber, LastViolatedMonthYear
| sort - LastViolatedResponse
| rename LastViolatedMonth as "Last Violation Month", LastViolatedResponse as "Last Violation p90ResponseTime (s)", Deviation as "Deviation (%)", ViolationCount as "Missed Count"
| eval CurrentMonth = strftime(now(), "%m"), CurrentYear= strftime(now(), "%Y"), ViolationMonthDifference=if(CurrentYear&amp;gt;LastViolatedMonthYear, (12-LastViolatedMonthNumber)+CurrentMonth, CurrentMonth-LastViolatedMonthNumber)
| where ViolationMonthDifference&amp;lt;=3
| eval Priority = if(Priority=="P1" AND LastViolatedMonthNumber != CurrentMonth-1 , "P2", Priority)
| fields - LastViolatedMonthNumber, LastViolatedMonthYear, CurrentMonth, CurrentYear, ViolationMonthDifference&lt;/LI-CODE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 08:15:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-last-6-months-for-event-indexed-every-month/m-p/560573#M159319</guid>
      <dc:creator>sangs8788</dc:creator>
      <dc:date>2021-07-23T08:15:54Z</dc:date>
    </item>
  </channel>
</rss>

