<?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 Can I use Powershell as the script triggered by Custom Alert Actions? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324183#M10750</link>
    <description>&lt;P&gt;I'm about to migrate all our scripted actions to custom alert actions. Each alert triggers a .bat file, which is only used to trigger a Powershell-script doing the real magic. The bat file is used since Splunk cannot trigger the .ps1 file, CMD will have to use &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Powershell -f filename.ps1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The same issue will be for a custom alert action, Splunk cannot trigger that either, so therefore I &lt;BR /&gt;
When using scripted alert actions I defined a bat file which the alert triggered. The .bat-file was really just a "proxy" since I was not able to trigger the Powershell script directly from Splunk. &lt;/P&gt;

&lt;P&gt;So I have tried the same using a custom alert action&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[nimsoft_100_filenet_error]
is_custom = 1
label = Nimsoft #100, test alert
icon_path = action.png
payload_format = xml
disabled = 0
#alert.execute.cmd = alertNimsoft-doSplunkAlert.ps1
alert.execute.cmd = testArguments.bat
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I must admit that I have not fully understood if I can still use this approach. All examples found here &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.6.0/AdvancedDev/ModAlertsIntro"&gt;http://docs.splunk.com/Documentation/Splunk/6.6.0/AdvancedDev/ModAlertsIntro&lt;/A&gt; shows only Python examples, and I have a hard time understanding how to read the payload (stdin) in a bat/cmd-file and the be able to forward it to my Powershell-script. Is this doable or do I have to install Python on the server when using scripts in Custom Alert Actions?&lt;/P&gt;</description>
    <pubDate>Thu, 01 Jun 2017 06:24:06 GMT</pubDate>
    <dc:creator>rune_hellem</dc:creator>
    <dc:date>2017-06-01T06:24:06Z</dc:date>
    <item>
      <title>Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324183#M10750</link>
      <description>&lt;P&gt;I'm about to migrate all our scripted actions to custom alert actions. Each alert triggers a .bat file, which is only used to trigger a Powershell-script doing the real magic. The bat file is used since Splunk cannot trigger the .ps1 file, CMD will have to use &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Powershell -f filename.ps1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The same issue will be for a custom alert action, Splunk cannot trigger that either, so therefore I &lt;BR /&gt;
When using scripted alert actions I defined a bat file which the alert triggered. The .bat-file was really just a "proxy" since I was not able to trigger the Powershell script directly from Splunk. &lt;/P&gt;

&lt;P&gt;So I have tried the same using a custom alert action&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[nimsoft_100_filenet_error]
is_custom = 1
label = Nimsoft #100, test alert
icon_path = action.png
payload_format = xml
disabled = 0
#alert.execute.cmd = alertNimsoft-doSplunkAlert.ps1
alert.execute.cmd = testArguments.bat
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I must admit that I have not fully understood if I can still use this approach. All examples found here &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.6.0/AdvancedDev/ModAlertsIntro"&gt;http://docs.splunk.com/Documentation/Splunk/6.6.0/AdvancedDev/ModAlertsIntro&lt;/A&gt; shows only Python examples, and I have a hard time understanding how to read the payload (stdin) in a bat/cmd-file and the be able to forward it to my Powershell-script. Is this doable or do I have to install Python on the server when using scripts in Custom Alert Actions?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2017 06:24:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324183#M10750</guid>
      <dc:creator>rune_hellem</dc:creator>
      <dc:date>2017-06-01T06:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324184#M10751</link>
      <description>&lt;P&gt;It is a bit vague but this is what I'm interpreting from the documentation:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.6.0/Admin/Alertactionsconf"&gt;https://docs.splunk.com/Documentation/Splunk/6.6.0/Admin/Alertactionsconf&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;alert.execute.cmd = &amp;lt;string&amp;gt;
* For custom alert actions: Explicitly specify the command to be executed
  when the alert action is triggered. This refers to a binary or script
  in the bin folder of the app the alert action is defined in, or to a
  path pointer file, also located in the bin folder.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is telling me alert.execute.cmd should point to the powershell executable&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;alert.execute.cmd = powershell.exe
