<?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: Why is custom alert action not working? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/641166#M15013</link>
    <description>&lt;P&gt;Well I found the problem. The script runs when I comment out the execute flag check section. Might be a bit of a problem, as it seems this is supposed to be in there for live apps.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2023 17:21:06 GMT</pubDate>
    <dc:creator>tlsawyer</dc:creator>
    <dc:date>2023-04-24T17:21:06Z</dc:date>
    <item>
      <title>Why is custom alert action not working?</title>
      <link>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/639975#M14995</link>
      <description>&lt;P&gt;I'm new to writing apps for Splunk, so I'm trying something simple. A raw payload dump. I have the alert set to log the event and fire off my custom action when CPU usage &amp;gt;20%, and only once every 15 minutes. So i have a reliable trigger source. However, it never seems to launch my action and I can't for the life of me figure out why. I'm trying to get the code to write a line to one file when it launches, write debug to another, and write both json and raw to separate files so I can decide on parsing later. Any thoughts on what I'm doing wrong here?? I'm not even getting the line in the file to let me know it tried to run.&lt;/P&gt;
&lt;P&gt;alert_actions.conf:&lt;/P&gt;
&lt;P&gt;[NCPAServiceAlert]&lt;BR /&gt;is_custom = 1&lt;BR /&gt;label = NCPA Service Alert&lt;BR /&gt;description = Test Alert for NCPA Listener Service&lt;BR /&gt;icon_path = awesomesauce.PNG&lt;BR /&gt;payload_format = json&lt;BR /&gt;python.version = python3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NCPAServiceAlert.py:&lt;/P&gt;
&lt;P&gt;import json&lt;BR /&gt;import sys&lt;BR /&gt;import logging&lt;BR /&gt;import time&lt;BR /&gt;import datetime&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ts = time.time()&lt;BR /&gt;sttime = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d_%H:%M:%S - ')&lt;/P&gt;
&lt;P&gt;didirun = "C:/Users/Public/debug/Did_I_Run.txt"&lt;BR /&gt;with open(didirun, "w+") as d:&lt;BR /&gt;d.write(sttime + " I ran. Can't say much about the rest though." + \n)&lt;/P&gt;
&lt;P&gt;logging.basicConfig(filename='C:/Users/Public/debug/debug.txt', filemode='w' encoding='utf-8', level=logging.DEBUG)&lt;/P&gt;
&lt;P&gt;class NCPAServiceAlert:&lt;BR /&gt;def __init__(self):&lt;BR /&gt;logging.debug()&lt;BR /&gt;self.params = [&lt;BR /&gt;#"configuration"&lt;BR /&gt;#"text"&lt;BR /&gt;]&lt;/P&gt;
&lt;P&gt;def send_alert&lt;BR /&gt;logging.debug()&lt;BR /&gt;filejson = "C:/Users/Public/debug/alertdump.txt"&lt;BR /&gt;with open(filejson, "w+") as f:&lt;BR /&gt;payload = json.loads(sys.stdin.read())&lt;BR /&gt;f.write(payload)&lt;BR /&gt;fileraw = "C:/Users/Public/debug/generic_dump.txt"&lt;BR /&gt;with open(fileraw, "w+") as g:&lt;BR /&gt;payload = sys.stdin.read()&lt;BR /&gt;g.write(payload)&lt;BR /&gt;&lt;BR /&gt;if __name__ == "__main__":&lt;BR /&gt;logging.debug()&lt;BR /&gt;if len(sys.argv) &amp;lt; 2 or sys.argv[1] != "--execute":&lt;BR /&gt;sys.stderr.write(FATAL EXCEPTION (expected --execute flag)\n)&lt;BR /&gt;sys.exit(1)&lt;BR /&gt;if not send_alert()&lt;BR /&gt;sys.exit(2)&lt;BR /&gt;&lt;BR /&gt;except Exception as e:&lt;BR /&gt;sys.stderr.write(ERROR - Unexpected error %s\n % e)&lt;BR /&gt;sys.exit(3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 18:45:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/639975#M14995</guid>
      <dc:creator>tlsawyer</dc:creator>
      <dc:date>2023-04-14T18:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why is custom alert action not working?</title>
      <link>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/640014#M14996</link>
      <description>&lt;P&gt;The alert_actions.conf stanza is missing&amp;nbsp; &lt;FONT face="courier new,courier"&gt;alert.execute.cmd = &amp;lt;file in bin directory&amp;gt;&lt;/FONT&gt;&amp;nbsp;so Splunk knows what code to run when the alert triggers.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 20:57:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/640014#M14996</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-04-14T20:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why is custom alert action not working?</title>
      <link>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/640265#M15001</link>
      <description>&lt;P&gt;Awesome, I'll try adding that. I didn't see that in other apps but I'll give her a try. Thanks man.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:48:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/640265#M15001</guid>
      <dc:creator>tlsawyer</dc:creator>
      <dc:date>2023-04-17T17:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why is custom alert action not working?</title>
      <link>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/640296#M15003</link>
      <description>&lt;P&gt;Hmm, still not working. I'm trying to find the logs and see if there is anything that would help figure out the cause.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 21:25:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/640296#M15003</guid>
      <dc:creator>tlsawyer</dc:creator>
      <dc:date>2023-04-17T21:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Why is custom alert action not working?</title>
      <link>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/641166#M15013</link>
      <description>&lt;P&gt;Well I found the problem. The script runs when I comment out the execute flag check section. Might be a bit of a problem, as it seems this is supposed to be in there for live apps.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 17:21:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Why-is-custom-alert-action-not-working/m-p/641166#M15013</guid>
      <dc:creator>tlsawyer</dc:creator>
      <dc:date>2023-04-24T17:21:06Z</dc:date>
    </item>
  </channel>
</rss>

