Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kryptonit1 opened this issue Jan 27, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@kryptonit1
Copy link

kryptonit1 commented Jan 27, 2022

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 ball42 self-assigned this Jan 27, 2022
@ball42 ball42 added the enhancement New feature or request label Jan 27, 2022
@ball42
Copy link
Collaborator

ball42 commented Jan 27, 2022

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
Copy link
Author

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
Copy link
Collaborator

ball42 commented Dec 2, 2022

added in #37

@ball42 ball42 closed this as completed Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants