<?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 determine whether a saved search was run on its cron schedule, or not? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435745#M7597</link>
    <description>&lt;P&gt;Sounds like you need an isolated development environment or more strict control of your users/roles.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Apr 2019 19:22:33 GMT</pubDate>
    <dc:creator>codebuilder</dc:creator>
    <dc:date>2019-04-30T19:22:33Z</dc:date>
    <item>
      <title>How to determine whether a saved search was run on its cron schedule, or not?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435742#M7594</link>
      <description>&lt;P&gt;In a report I'm building, I'm using the &lt;CODE&gt;| map&lt;/CODE&gt; command to send emails to many recipients, each with their own custom view of data. A problem I've run into while editing the search is, I do not want to accidentally send many erroneous reports via email if I run the search while testing/editing, or even accidentally opening the search. I've come up with a rough solution, but, am wondering if someone has a better idea. &lt;/P&gt;

&lt;P&gt;Basically I've created a macro that:&lt;BR /&gt;
1) uses &lt;CODE&gt;| rest&lt;/CODE&gt; to check the cron the search is scheduled for,&lt;BR /&gt;
2) guesses at the epoch time &lt;CODE&gt;cron_guess&lt;/CODE&gt; the search would have run at today (this logic breaks if the cron doesn't follow MM HH * * * format, e.g. 0,15,30,45 12 * * * breaks my logic)&lt;BR /&gt;
3) checks to see if &lt;CODE&gt;cron_guess&lt;/CODE&gt; = &lt;CODE&gt;now()&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;After that, I use &lt;CODE&gt;ranOnCron&lt;/CODE&gt;=1 to set the real email addresses, or &lt;CODE&gt;ranOnCron&lt;/CODE&gt;=0 to set email addresses to my test account, preventing any "true" emails from going out.&lt;/P&gt;

&lt;P&gt;This works for my purposes, but, I'd love a more robust solution if anyone knows of something. Accidentally sending hundreds of emails to hundreds of people with garbage data isn't fun.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ranOnCron(3)]
args = NS_user, NS_app, saved_search
definition = eval ranOnCron=
    [| rest splunk_server=local /servicesNS/$NS_user$/$NS_app$/saved/searches
    | search title="$saved_search$"
    | rex field=cron_schedule "^(?&amp;lt;cron_min&amp;gt;\d+)\s+(?&amp;lt;cron_hour&amp;gt;\d+)\s+"
    | eval cron_guess=floor(relative_time(now(), "@d"))+tonumber(cron_min)*60+tonumber(cron_hour)*60*60
    | eval runOnCron_sec_min_hour=if(cron_guess==now(), 1, 0)
    | return $runOnCron_sec_min_hour]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Apr 2019 18:47:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435742#M7594</guid>
      <dc:creator>adamsmith47</dc:creator>
      <dc:date>2019-04-30T18:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether a saved search was run on its cron schedule, or not?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435743#M7595</link>
      <description>&lt;P&gt;Why not just clone your report, disable notifications, and use that as your working copy.&lt;BR /&gt;
Then after validation, move your changes up to the published version.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 18:56:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435743#M7595</guid>
      <dc:creator>codebuilder</dc:creator>
      <dc:date>2019-04-30T18:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether a saved search was run on its cron schedule, or not?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435744#M7596</link>
      <description>&lt;P&gt;That doesn't prevent accidents. I suppose accidents are always possible, but I'm sure you can see it'd be very easy for someone to OPEN the search, instead of click Edit to clone it... sending out hundreds of unexpected emails. Or one power user clicks on a saved search another power user created, sending out hundreds of unexpected emails.&lt;/P&gt;

&lt;P&gt;I'm looking for a technical solution to reduce extremely visible errors, in addition to trying to be careful.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 19:04:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435744#M7596</guid>
      <dc:creator>adamsmith47</dc:creator>
      <dc:date>2019-04-30T19:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether a saved search was run on its cron schedule, or not?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435745#M7597</link>
      <description>&lt;P&gt;Sounds like you need an isolated development environment or more strict control of your users/roles.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 19:22:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435745#M7597</guid>
      <dc:creator>codebuilder</dc:creator>
      <dc:date>2019-04-30T19:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether a saved search was run on its cron schedule, or not?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435746#M7598</link>
      <description>&lt;P&gt;Yeah, life sucks.&lt;/P&gt;

&lt;P&gt;Anything else?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 19:33:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435746#M7598</guid>
      <dc:creator>adamsmith47</dc:creator>
      <dc:date>2019-04-30T19:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether a saved search was run on its cron schedule, or not?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435747#M7599</link>
      <description>&lt;P&gt;Just re-reading my post, and to clarify what I have in mind, I'm looking for probably a &lt;CODE&gt;| rest&lt;/CODE&gt; command and logic to determine whether the search was run by the scheduler, or if it were run manually.&lt;/P&gt;

&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 13:33:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-determine-whether-a-saved-search-was-run-on-its-cron/m-p/435747#M7599</guid>
      <dc:creator>adamsmith47</dc:creator>
      <dc:date>2019-05-03T13:33:47Z</dc:date>
    </item>
  </channel>
</rss>

