<?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 Adding custom alert action for launching python script in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595465#M13790</link>
    <description>&lt;P&gt;In short, I have a router with an IP address on a virtual machine, and I need that when I receive a log that one of its interfaces has turned off, a trigger is triggered and my script runs.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;test1.py&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;netmiko &lt;SPAN&gt;import &lt;/SPAN&gt;ConnectHandler&lt;BR /&gt;&lt;BR /&gt;R1 = {&lt;BR /&gt;    &lt;SPAN&gt;"device_type"&lt;/SPAN&gt;: &lt;SPAN&gt;"cisco_ios"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"host"&lt;/SPAN&gt;: &lt;SPAN&gt;"R1"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"ip"&lt;/SPAN&gt;: &lt;SPAN&gt;"192.168.12.130"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"username"&lt;/SPAN&gt;: &lt;SPAN&gt;"admin"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"password"&lt;/SPAN&gt;: &lt;SPAN&gt;"admin1"&lt;BR /&gt;&lt;/SPAN&gt;}&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;main&lt;/SPAN&gt;():&lt;BR /&gt;    commands = [&lt;SPAN&gt;'int fa3/0'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                &lt;SPAN&gt;'no sh'&lt;BR /&gt;&lt;/SPAN&gt;                ]&lt;BR /&gt;&lt;BR /&gt;    connect = ConnectHandler(**R1)&lt;BR /&gt;    connect.enable()&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    output = connect.send_config_set(commands)&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;f"&lt;/SPAN&gt;&lt;SPAN&gt;\n\n&lt;/SPAN&gt;&lt;SPAN&gt;-------------- Device &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;R1[&lt;SPAN&gt;'ip'&lt;/SPAN&gt;]&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt; --------------"&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(output)&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"-------------------- End -------------------"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if &lt;/SPAN&gt;__name__ == &lt;SPAN&gt;'__main__'&lt;/SPAN&gt;:&lt;BR /&gt;    main()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Login to splunk I get, the Add to Triggered Alerts trigger is triggered. But the .py file itself does not run. Checked through ".../splunk.exe cmd python .../test1.py " it starts and works.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;alert_actions.conf&lt;/P&gt;&lt;PRE&gt;[test1]&lt;BR /&gt;&lt;SPAN&gt;is_custom &lt;/SPAN&gt;= 1&lt;BR /&gt;&lt;SPAN&gt;label &lt;/SPAN&gt;= Change_interface_state&lt;BR /&gt;&lt;SPAN&gt;description &lt;/SPAN&gt;= Change_interface_state&lt;BR /&gt;&lt;SPAN&gt;icon_path &lt;/SPAN&gt;= test1.png&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;alert.execute.cmd &lt;/SPAN&gt;= test1.py&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;app.conf&lt;/P&gt;&lt;PRE&gt;[install]&lt;BR /&gt;&lt;SPAN&gt;is_configured &lt;/SPAN&gt;= 1&lt;BR /&gt;&lt;SPAN&gt;state &lt;/SPAN&gt;= enabled&lt;BR /&gt;&lt;BR /&gt;[ui]&lt;BR /&gt;&lt;SPAN&gt;is_visible &lt;/SPAN&gt;= 1&lt;BR /&gt;&lt;SPAN&gt;label &lt;/SPAN&gt;= test&lt;BR /&gt;&lt;BR /&gt;[launcher]&lt;BR /&gt;&lt;SPAN&gt;author &lt;/SPAN&gt;= QAZxsw&lt;BR /&gt;&lt;SPAN&gt;description &lt;/SPAN&gt;= This is custom&lt;BR /&gt;&lt;SPAN&gt;version &lt;/SPAN&gt;= 1.0.0&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;test1.html&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&amp;lt;from &lt;/SPAN&gt;&lt;SPAN&gt;class&lt;/SPAN&gt;&lt;SPAN&gt;="from-horizontal from-complex"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    &amp;lt;p&amp;gt;&lt;/SPAN&gt;Change state of interface&lt;SPAN&gt;&amp;lt;/p&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/from&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help (._.)&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2022 17:55:52 GMT</pubDate>
    <dc:creator>sherkhan6ad6oy</dc:creator>
    <dc:date>2022-04-26T17:55:52Z</dc:date>
    <item>
      <title>Adding custom alert action for launching python script</title>
      <link>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595465#M13790</link>
      <description>&lt;P&gt;In short, I have a router with an IP address on a virtual machine, and I need that when I receive a log that one of its interfaces has turned off, a trigger is triggered and my script runs.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;test1.py&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;netmiko &lt;SPAN&gt;import &lt;/SPAN&gt;ConnectHandler&lt;BR /&gt;&lt;BR /&gt;R1 = {&lt;BR /&gt;    &lt;SPAN&gt;"device_type"&lt;/SPAN&gt;: &lt;SPAN&gt;"cisco_ios"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"host"&lt;/SPAN&gt;: &lt;SPAN&gt;"R1"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"ip"&lt;/SPAN&gt;: &lt;SPAN&gt;"192.168.12.130"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"username"&lt;/SPAN&gt;: &lt;SPAN&gt;"admin"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;"password"&lt;/SPAN&gt;: &lt;SPAN&gt;"admin1"&lt;BR /&gt;&lt;/SPAN&gt;}&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;main&lt;/SPAN&gt;():&lt;BR /&gt;    commands = [&lt;SPAN&gt;'int fa3/0'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                &lt;SPAN&gt;'no sh'&lt;BR /&gt;&lt;/SPAN&gt;                ]&lt;BR /&gt;&lt;BR /&gt;    connect = ConnectHandler(**R1)&lt;BR /&gt;    connect.enable()&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    output = connect.send_config_set(commands)&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;f"&lt;/SPAN&gt;&lt;SPAN&gt;\n\n&lt;/SPAN&gt;&lt;SPAN&gt;-------------- Device &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;R1[&lt;SPAN&gt;'ip'&lt;/SPAN&gt;]&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt; --------------"&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(output)&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"-------------------- End -------------------"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if &lt;/SPAN&gt;__name__ == &lt;SPAN&gt;'__main__'&lt;/SPAN&gt;:&lt;BR /&gt;    main()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Login to splunk I get, the Add to Triggered Alerts trigger is triggered. But the .py file itself does not run. Checked through ".../splunk.exe cmd python .../test1.py " it starts and works.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;alert_actions.conf&lt;/P&gt;&lt;PRE&gt;[test1]&lt;BR /&gt;&lt;SPAN&gt;is_custom &lt;/SPAN&gt;= 1&lt;BR /&gt;&lt;SPAN&gt;label &lt;/SPAN&gt;= Change_interface_state&lt;BR /&gt;&lt;SPAN&gt;description &lt;/SPAN&gt;= Change_interface_state&lt;BR /&gt;&lt;SPAN&gt;icon_path &lt;/SPAN&gt;= test1.png&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;alert.execute.cmd &lt;/SPAN&gt;= test1.py&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;app.conf&lt;/P&gt;&lt;PRE&gt;[install]&lt;BR /&gt;&lt;SPAN&gt;is_configured &lt;/SPAN&gt;= 1&lt;BR /&gt;&lt;SPAN&gt;state &lt;/SPAN&gt;= enabled&lt;BR /&gt;&lt;BR /&gt;[ui]&lt;BR /&gt;&lt;SPAN&gt;is_visible &lt;/SPAN&gt;= 1&lt;BR /&gt;&lt;SPAN&gt;label &lt;/SPAN&gt;= test&lt;BR /&gt;&lt;BR /&gt;[launcher]&lt;BR /&gt;&lt;SPAN&gt;author &lt;/SPAN&gt;= QAZxsw&lt;BR /&gt;&lt;SPAN&gt;description &lt;/SPAN&gt;= This is custom&lt;BR /&gt;&lt;SPAN&gt;version &lt;/SPAN&gt;= 1.0.0&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;test1.html&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&amp;lt;from &lt;/SPAN&gt;&lt;SPAN&gt;class&lt;/SPAN&gt;&lt;SPAN&gt;="from-horizontal from-complex"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    &amp;lt;p&amp;gt;&lt;/SPAN&gt;Change state of interface&lt;SPAN&gt;&amp;lt;/p&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/from&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help (._.)&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 17:55:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595465#M13790</guid>
      <dc:creator>sherkhan6ad6oy</dc:creator>
      <dc:date>2022-04-26T17:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding custom alert action for launching python script</title>
      <link>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595574#M13792</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/245240"&gt;@sherkhan6ad6oy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are there any messages in the splunkd.log that suggests that the script was not able to be ran?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 12:53:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595574#M13792</guid>
      <dc:creator>Stefanie</dc:creator>
      <dc:date>2022-04-27T12:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding custom alert action for launching python script</title>
      <link>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595614#M13794</link>
      <description>&lt;LI-CODE lang="markup"&gt;Alert script returned error code 1&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Apr 2022 15:52:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595614#M13794</guid>
      <dc:creator>sherkhan6ad6oy</dc:creator>
      <dc:date>2022-04-27T15:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Adding custom alert action for launching python script</title>
      <link>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595626#M13796</link>
      <description>&lt;P&gt;Could you try editing alert_actions.conf to include the correct Python version?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;python.version = {default|python|python2|python3}
