0
votes

It is possible to configure Consul callback "POST" to a rest API every time that a service status is updated?

I've found "Watch" feature in documentation (https://www.consul.io/docs/dynamic-app-config/watches#http-endpoint), but seems like this feature is not to automatically Consul call some API when a services event is called.

Please, if someone know how to do this task, will be very thankful!

1
Consul watches will send a complete payload of the service being monitored to the configured watch destination. So, if you're watching a service, the watch will send the output of /v1/health/service/:service to the configured HTTP endpoint whenever the service is updated. If your HTTP server cannot parse that payload as-is, you will need to send the output to a script which modifies the request before POSTing it to the HTTP server. - Blake Covarrubias

1 Answers

0
votes

I’ve found a solution:

In agent command (to start Consul):

sudo consul agent --dev --client 0.0.0.0 --config-file ./path/consul-agent.json

In consul-agent.json file:

{
“watches”: [
{
“type”: “services”,
“handler_type”: “http”,
“http_handler_config”: {
“path”: “https://localhost/routetocall”,
“method”: “POST”,
“header”: { “Authentication”: [“something”] },
“timeout”: “10s”,
“tls_skip_verify”: true
}
}
]
}