<?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: Powershell script triggered from alert is not executing but I can see it triggered in python.log in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150393#M30575</link>
    <description>&lt;P&gt;:hangs head in shame: The script was actually writing to &lt;CODE&gt;$splunk_home\bin&lt;/CODE&gt;, not to &lt;CODE&gt;$splunk_home\bin\scripts&lt;/CODE&gt; where the script was actually located. I found a bunch of text files from my testing in bin &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I had tested a hard path earlier, but I think I had other unresolved issues as well at that point so I errantly dismissed that as a solution.&lt;/P&gt;

&lt;P&gt;Failure in basic troubleshooting I'm afraid &lt;span class="lia-unicode-emoji" title=":neutral_face:"&gt;😐&lt;/span&gt; I will blame it on a lack of sleep.&lt;/P&gt;

&lt;P&gt;Thank you for your help! If you post it has an answer I can accept it.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Oct 2014 15:57:14 GMT</pubDate>
    <dc:creator>neiljpeterson</dc:creator>
    <dc:date>2014-10-03T15:57:14Z</dc:date>
    <item>
      <title>Powershell script triggered from alert is not executing but I can see it triggered in python.log</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150391#M30573</link>
      <description>&lt;P&gt;My forehead is sore from banging it on my desk. Please help.&lt;/P&gt;

&lt;P&gt;I cannot get scripts to run from an alert. The following is all the relevant info I have been using to trouble shoot this.&lt;/P&gt;

&lt;H4&gt;Implementation&lt;/H4&gt;

&lt;P&gt;To make it easy, I configured the alert to run "always" so the search term is irrelevant. The alert should be triggered every minute regardless. (I have also ran this with a search that I was manually triggering events in)&lt;/P&gt;

&lt;P&gt;The powershell script&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
"hello world" | Out-File -FilePath .\hello_ps.txt
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;savedsearches.conf&lt;/CODE&gt; stanzas&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script_test_ps]
action.script = 1
action.script.filename = test.ps1
alert.digest_mode = True
alert.suppress = 0
alert.track = 0
auto_summarize.dispatch.earliest_time = -1d@h
cron_schedule = * * * * *
enableSched = 1
search = sourcetype=nothing
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H4&gt;Verification&lt;/H4&gt;

&lt;P&gt;We know the search is running, we can see the search run and we can watch the script being called but it never actually executes.&lt;/P&gt;

&lt;P&gt;From &lt;CODE&gt;python.log&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2014-10-02 18:19:03,171 Central Daylight Time INFO  runshellscript:188 - runshellscript: ['C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', 'D:\\Splunk\\bin\\scripts\\test.ps1', '0', 'index=testing sourcetype=script_test', 'index=testing sourcetype=script_test', 'script_test_ps', 'Saved Search [script_test_ps] always(0)', 'https://splunkweb.domain.tld/app/search/@go?sid=scheduler_bmVpbC5wZXRlcnNvbg__search__RMD59d824a49b6b738b2_at_1412291940_27935', '', 'D:\\Splunk\\var\\run\\splunk\\dispatch\\scheduler_bmVpbC5wZXRlcnNvbg__search__RMD59d824a49b6b738b2_at_1412291940_27935\\results.csv.gz']
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;From &lt;CODE&gt;scheduler.log&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;10-02-2014 18:19:03.889 -0500 INFO  SavedSplunker - savedsearch_id="neil.peterson;search;script_test_ps", user="neil.peterson", app="search", savedsearch_name="script_test_ps", status=success, digest_mode=1, scheduled_time=1412291940, dispatch_time=1412291942, run_time=0.562, result_count=0, alert_actions="script", sid="scheduler_bmVpbC5wZXRlcnNvbg__search__RMD59d824a49b6b738b2_at_1412291940_27935", suppressed=0, thread_id="AlertNotifierWorker-1"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H4&gt;Troubleshooting&lt;/H4&gt;

&lt;P&gt;Powershell execution policy is unrestricted&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;PS D:\Splunk\bin\scripts&amp;gt; Get-ExecutionPolicy
Unrestricted
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunkd is running as a service account&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;PS D:\Splunk\bin\scripts&amp;gt; Get-WmiObject win32_service | Where-Object {$_.name -like "splunk*"} | Select-Object name, startname

name                                                        startname
----                                                        ---------
Splunkd                                                     domain\svc.splunk
splunkweb                                                   domain\svc.splunk
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The service account is in the Administrators groups&lt;/P&gt;

&lt;P&gt;The troubleshooting steps from this wiki article: &lt;A href="http://wiki.splunk.com/Community:TroubleshootingAlertScripts"&gt;http://wiki.splunk.com/Community:TroubleshootingAlertScripts&lt;/A&gt;&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;&lt;P&gt;Is my scheduled search running? YES. I see it in scheduler.log&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Is my scheduled search generating the expected results? YES. I can watch the results come in on a real time search. I have also scheduled the alert to run "always" to make the search part of it irrelevant. &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Is my alert action being triggered? YES. I have added email actions and I get those emails, as well as watching it in &lt;CODE&gt;&lt;A href="https://splunkweb.domain.tld/en-US/app/launcher/job_management?savedSearch=script_test" target="test_blank"&gt;https://splunkweb.domain.tld/en-US/app/launcher/job_management?savedSearch=script_test&lt;/A&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Is my alert script working? YES. I can run it from the command line, as the svc.splunk user, but when the alert triggers it, nothing happens.&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;H4&gt;Reference&lt;/H4&gt;

