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!

Developer Spotlight with Brett Adams

In our third Spotlight feature, we're excited to shine a light on Brett—a Splunk consultant, innovative ...

Index This | What can you do to make 55,555 equal 500?

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

Say goodbye to manually analyzing phishing and malware threats with Splunk Attack ...

In today’s evolving threat landscape, we understand you’re constantly bombarded with phishing and malware ...