Hello all! I am struggling to create webhooks towa...
# pact-broker
a
Hello all! I am struggling to create webhooks towards a Prometheus server, I was wondering if anyone here has ever done it and could chare some knowledge? Better to create them visually on the broker or via the broker CLI? What do you put in the body? Thank you in advance
👀 1
m
What are you trying to do?
a
the big picture is to see broker events in a Grafana dashbaord. What I understand is that I need to pass through Prometheus, whereas the broker sends HTTP requests to Prometheus and this latter to Grafana. So I want to create webhooks that send events to the Prometheus server -- hope it is clear
👍 1
m
Yep! And what problem are you currently running into?
a
Right now I am running everything local using Docker. I have Prometheus in one container (localhost:9090) and the broker on another container (localhost:9292). I use the broker UI to create the webhook as in the first image attached. I don't understand where I need to pass the event name, and when I try I get a simple 0 error as outcome (see second image). No idea where to dig deeper for what is wrong...
In this case I would like to get a simple text to Prometheus
m
hmm not sure what inspired you to send a POST request to the root path - what were you expecting to happen there? The Pact Broker has a number of APIs and uses the HAL convention for hypermedia. The
/
(root) resource will provide you links to follow to other resources
See https://docs.pact.io/pact_broker/webhooks#events for general advice, I’d start by using the CLI
You can add the
--verbose
command to that to see what requests it actually makes. If you really need the API, there is some basic docs here: https://docs.pact.io/pact_broker/api/webhooks
We at PactFlow actually also publish a more formal version of that API here: https://smartbear.portal.swaggerhub.com/pactflow/default/pactflow_saas_api#/webhook/post_webhooks (just be careful looking at the rest of the APIs because a bunch of them are PactFlow specific and won’t apply to the OSS Pact Broker)
a
Thank you for the links. I went for a POST because since I am pushing content from the broker to another server a GET seemed counter-intuitive. and I choose the root path because I didn't have any other path to choose from in Prometheus. I already did take a look at the events link above, but that doesn't really tell me anything around how to create webhooks correctly -- which is currently my issue. And, I deliberately avoided looking into PactFlow exactly because I didn't want to run into something that the OSS broker does not support. I guess I'll change strategy and do not use Prometheus/Grafana in the end -- thank you in any way
m
maybe I’ve confused you, sorry
The screenshot you showed above is sending a non-get request to Pact Broker - not to prometheus. It should be possible to create a webhook in the Pact Broker that fires a request to prometheus
I’d use the CLI for now. Do you know the shape of the request (and headers etc. needed) to send a request to prometheus? I could help you write the CLI command that should get you on the way
a
Thank you. Can you please point me at where I can get into around using the CLI to create webhooks? And just to be clear: I need the pact broker to push notifications to another component...
m
Docs on webhooks in the thread above ^^
> And just to be clear: I need the pact broker to push notifications to another component yep, that’s how webhooks will work here so you’re on the right track
a
Thanks. I am looking at the CLI as you suggested, but description is pretty poor and therer are things I still do not get. I gather the line below tells the broker to send an event to a target defined in the URL parameter, is that the case? Also, do I have to specify the body of the request? How do I do it in that case? Do I also need to specify the event type in the body? Thank you for your help, as I said above documentation is pretty poor and I cannot find much around...
Copy code
pact-broker create-webhook URL -X, --request=METHOD -b, --broker-base-url=BROKER_BASE_URL
A bit of an update. I started using the CLI as you suggested, and after a bit of search I drafted a request in this way:
Copy code
docker run --rm --network="host" pactfoundation/pact-cli:latest pact-broker create_webhook <http://localhost:8080/notifications> -X POST -b <http://localhost:9292/webhooks> -u pactBrokerUsername -p pactBrokerUserPassword -d "{\"description\":\"Sendnotification-test\",\"provider\":{\"name\":\"bm\"},\"events\":[{\"name\":\"contract_content_changed\"}],\"request\":{\"method\":\"POST\",\"url\":\"http:localhost:8080/notifications\",\"headers\":{\"Accept\":\"application/json\"}}}" --contract-published
Now when I fire this, i get:
Copy code
PactBroker::Client::hal::ErrorResponseReturned - Error making request to <http://localhost:9292/webhooks> status=401
Not sure why I get a 401, I am providing the broker's credentials and the recipient app does not need any credentials. Also, I am using something similar to publish and verify a PACT and do not have any auth issues