<?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: Looping emails for multiple events in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131171#M2952</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;so my final command will look like this :-&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=main sourcetype="DBMONCustom*"| table TablespaceName| join type=inner [| inputlookup hostlookup] | dedup TablespaceName | table *| head 5&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This is printing the outcome :-&lt;/P&gt;

&lt;P&gt;TablespaceName      emailto      hostname&lt;BR /&gt;
abc                   &lt;A href="mailto:a@a.com"&gt;a@a.com&lt;/A&gt;          aaa&lt;BR /&gt;
ddd                   &lt;A href="mailto:d@f.com"&gt;d@f.com&lt;/A&gt;         eee&lt;/P&gt;

&lt;P&gt;Now I changed the command like this (please see next comment as I am hitting the word limit)&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jan 2014 02:44:05 GMT</pubDate>
    <dc:creator>ramanjain1983</dc:creator>
    <dc:date>2014-01-31T02:44:05Z</dc:date>
    <item>
      <title>Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131167#M2948</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;I have created a query which returns something like this :-&lt;/P&gt;

&lt;P&gt;OrderNo          CreatedBy          OrderError&lt;/P&gt;

&lt;P&gt;0001               Alice               Faulty&lt;/P&gt;

&lt;P&gt;2222               Prince              None&lt;/P&gt;

&lt;P&gt;..............................................&lt;/P&gt;

&lt;P&gt;..............................................&lt;/P&gt;

&lt;P&gt;9999               Text               Wrong Capture&lt;/P&gt;

&lt;P&gt;The query will return me number of records in above fashion in case of errors only. It means if there are not any error then results will be ZERO.&lt;/P&gt;

&lt;P&gt;Now what I want to do is that if there are errors which could be single entry or multiple entries like as shown above then I would like to send an email to respective users whose names are given in field =CreatedBy. Also I need to do a lookup for email ID for that respective user.&lt;/P&gt;

&lt;P&gt;Can anyone suggest some possible approach for this.&lt;/P&gt;

&lt;P&gt;I was thinking that if I will have a ldap python script which will take CreatedBy field as argument and then will return an outfield = EMAILID then I would like to call sendemail command to send the result. But here the challenge is that the query may return multiple entries so in that case I am not sure how splunk will treat it.&lt;/P&gt;

&lt;P&gt;let's say the query is :-&lt;/P&gt;

&lt;P&gt;Primary search [secondary search | fields OrderNo] | fields OrderNo CreatedBy OrderError | someExternalPythonLDAPLookupCommand outfield=emailid "$CreatedBY" | sendemail To="$emaildid" server="" from="&lt;A href="mailto:a@a.com"&gt;a@a.com&lt;/A&gt;"&lt;/P&gt;

&lt;P&gt;If I use the above concept , will it solve my requirement. I doubt what will happen if the outcome  is a multi value table.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2014 13:33:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131167#M2948</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-01-30T13:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131168#M2949</link>
      <description>&lt;P&gt;I would use a scripted alert to do this. Write the search, leaving out the external command. You can set the alert so that it triggers the script once for each result, or once for all results.&lt;/P&gt;

&lt;P&gt;The script will have access to the results in a temporary file. And of course, you can write whatever you like in a script!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2014 18:07:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131168#M2949</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-01-30T18:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131169#M2950</link>
      <description>&lt;P&gt;Writing a scripted alert will certainly work well, and will allow you to send more customized emails.&lt;BR /&gt;
If however you want to avoid that for whatever reason, here's a pointer on how to make Splunk send one email per result row using an address from that very row:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search creating the table you posted | some way of adding the email address to each row into field email | map maxsearches=0 search="stats count | eval OrderError=$OrderError$ | fields - count | sendemail server=yourserver to=$email$ subject=\"Faulty order $OrderNo$\" sendresults=true"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That map will run its search once per result row, sending an email to the address from the result with the OrderNo in the subject and OrderError in the body.&lt;BR /&gt;
If the users are also Splunk users you can use Splunk to retrieve the email addresses from their Splunk account, avoiding the external ldap lookup thingy...&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2014 21:18:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131169#M2950</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-30T21:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131170#M2951</link>
      <description>&lt;P&gt;Awesome , let me give it a shot and I will post back my response.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2014 21:21:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131170#M2951</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-01-30T21:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131171#M2952</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;so my final command will look like this :-&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=main sourcetype="DBMONCustom*"| table TablespaceName| join type=inner [| inputlookup hostlookup] | dedup TablespaceName | table *| head 5&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This is printing the outcome :-&lt;/P&gt;