&lt;P&gt;I have been using the following documentation. I have read it and reread it.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/alert/ConfiguringScriptedAlerts"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/alert/ConfiguringScriptedAlerts&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/Alert/Setupalertactions#Run_a_script"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/Alert/Setupalertactions#Run_a_script&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/Admin/Savedsearchesconf"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/Admin/Savedsearchesconf&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://wiki.splunk.com/Community:TroubleshootingAlertScripts"&gt;http://wiki.splunk.com/Community:TroubleshootingAlertScripts&lt;/A&gt;&lt;/P&gt;

&lt;H4&gt;I am out of rope on this one. Any help is appreciated. I have also done all of the above with a batch script as well with the same disappointing results.&lt;/H4&gt;

&lt;P&gt;I have been testing and troubleshooting this from lots of different angles. I tried to break everything down to the simplest example, but my copy pasta above may still have gotten mixed up. If so please point it out and I will verify my testing results.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;EDIT: For posterity sake, I will explain the (very very very elementary and obvious) solution here. The script was writing out to &lt;CODE&gt;$splunk_home\bin&lt;/CODE&gt; not &lt;CODE&gt;$splunk_home\bin\scripts&lt;/CODE&gt; where the script was located. If you browse to the scripts location and run it, it obviously works, but when Splunk runs it, those relative paths do not exist from bin/&lt;/P&gt;

&lt;P&gt;The other quirk I have noticed is that when Splunkd is running as LocalSystem, it can execute batch scripts but not powershell. When Splunk is running as a service account the powershell scripts work fine.&lt;/P&gt;

&lt;P&gt;To wrap your ps1 up into a bat you should put the folllowing in the batch script.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File .\location\ofyour\script.ps1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above will look for &lt;CODE&gt;$splunk_home\bin\location\ofyour\script.ps1&lt;/CODE&gt; which is what we want.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2014 00:26:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150391#M30573</guid>
      <dc:creator>neiljpeterson</dc:creator>
      <dc:date>2014-10-03T00:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell script triggered from alert is not executing but I can see it triggered in python.log</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150392#M30574</link>
      <description>&lt;P&gt;where do you expect the file to be created? give the absolute file path rather than the one you have mentioned. I have not tries to give a ps1 file in the script trigger path ever. So could you try with a bat file? just mention complete path to script and output file everywhere. Make the cron schedule to &lt;CODE&gt;*/1 * * * *&lt;/CODE&gt;. It's quite easy to test with the below in a .bat file&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;%SPLUNK_ARG_5% &amp;gt; e:\output.txt&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2014 04:26:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150392#M30574</guid>
      <dc:creator>linu1988</dc:creator>
      <dc:date>2014-10-03T04:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell script triggered from alert is not executing but I can see it triggered in python.log</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150393#M30575</link>
      <description>&lt;P&gt;:hangs head in shame: The script was actually writing to &lt;CODE&gt;$splunk_home\bin&lt;/CODE&gt;, not to &lt;CODE&gt;$splunk_home\bin\scripts&lt;/CODE&gt; where the script was actually located. I found a bunch of text files from my testing in bin &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I had tested a hard path earlier, but I think I had other unresolved issues as well at that point so I errantly dismissed that as a solution.&lt;/P&gt;

&lt;P&gt;Failure in basic troubleshooting I'm afraid &lt;span class="lia-unicode-emoji" title=":neutral_face:"&gt;😐&lt;/span&gt; I will blame it on a lack of sleep.&lt;/P&gt;

&lt;P&gt;Thank you for your help! If you post it has an answer I can accept it.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2014 15:57:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150393#M30575</guid>
      <dc:creator>neiljpeterson</dc:creator>
      <dc:date>2014-10-03T15:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell script triggered from alert is not executing but I can see it triggered in python.log</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150394#M30576</link>
      <description>&lt;P&gt;Converted to an answer for ya.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2014 16:27:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150394#M30576</guid>
      <dc:creator>halr9000</dc:creator>
      <dc:date>2014-10-03T16:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell script triggered from alert is not executing but I can see it triggered in python.log</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150395#M30577</link>
      <description>&lt;P&gt;Hey @neiljpeterson, if I'm understanding you correctly, the final solution uses a .bat file in action.script.filename, is that right? I just pinged docs team to add this to the official scripted alert docs, and wanted to make sure I had that detail right. Or were you only mentioning .bat because of the issues when running PowerShell as localsystem?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jul 2015 18:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Powershell-script-triggered-from-alert-is-not-executing-but-I/m-p/150395#M30577</guid>
      <dc:creator>halr9000</dc:creator>
      <dc:date>2015-07-13T18:51:28Z</dc:date>
    </item>
  </channel>
</rss>

