<?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 organize a search with two lookup tables: common and event-specific? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487831#M136297</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;index=yourIndex sourcetype=yourEvents [|inputlookup Employees |where Holiday="N" AND Shift="1"| fields name | format]  
| eval date=strftime(_time,"%F")
| lookup Holiday holiday as date OUTPUT holiday
| where isnotnull(holiday)
| lookup Employees name OUTPUT DaysOfWeek as DOW DaysOfMonth as DOM Quota
| eval DaysOfWeek=tonumber(strftime(_time,"%w")) % 7, DaysOfMonth=tonumber(strftime(_time,"%d"))
| where NOT (match(split(DOW,","),DaysOfWeek) OR match(split(DOM,","),DaysOfMonth))
| eventstats sum(Quota) by name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I don't know the &lt;STRONG&gt;logs&lt;/STRONG&gt; , &lt;CODE&gt;e.units&lt;/CODE&gt; also.&lt;BR /&gt;
please add &lt;CODE&gt;where&lt;/CODE&gt; with comparison to &lt;CODE&gt;sum(Quota)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Splunk SPL(query) is made by looking the logs, not SPL/query.&lt;/P&gt;

&lt;P&gt;I don't know DB. the DB technician can make the SQL without looking data?&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2020 23:53:22 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-04-29T23:53:22Z</dc:date>
    <item>
      <title>How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487826#M136292</link>
      <description>&lt;P&gt;In my question I will use a manufacturing monitoring analogy.&lt;/P&gt;

&lt;P&gt;Employees (uniquely identified by name) work a certain shift.&lt;BR /&gt;&lt;BR /&gt;
Their names and each completed unit of work are recorded.&lt;BR /&gt;&lt;BR /&gt;
There are two shifts.&lt;/P&gt;

&lt;P&gt;While Splunk ingests every manufactured unit we are interested only in totals for a few particular employees on probation.&lt;/P&gt;

&lt;P&gt;Each employee has a predefined work schedule, but it's not the same for everyone. Each employee has their own quota that does not change often.&lt;/P&gt;

&lt;P&gt;We have two lookup tables: Employees and Holidays.&lt;/P&gt;

&lt;P&gt;"Holidays" lists all common days off for the majority of employees - 1 column with data like "2021-01-01".&lt;/P&gt;

&lt;P&gt;"Employees" provides details about work schedule and quotas.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Name    Shift Holidays DaysOfWeek  DaysOfMonth  Quota
John      1      Y        6,7                    100
Jim       2      N        6,7       15,16,17     3000
Nick      2      Y                               1000000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Our search will be scheduled to run twice a day at the end of each shift and needs to output probation employees that were scheduled to work and did meet their quota.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;We need to disregard all employees who are not in the table &lt;/LI&gt;
&lt;LI&gt;We need to filter just the current shift &lt;/LI&gt;
&lt;LI&gt;For employees that are not required to work on holidays, we need to exclude holidays&lt;/LI&gt;
&lt;LI&gt;For employees that have weekly days off, we need to exclude such days &lt;/LI&gt;
&lt;LI&gt;For employees that have monthly days off, we need to exclude them as well &lt;/LI&gt;
&lt;LI&gt;For the remaining, we need to compare their total to their quota&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;While I would not have a problem writing an SQL query for the above, I'm not sure about Splunk.&lt;BR /&gt;&lt;BR /&gt;
I'm also not certain if it's possible to match to comma-separated fields without "unpacking" them.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Apr 2020 19:54:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487826#M136292</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2020-04-27T19:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487827#M136293</link>
      <description>&lt;P&gt;see:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SQLtoSplunk"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SQLtoSplunk&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;and why don't you provide your SQL query?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Apr 2020 23:49:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487827#M136293</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-27T23:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487828#M136294</link>
      <description>&lt;P&gt;Something like below. Assuming there are DOW (single-digit)  and DOM (double-digit) functions.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SET @shift=1

SELECT emp.name, SUM(e.units) as Total, emp.quota
FROM Employees emp
JOIN Events evt ON emp.name=evt_name
LEFT JOIN Holidays h ON evt.date=h.date
WHERE emp.shift=@shift
  AND emp.dow IS NOT NULL AND emp.dow NOT LIKE '%'+DOW(e.date)+'%'
  AND emp.dom IS NOT NULL AND emp.dom NOT LIKE '%'+DOM(e.date)+'%'