&lt;P&gt;TablespaceName      emailto      hostname&lt;BR /&gt;
abc                   &lt;A href="mailto:a@a.com"&gt;a@a.com&lt;/A&gt;          aaa&lt;BR /&gt;
ddd                   &lt;A href="mailto:d@f.com"&gt;d@f.com&lt;/A&gt;         eee&lt;/P&gt;

&lt;P&gt;Now I changed the command like this (please see next comment as I am hitting the word limit)&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 02:44:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131171#M2952</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-01-31T02:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131172#M2953</link>
      <description>&lt;P&gt;&lt;CODE&gt;index=main sourcetype="DBMONCustom*"| table TablespaceName| join type=inner [| inputlookup hostlookup] | dedup TablespaceName | table *| head 5 | map maxsearches=10 search="stats count"| eval TablespaceName=$TablespaceName$ | fields - count | sendemail server=test@test.com from=test@test.com to=$emailto$ subject=$TablespaceName$ sendresults=true&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;but it is returning me this error :- &lt;BR /&gt;
&lt;CODE&gt;command="sendemail", {'$emailto$': (501, "#5.1.3 Partial domain not allowed: ''")} while sending mail to: $emailto&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 02:44:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131172#M2953</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-01-31T02:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131173#M2954</link>
      <description>&lt;P&gt;Am i doing it rightly ....or any other solution please.&lt;/P&gt;

&lt;P&gt;I need to send an email to all people in field 'emailto' in above table with subject line having TablespaceName respectively.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 02:44:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131173#M2954</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-01-31T02:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131174#M2955</link>
      <description>&lt;P&gt;If there are errors, chances are low that you're doing things correctly.&lt;/P&gt;

&lt;P&gt;I see a closing quotation mark after two words of map's search, that can't be right. The quoted string should end after the end of the sendemail command, otherwise the $foo$ token replacement of map will not work back there.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 08:32:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131174#M2955</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-31T08:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131175#M2956</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype="DBMONCustom*"
| join type=inner [ | inputlookup hostlookup] 
| dedup TablespaceName 
| table * | head 5 
| map maxsearches=0 search="stats count 
| eval TablespaceName=$TablespaceName$ 
| fields - count 
| sendemail server=test@test.com from=test@test.com to=$emailto$ subject=$TablespaceName$ sendresults=true"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is what I think you will have after combining @martin_meuller's advice with your original search. I removed the first &lt;CODE&gt;table&lt;/CODE&gt; command, as it was doing nothing. Why are you using &lt;CODE&gt;inputlookup&lt;/CODE&gt;? Are you getting a bunch of fields from the lookup table?&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 23:18:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131175#M2956</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-01-31T23:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131176#M2957</link>
      <description>&lt;P&gt;The combination of &lt;CODE&gt;join&lt;/CODE&gt; and &lt;CODE&gt;inputlookup&lt;/CODE&gt; feels to me as if it'd be equivalent to a regular &lt;CODE&gt;lookup&lt;/CODE&gt; while filtering for only events that actually had something look up.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2014 23:39:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131176#M2957</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-31T23:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131177#M2958</link>
      <description>&lt;P&gt;Thanks Martin and Lguinn for all the responses on it. Seems like this map command is really a good weapon for lot of other things. It is working for me.....I just need to change the maxsearches to repeat the number of loop which is count of total events.&lt;/P&gt;

&lt;P&gt;The only challenge is that the results sent inside the mail does not have anything. Ideally the line should be printed. I need to send one field in that and I am not sure if you can send custom text or body in the email. Any idea on that please...&lt;/P&gt;</description>
      <pubDate>Sat, 01 Feb 2014 05:20:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131177#M2958</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-02-01T05:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131178#M2959</link>
      <description>&lt;P&gt;The searches launched by &lt;CODE&gt;map&lt;/CODE&gt; don't know anything about the outer search. In order to copy over data from the row of the outer search responsible for launching a &lt;CODE&gt;map&lt;/CODE&gt; search, you need to use $foo$ tokens. For an example, see Lisa's search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| eval TablespaceName=$TablespaceName$ 
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That creates a field which should appear in the inline results table of the email.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Feb 2014 10:10:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131178#M2959</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-02-01T10:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131179#M2960</link>
      <description>&lt;P&gt;I tried that way but the problem is actually with the arguments passed inside the sendemail python script. I changed the script a bit to pass custom argument in body and everything is so smooth now....&lt;/P&gt;

