Search code examples
consulnomadhashicorp

Consul configuration to automatically callback (on event) rest API


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!


Solution

  • 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
    }
    }
    ]
    }