All Apps and Add-ons

Problems calling a webhook

davedeluxe
Engager

Hi,
can someone help me? I'm trying to call a webhook on AWX Tower (Ansible) using the Add-On Builder.
This is my script but it doesn't work, but I don't get an error message either:

 

# encoding = utf-8
def process_event(helper, *args, **kwargs):
    """
    # IMPORTANT
    # Do not remove the anchor macro:start and macro:end lines.
    # These lines are used to generate sample code. If they are
    # removed, the sample code will not be updated when configurations
    # are updated.

    [sample_code_macro:start]

    # The following example gets the alert action parameters and prints them to the log
    machine = helper.get_param("machine")
    helper.log_info("machine={}".format(machine))


    # The following example adds two sample events ("hello", "world")
    # and writes them to Splunk
    # NOTE: Call helper.writeevents() only once after all events
    # have been added
    helper.addevent("hello", sourcetype="sample_sourcetype")
    helper.addevent("world", sourcetype="sample_sourcetype")
    helper.writeevents(index="summary", host="localhost", source="localhost")

    # The following example gets the events that trigger the alert
    events = helper.get_events()
    for event in events:
        helper.log_info("event={}".format(event))

    # helper.settings is a dict that includes environment configuration
    # Example usage: helper.settings["server_uri"]
    helper.log_info("server_uri={}".format(helper.settings["server_uri"]))
    [sample_code_macro:end]
    """

    helper.log_info("Alert action awx_webhooks started.")

    # TODO: Implement your alert action logic here
    
    import requests

    url = 'https://<AWX-URL>/api/v2/job_templates/272/gitlab/'
    headers = {'Authorization': 'X-Gitlab-Token: <MYTOKEN>'}
    
    response = requests.post(url, headers=headers, verify=False)
    
    print(response.status_code)
    print(response.text)

 

Labels (1)
0 Karma
Get Updates on the Splunk Community!

Index This | What did the zero say to the eight?

June 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

Splunk Observability Cloud's AI Assistant in Action Series: Onboarding New Hires & ...

This is the fifth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Now Playing: Splunk Education Summer Learning Premieres

It’s premiere season, and Splunk Education is rolling out new releases you won’t want to miss. Whether you’re ...