Custom slack channel definition using single slack handler

Hi -

Hopefully this is the right place to post this. .

I’m trying to use a single slack handler to send slack messages to custom slack channels that is either defined in the entity’s labels or annotations. What I’m trying to do is this -

I have different entities that have a different slack_channel label/annotation defined. for instance, a production entity would go to #prod while a staging entity would go to #stage (so they would have their slack_channel set to #prod and #stage respectively). I would like to use a single slack handler to simplify management of it since I would eventually have about > 30 entities that has 30 different slack_channel definitions.

Right now, I have the slack handler doing something like this for the command :

type: Handler
api_version: core/v2
  created_by: admin
  name: slack
  namespace: default
  command: sensu-slack-handler -c '{{ .Entity.Labels.slack_channel }}'
  filters: null
  handlers: null
  - sensu-slack-handler
  secrets: null
  timeout: 0
  type: pipe

I have a check_ssl check that uses this handler so that on a warn/crit it’ll send the appropriate slack notification out.

The issue I’m running into is in the logs, the check runs, but the slack handler fails due to “cannot find channel” error :

{"check_name":"check_ssl_cert","check_namespace":"default","component":"pipeline/legacy","entity_name":"prod_host","entity_namespace":"default","event_id":"717efa3b-f2ca-4ea8-8565-b164896891e3","level":"info","msg":"event pipe handler executed","output":"Usage:\n  sensu-slack-handler [flags]\n  sensu-slack-handler [command]\n\nAvailable Commands:\n  help        Help about any command\n  version     Print the version number of this plugin\n\nFlags:\n  -c, --channel string                The channel to post messages to (default \"#general\")\n  -t, --description-template string   The Slack notification output template, in Golang text/template format (default \"{{ .Check.Output }}\")\n  -h, --help                          help for sensu-slack-handler\n  -i, --icon-url string               A URL to an image to use as the user avatar (default \"\")\n  -u, --username string               The username that messages will be sent as (default \"sensu\")\n  -w, --webhook-url string            The webhook url to send messages to\n\nUse \"sensu-slack-handler [command] --help\" for more information about a command.\n\nError executing sensu-slack-handler: error executing handler: Failed to send Slack message: channel_not_found\n","pipeline":"legacy-pipeline","pipeline_workflow":"legacy-pipeline-workflow-slack","status":1,"time":"2021-12-30T09:19:27Z"}

Not sure if the info from the template-toolkit-command can be used in the handler definition or not but any pointers will be greatly appreciated. I am really trying to not define 30 or more slack handlers if at all possible.

I’m using the latest official Sensu-Go docker container.

Thanks in advance.