GROUP BY emp.name  
HAVING SUM(e.units) &amp;lt; emp.quota
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Apr 2020 23:18:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487828#M136294</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2020-04-28T23:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487829#M136295</link>
      <description>&lt;P&gt;&lt;CODE&gt;e&lt;/CODE&gt; ? &lt;BR /&gt;
Which is "Holidays"  or "Employees" ?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;if it's possible to match to comma-separated fields without "unpacking" them.&lt;/CODE&gt;&lt;BR /&gt;
In splunk, It should be divided rows.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 23:36:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487829#M136295</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-28T23:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487830#M136296</link>
      <description>&lt;P&gt;Table included in my question is "Employees". &lt;/P&gt;

&lt;P&gt;"Holidays" is a single-column table with dates of holidays.&lt;/P&gt;

&lt;P&gt;"Events" is the main feed table with many-to-one relationship with "Employees".  It has two significant columns: Name and Units&lt;/P&gt;

&lt;P&gt;I also forgot to exclude holidays for employees that work through them.  So I need one more &lt;CODE&gt;WHERE&lt;/CODE&gt; condition:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;e.Holidays='N' OR h.date IS NOT NULL
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My "comma-separated"  fields  are in Employees table:  DaysOfWeek (DOW) and DaysOfMonth(DOM).&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 23:03:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487830#M136296</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2020-04-29T23:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487831#M136297</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=yourIndex sourcetype=yourEvents [|inputlookup Employees |where Holiday="N" AND Shift="1"| fields name | format]  
| eval date=strftime(_time,"%F")
| lookup Holiday holiday as date OUTPUT holiday
| where isnotnull(holiday)
| lookup Employees name OUTPUT DaysOfWeek as DOW DaysOfMonth as DOM Quota
| eval DaysOfWeek=tonumber(strftime(_time,"%w")) % 7, DaysOfMonth=tonumber(strftime(_time,"%d"))
| where NOT (match(split(DOW,","),DaysOfWeek) OR match(split(DOM,","),DaysOfMonth))
| eventstats sum(Quota) by name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I don't know the &lt;STRONG&gt;logs&lt;/STRONG&gt; , &lt;CODE&gt;e.units&lt;/CODE&gt; also.&lt;BR /&gt;
please add &lt;CODE&gt;where&lt;/CODE&gt; with comparison to &lt;CODE&gt;sum(Quota)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Splunk SPL(query) is made by looking the logs, not SPL/query.&lt;/P&gt;

&lt;P&gt;I don't know DB. the DB technician can make the SQL without looking data?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 23:53:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487831#M136297</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-29T23:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487832#M136298</link>
      <description>&lt;P&gt;Thank you very much.  &lt;/P&gt;

&lt;P&gt;My &lt;CODE&gt;Events&lt;/CODE&gt; table &lt;STRONG&gt;is&lt;/STRONG&gt; the data source (log).  It has "Name" and "Units"  (quantity of manufactured items) fields.  Total of "Units" is to be compared to "Quota" (so it's a post-aggregation filtering).&lt;/P&gt;

&lt;P&gt;I still have a question:  Why do we need &lt;CODE&gt;split()&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 14:20:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487832#M136298</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2020-04-30T14:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487833#M136299</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;DOW, DaysOfWeek
---,---------
15,21
16
21
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;DaysOfWeek&lt;/CODE&gt; is single value in a row.&lt;/P&gt;

&lt;P&gt;I see now, it's unnecessary. my habits.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 20:54:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487833#M136299</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-30T20:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487834#M136300</link>
      <description>&lt;P&gt;@to4kawa ,  Thank you very much for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 17:56:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487834#M136300</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2020-05-01T17:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to organize a search with two lookup tables: common and event-specific?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487835#M136301</link>
      <description>&lt;P&gt;you're welcome. try to present your final query.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 20:30:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-organize-a-search-with-two-lookup-tables-common-and-event/m-p/487835#M136301</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-05-01T20:30:53Z</dc:date>
    </item>
  </channel>
</rss>

