jamf / JAWA

Jamf Automation and Webhook Assistant
MIT License
130 stars 12 forks source link

Possibility to send a custom response to POST requests for custom webhooks #27

Closed kryptonit1 closed 1 year ago

kryptonit1 commented 2 years ago

I've got a non-Jamf Pro system on which I've created a webhook in. When that webhook is triggered I want it to send a POST request to JAWA, which will run a script that collects information from Jamf Pro.

So I've created a custom webhook in JAWA and the non-Jamf Pro system is able to send a POST request to JAWA which JAWA receives. So far so good. The problem now is that I want to send a custom JSON response to that POST request based on the output of the script being executed by JAWA. But it seems that JAWA is only returning the original JSON string that was sent with the POST request from the non-Jamf Pro system when it responds with HTTP 200 OK on a successful POST request.

Would it be possible to change so that the response is the output of the script that is being executed for the custom webhook in JAWA? Or at least make it optional to return the script output as response?

My Python scripting skills are not very good, but I've looked at jawa_receiver.py and it could look something like this (not tested):

if validate_webhook(webhook_data, webhook_name, webhook_user, webhook_pass):
    jawa_logger().info(f"{webhook_name} validated!")
    run_script(webhook_data, webhook_name)

    for each_webhook in webhooks_json:
      if each_webhook['name'] == webhook_name:
        if each_webhook['tag'] == "custom":
          return run_script(webhook_data, webhook_name), 200
else:
    jawa_logger().info(f"{webhook_name} not validated!")
    return "Unauthorized", 401

return webhook_data, 200

There's probably a much more efficient way to return the output of the script than to run the script one more time via the run_script function though.

This would be really helpfully! I really appreciate that JAWA exists! :)

ball42 commented 2 years ago

Thanks for the feedback! I like this idea and agree that it would be useful - I'll wrap up the v3.0.2 release first (hopefully quickly) and tentatively plan to add this in for v3.0.3. I think it will be a pretty light lift to add in, and we can also include an option to use a custom key name with returning the script output if needed.

kryptonit1 commented 2 years ago

Thanks for the feedback! I like this idea and agree that it would be useful - I'll wrap up the v3.0.2 release first (hopefully quickly) and tentatively plan to add this in for v3.0.3. I think it will be a pretty light lift to add in, and we can also include an option to use a custom key name with returning the script output if needed.

Thanks a lot! Sounds good! đź‘Ť

ball42 commented 1 year ago

added in #37