&lt;P&gt;Thanks a lot Martin and Lguinn for your advise on this question. Kudos!!!&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2014 11:58:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131179#M2960</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-02-02T11:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131180#M2961</link>
      <description>&lt;P&gt;CLOSED AND KUDOS TO MARTIN AND LGUINN!&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2014 11:59:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131180#M2961</guid>
      <dc:creator>ramanjain1983</dc:creator>
      <dc:date>2014-02-02T11:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131181#M2962</link>
      <description>&lt;P&gt;In order to mark an answer as accepted, press the checkmark next to that answer.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2014 17:17:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/131181#M2962</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-02-02T17:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/550614#M9067</link>
      <description>&lt;P&gt;hi Martin, i am using map along with the sendemail, but Spluk gives me a authentication error like below. but it works fine if I only use sendemail, some blog said the subsearch lost the session, do you have any idea to fix this? or which version you are running on? i am on 8.0.1&lt;/P&gt;&lt;LI-CODE lang="python"&gt;endemail:1454 - [HTTP 403] Client is not authorized to perform requested action; 
File "/opt/splunk/etc/apps/search/bin/sendemail.py", line 1447, in &amp;lt;module&amp;gt;
    results = sendEmail(results, settings, keywords, argvals)
  File "/opt/splunk/etc/apps/search/bin/sendemail.py", line 403, in sendEmail
    jobResponseHeaders, jobResponseBody = simpleRequest(uriToJob, method='GET', getargs={'output_mode':'json'}, sessionKey=sessionKey)
  File "/opt/splunk/lib/python2.7/site-packages/splunk/rest/__init__.py", line 559, in simpleRequest
    raise splunk.AuthorizationFailed(extendedMessages=uri)
AuthorizationFailed: [HTTP 403] Client is not authorized to perform requested action; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 08:33:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/550614#M9067</guid>
      <dc:creator>wangjianiu</dc:creator>
      <dc:date>2021-05-06T08:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Looping emails for multiple events</title>
      <link>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/605601#M11541</link>
      <description>&lt;P&gt;This sendmail command worked for me.&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;| rest timeout=600 splunk_server=local /servicesNS/-/-/saved/searches add_orphan_field=yes count=0&lt;BR /&gt;| search orphan=1 disabled=0 is_scheduled=1 title IN ("Missed_workfusion","Failed Intake Document")&lt;BR /&gt;| eval status = if(disabled = 0, "enabled", "disabled")&lt;BR /&gt;| fields title eai:acl.owner eai:acl.app eai:acl.sharing orphan status is_scheduled cron_schedule next_scheduled_time next_scheduled_time actions "action.email.to"&lt;BR /&gt;| rename title AS "search_name" eai:acl.owner AS owner eai:acl.app AS app eai:acl.sharing AS sharing "action.email.to" as Email_Address&lt;BR /&gt;| map search="| makeresults search_name owner&lt;BR /&gt;| sendemail&lt;BR /&gt;to=\"$Email_Address$\"&lt;BR /&gt;cc="abc@xyz.com;123@yahoo.com"&lt;BR /&gt;subject=\"Orphaned Searches/Reports/Alerts to be reviewed and reowned\"&lt;BR /&gt;message=\"Below Searches/Reports/Alerts in Splunk were orphaned. \n&lt;BR /&gt;Please take necessary action in changing the ownership from retired owners to new owners in getting the reports functional otherwise these reports would be disabled by SPLUNK Team after 15 days since the first trigger\n.&lt;BR /&gt;SEARCH NAME : \\\"$search_name$\\\" \n&lt;BR /&gt;OWNER OF THE SEARCH : \\\"$owner$\\\" \n&lt;BR /&gt;APPLICATION : \\\"$app$\\\" \n&lt;BR /&gt;STATUS : \\\"$status$\\\" \n&lt;BR /&gt;CRON SCHEDULE OF SEARCH: \\\$cron_schedule$\\\ \n&lt;BR /&gt;EMAIL ADDRESS OF SEARCH: \\\"$Email_Address$\\\" \n&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards \n&lt;BR /&gt;SPLUNK Team&lt;BR /&gt;\""&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 14:27:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Looping-emails-for-multiple-events/m-p/605601#M11541</guid>
      <dc:creator>splunkhu123</dc:creator>
      <dc:date>2022-07-14T14:27:09Z</dc:date>
    </item>
  </channel>
</rss>

