<?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: Is There an Easy Guide to Create a Custom Alert Action to Run a Batch File or PowerShell Script in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750294#M22694</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/311834"&gt;@Salvador_Dalí&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The run a script alert action is officially deprecated.&amp;nbsp;&lt;BR /&gt;You can better try with a custom alert action app.&lt;/P&gt;&lt;P&gt;Create custom alert action app with &lt;STRONG&gt;bin, default, and metadata &lt;/STRONG&gt;folders&lt;BR /&gt;Eg:&lt;BR /&gt;$SPLUNK_HOME/etc/apps/custom_alert_action/bin/&lt;BR /&gt;Put your&lt;STRONG&gt; script.bat&lt;/STRONG&gt; inside the &lt;STRONG&gt;bin&lt;/STRONG&gt;/ folder&lt;/P&gt;&lt;P&gt;Inside default/, create &lt;STRONG&gt;alert_actions.conf&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[run_script]
is_custom = 1
label = Run Script
description = Executes a script
script = script.bat&lt;/LI-CODE&gt;&lt;P&gt;Also in default/, create &lt;STRONG&gt;app.conf&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[install]
state = enabled

[ui]
is_visible = true&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Restart Splunk&lt;/STRONG&gt;&lt;BR /&gt;After restarting, your alert action “&lt;STRONG&gt;Run Script&lt;/STRONG&gt;” will show up in the alert UI&lt;/P&gt;&lt;P&gt;#&lt;A href="https://help.splunk.com/en/splunk-enterprise/alert-and-respond/alerting-manual/9.4/configure-alert-actions/run-a-script-alert-action" target="_blank"&gt;https://help.splunk.com/en/splunk-enterprise/alert-and-respond/alerting-manual/9.4/configure-alert-actions/run-a-script-alert-action&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Prewin&lt;BR /&gt;Splunk Enthusiast | Always happy to help! If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jul 2025 04:05:13 GMT</pubDate>
    <dc:creator>PrewinThomas</dc:creator>
    <dc:date>2025-07-23T04:05:13Z</dc:date>
    <item>
      <title>Is There an Easy Guide to Create a Custom Alert Action to Run a Batch File or PowerShell Script</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750292#M22692</link>
      <description>&lt;P&gt;I don't understand why t&lt;SPAN&gt;he legacy 'run a script' alert action has been deprecated.&amp;nbsp; The official guidelines to create a 'Custom Alert Action' are to complicated to follow.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I attempted to find a guide from Google, but there are too many conflicting methods, and I consistently failed to implement them.&lt;/P&gt;&lt;P&gt;I just want a simple and straightforward guide to create a 'Custom Alert Action'&amp;nbsp; that runs a batch file (script.bat) or a PowerShell script file (script.ps1) when the alert is triggered.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Or just create a 'custom alert action' that exactly do the same thing as the&amp;nbsp;deprecated 'run a script' alert action. (Just type the batch file name and that's it)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Environment: Splunk Enterprise 9.1 (Windows)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 03:56:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750292#M22692</guid>
      <dc:creator>Salvador_Dalí</dc:creator>
      <dc:date>2025-07-23T03:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Is There an Easy Guide to Create a Custom Alert Action to Run a Batch File or PowerShell Script</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750294#M22694</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/311834"&gt;@Salvador_Dalí&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The run a script alert action is officially deprecated.&amp;nbsp;&lt;BR /&gt;You can better try with a custom alert action app.&lt;/P&gt;&lt;P&gt;Create custom alert action app with &lt;STRONG&gt;bin, default, and metadata &lt;/STRONG&gt;folders&lt;BR /&gt;Eg:&lt;BR /&gt;$SPLUNK_HOME/etc/apps/custom_alert_action/bin/&lt;BR /&gt;Put your&lt;STRONG&gt; script.bat&lt;/STRONG&gt; inside the &lt;STRONG&gt;bin&lt;/STRONG&gt;/ folder&lt;/P&gt;&lt;P&gt;Inside default/, create &lt;STRONG&gt;alert_actions.conf&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[run_script]
is_custom = 1
label = Run Script
description = Executes a script
script = script.bat&lt;/LI-CODE&gt;&lt;P&gt;Also in default/, create &lt;STRONG&gt;app.conf&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[install]
state = enabled

