Alerting

Missing --execute Argument in Custom Alert App

secphilomath1
Explorer

I am working on a custom alert app to replace our old custom alert script action.  It was working fine but all of sudden I am no longer getting the --execute argument being passed and my script doesn't work any more.

 

Here is the code:

 

if __name__ == "__main__":

    #clear logs
    now = datetime.now()
    dt_string = now.strftime("%d/%m/%Y %H:%M:%S")

    log(dt_string + ":  Start Version 1.2","w")


    log("Checking to see if we have any arguments...")

    log("Number of arguments: " + str(len(sys.argv)))
    
    if len(sys.argv) > 1 and sys.argv[1] == "--execute":
        log("We have arguments.")

        try:
            payload = json.loads(sys.stdin.read())

            result_file = payload['results_file']

            #Pass the payload to main for processing....
            main(payload)

            #End
            now = datetime.now()
            dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
            log(dt_string + ": Processing complete.")


        except:
            log("We have an error on settings, exiting")
            sys.exit()

    else:
        log("There were no arguments.  Exiting.")

    sys.exit()

 

Here is the output of my logging:

 

16/03/2023 10:55:16:  Start Version 1.2

Checking to see if we have any arguments...

Number of arguments: 1

There were no arguments.  Exiting.

 

 

I have no idea what the --execute argument is and how it is passed, or what it actually means and can't find anything much about it  Hoping to shed some light here

 

thanks!

 

Labels (2)
0 Karma

secphilomath1
Explorer

Cool thanks for the reference info, but mine all of a sudden isn't passing the --execute and then is failing.  Can you think of a reason why it wouldn't pass that, the script is being called by the custom alert app.

0 Karma

yeahnah
Motivator

That sounds weird alright.

I guess you've tried a Splunk restart?

What do the internal logs show (Settings > Alert actions > View log events).  Any errors showing up?

Also, the new Slunk Dev Portal docs are pretty poor.  The old docs were better.  I found an archived copy here, if that helps. 

http://web.archive.org/web/20220519181621/http://docs.splunk.com:80/Documentation/Splunk/latest/Adva...

0 Karma

yeahnah
Motivator

Hi @secphilomath1 

After you configure a test alert and define your custom alert action as a triggered action, when Splunk calls the alert action script it passes the --execute as the first command line parameter.

https://dev.splunk.com/enterprise/docs/devtools/customalertactions/writescriptcaa

yeahnah_0-1679010305411.png

Basically, something like this...

 

 

 python _myalertscript.py_ --execute < _myalert_result_payload.json_

 

 

How are you testing you alerting script?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Accelerate Splunk App Development with AI

  Learn how to automate the repetitive parts of your build cycle.   Watch On-Demand   Replay the Accelerate ...

Splunk Agent Observability: Measuring AI Value with Splunk Tokenomics on AWS

The AI landscape is moving faster than ever, and our latest 2026 State of Observability report provides the ...

Enterprise Security Watch Party: What’s New in 8.8 - Recap

Splunk Community HQ hosted a Splunk Enterprise Security Watch Party: What’s New In ES 8.8 last Thursday. I had ...