alert.execute.cmd.arg.1 = -f
alert.execute.cmd.arg.2 = filename.ps1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to use python, you would not need to install python as python is packaged with splunk.  &lt;/P&gt;

&lt;P&gt;To use the arguments send to the powershell you'll use something like this in the script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$arg1=$args[0]
$arg2=$args[1]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I feel like the args should be the same as you see here: &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;Personally I'd use python for this even if I didnt know python.  Learning python gives you super Splunk powers &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 13:05:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324184#M10751</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2017-06-02T13:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324185#M10752</link>
      <description>&lt;P&gt;Ahh, yes - off course, I will try that out. &lt;/P&gt;

&lt;P&gt;And yes, I see the point with Python, but I prefer to use out of the box if possible. But the good news is that my boss has said ok to use Linux when we later move to a clustered Splunk-environment....so that should make things easier....sometimes in the future &lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 12:40:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324185#M10752</guid>
      <dc:creator>rune_hellem</dc:creator>
      <dc:date>2017-06-15T12:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324186#M10753</link>
      <description>&lt;P&gt;This was how I finally was able to launch the Powershell-script. All was in the documentation, but only after I got it figured out I did understand the documentation ... (as so many times before)&lt;/P&gt;

&lt;P&gt;In the file alert_actions.conf the alert has been defined like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;alert.execute.cmd = powershell.path
alert.execute.cmd.arg.0 = -NoProfile
alert.execute.cmd.arg.1 = -f
alert.execute.cmd.arg.2 = $SPLUNK_HOME\etc\apps\klp_nimsoft_custom_alerts\bin\testArguments.ps1
alert.execute.cmd.arg.3 = --execute
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then in the \bin-folder of the Splunk-app I have created I have added a file named &lt;EM&gt;powershell.path&lt;/EM&gt; containing one single line &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next step now will be to understand how I can use Powershell to read the payload, same as Pyhton does with the code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;settings = json.loads(sys.stdin.read())
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 08:14:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324186#M10753</guid>
      <dc:creator>rune_hellem</dc:creator>
      <dc:date>2017-06-22T08:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324187#M10754</link>
      <description>&lt;P&gt;Did you ever figure out how to pass arguments to powershell?  The only thing I'm getting when looping through the args array is "--Execute."&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 15:31:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324187#M10754</guid>
      <dc:creator>jdajpowell</dc:creator>
      <dc:date>2018-03-14T15:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324188#M10755</link>
      <description>&lt;P&gt;Adding this in the comments vs. answers.  &lt;/P&gt;

&lt;P&gt;Were you able to figure out how to pass arguments?  When looping through the args array I'm only seeing "--execute."  &lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 15:33:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324188#M10755</guid>
      <dc:creator>jdajpowell</dc:creator>
      <dc:date>2018-03-14T15:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324189#M10756</link>
      <description>&lt;P&gt;As I remember it I got an answer from support saying that it actually is not possible using Powershell. If I'm not totally wrong it is a bug in how Splunk implements Powershell. Therefore I switched to Python, as a starter because of this, but also to make the move to running Splunk on Linux easier. As a result of the work my company does related to GDPR we will index a lot more data/logs, and I really expect this to force us to cluster Splunk due to performance. So anyhow it was not a big deal moving to Python.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 06:54:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324189#M10756</guid>
      <dc:creator>rune_hellem</dc:creator>
      <dc:date>2018-03-15T06:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Powershell as the script triggered by Custom Alert Actions?</title>
      <link>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324190#M10757</link>
      <description>&lt;P&gt;$args doesn't work for PowerShell for some reason. There is a variable called $input which has the XML or JSON result information.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 00:15:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Can-I-use-Powershell-as-the-script-triggered-by-Custom-Alert/m-p/324190#M10757</guid>
      <dc:creator>gclaytontmwa</dc:creator>
      <dc:date>2018-06-12T00:15:49Z</dc:date>
    </item>
  </channel>
</rss>