[ui]
is_visible = true&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Restart Splunk&lt;/STRONG&gt;&lt;BR /&gt;After restarting, your alert action “&lt;STRONG&gt;Run Script&lt;/STRONG&gt;” will show up in the alert UI&lt;/P&gt;&lt;P&gt;#&lt;A href="https://help.splunk.com/en/splunk-enterprise/alert-and-respond/alerting-manual/9.4/configure-alert-actions/run-a-script-alert-action" target="_blank"&gt;https://help.splunk.com/en/splunk-enterprise/alert-and-respond/alerting-manual/9.4/configure-alert-actions/run-a-script-alert-action&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Prewin&lt;BR /&gt;Splunk Enthusiast | Always happy to help! If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 04:05:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750294#M22694</guid>
      <dc:creator>PrewinThomas</dc:creator>
      <dc:date>2025-07-23T04:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Is There an Easy Guide to Create a Custom Alert Action to Run a Batch File or PowerShell Script</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750305#M22698</link>
      <description>&lt;P&gt;Didn't work. The alert is triggered but the batch didn't run.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 06:19:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750305#M22698</guid>
      <dc:creator>Salvador_Dalí</dc:creator>
      <dc:date>2025-07-23T06:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Is There an Easy Guide to Create a Custom Alert Action to Run a Batch File or PowerShell Script</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750307#M22699</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/311834"&gt;@Salvador_Dalí&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To create a simple custom alert action that runs a batch file (script.bat) or PowerShell script (script.ps1) on Windows in Splunk Enterprise 9.x, you'll need to build a basic Splunk app with a custom modular alert. This replaces the deprecated "run a script" action.&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Create a new app directory on your Splunk server, navigate to $SPLUNK_HOME/etc/apps/ and create a new folder, e.g., myorg_custom_action.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;Create default/alert_actions.conf with:&lt;PRE&gt;[my_script_action]
is_custom = 1
label = Run My Script
description = Runs a batch or PowerShell script
payload_format = &lt;SPAN class=""&gt;json&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;Create default/app.conf with basic app metadata:&lt;PRE&gt;[ui]
is_visible = 0  &lt;BR /&gt;# Hide from app list because this isnt a UI based app...
&lt;BR /&gt;#...&amp;nbsp;etc.&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Create bin/my_script_action.py (the Python script that executes your batch/PS script). Use this template to get you started:&lt;/P&gt;&lt;PRE&gt;python
     import sys
     import json
     import subprocess

     # Read payload from stdin
     payload = json.loads(sys.stdin.read())

     # Define your script path (absolute path on the Splunk server)
     script_path = "C:\\path\\to\\your\\script.bat"  # Or .ps1 for PowerShell

     # Run the script (use powershell.exe for .ps1)
     if script_path.endswith('.ps1'):
         subprocess.call(['powershell.exe', '-File', script_path])
     else:
         subprocess.call([script_path])

     sys.exit(0)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;If you want to pass alert data to the script, modify the Python to write payload to a file or pass as args, then adjust your batch/PS script accordingly.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Restart Splunk ($SPLUNK_HOME/bin/splunk restart). The action "Run My Script" will appear in alert configuration under "Add Actions".&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Test&lt;/STRONG&gt;: Create a test alert, add your custom action, and trigger it to verify the script runs.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;This is a minimal setup, I would recommend extending it for error handling or parameters as required.&lt;/P&gt;&lt;P&gt;Custom alert actions are modular apps that allow flexible scripting. The Python handler example reads the alert payload and executes your external script using subprocess. This works on Windows but ensure the Splunk service account has permissions to run the scripts.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":glowing_star:"&gt;🌟&lt;/span&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Did this answer help you?&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If so, please consider:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Adding karma to show it was useful&lt;/LI&gt;&lt;LI&gt;Marking it as the solution if it resolved your issue&lt;/LI&gt;&lt;LI&gt;Commenting if you need any clarification&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Your feedback encourages the volunteers in this community to continue contributing&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 06:36:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750307#M22699</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-07-23T06:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is There an Easy Guide to Create a Custom Alert Action to Run a Batch File or PowerShell Script</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750313#M22701</link>
      <description>&lt;P class="lia-align-left"&gt;&lt;SPAN&gt;It didn't work.&amp;nbsp; The alert is triggered but the batch still didn't run.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 07:17:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Is-There-an-Easy-Guide-to-Create-a-Custom-Alert-Action-to-Run-a/m-p/750313#M22701</guid>
      <dc:creator>Salvador_Dalí</dc:creator>
      <dc:date>2025-07-23T07:17:13Z</dc:date>
    </item>
  </channel>
</rss>

