Alert handlers through API

In Kapacitor, I want to create a slack alert handler through the CLI or API. This seems to apply ok but I can’t get alerts and I get this in the logs:

[alert] 2017/04/03 19:49:50 E! failed to send event to Slack service is not enabled
[net_alert:alert2] 2017/04/03 19:49:50 E! failed to send event to Slack service is not enabled

Is it possible to specify alerts without configuring them in the config file? Any idea what I might be missing? I did have “enabled”: true in my alert handler definition.

@sloach This feature was just added to kapacitor. There is some documentation of the API here.

Right, the problem I’m having is it doesn’t seem to work. I can setup my alert handler through Kapacitor and it looks fine, but I get that error message I pasted in my original post.

I spent some more time looking into this. It seems that only part of the handler config is exposed through the API. For Slack, the channel, username, and icon-emoji are exposed through the API, but the URL and enabled flat and other config is not.

Can anyone explain the reason for this? I was hoping to be able to use multiple different slack handlers with different destinations but it looks like I might have to use multiple instances of Kapacitor to achieve this.

@sloach I dont think thats the case. Can you post where you are seeing that?

In the Handle() function, you can see that it only sends the Handle, Channel and IconEmoji from the HandlerConfig:

And, in fact, that is all that exists for the HandlerConfig:

The enabled flag, URL, etc come from the config file but it doesn’t seem to be possible to specify these in the Handler object via the CLI/API.

Happy to be corrected if I am missing something.

Yeah there are two different configs.

  1. The configuration for the Slack service itself.
  2. The config for each handler.

The Slack service config is set via the kapacitor.conf file or via the /kapacitor/v1/config/slack API endpoint.

The handlers config doesn’t effect the aspects of the service itself. This is because the handlers consume the service, meaning you can have multiple Slack handlers to that go to different channels etc, but they all use the same Slack service.