* For Python scripts only, selects which Python version to use.
* Set to either "default" or "python" to use the system-wide default Python
  version.
* Optional.
* Default: Not set; uses the system-wide Python version.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.2.6/Admin/Alertactionsconf" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/8.2.6/Admin/Alertactionsconf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 18:05:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595626#M13796</guid>
      <dc:creator>Stefanie</dc:creator>
      <dc:date>2022-04-27T18:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Adding custom alert action for launching python script</title>
      <link>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595745#M13797</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236717"&gt;@Stefanie&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, the problem will not be solved. Python in the bar works on a different principle. There is an error in the code in the logs, on line N. Importing other libraries is not possible. There is a similar question where the problem was in the import. She decided to import the app to add the numpy library.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 07:32:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/595745#M13797</guid>
      <dc:creator>sherkhan6ad6oy</dc:creator>
      <dc:date>2022-04-28T07:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Adding custom alert action for launching python script</title>
      <link>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/596036#M13810</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236717"&gt;@Stefanie&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have solved this problem. Moved the root folder with windows python to the splank folder. Now everything works fine, all libraries are available&lt;/P&gt;</description>
      <pubDate>Sat, 30 Apr 2022 13:50:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Adding-custom-alert-action-for-launching-python-script/m-p/596036#M13810</guid>
      <dc:creator>sherkhan6ad6oy</dc:creator>
      <dc:date>2022-04-30T13:50:33Z</dc:date>
    </item>
  </channel>
</rss>

