Dynamic Slack Webhook Option #1520
-
Hi, is it possible to create an enhancement in ElastAlert2 where the slack_webhook_url changes based on the value of the source.ip field? For example:
I’ve tried a few scripts, but the alert only gets sent to the webhook URL specified in the main rule configuration. Or is there any other way to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I would think this is possible. Show us the enchancement code you tried; perhaps someone will spot a problem. |
Beta Was this translation helpful? Give feedback.
-
I tried a couple of enhancement codes: The first code should add an extra webhook to send alerts to multiple Slack channels if data_stream.namespace is value is "test":
The second enhancement I tried is to replace an already existing webhook:
|
Beta Was this translation helpful? Give feedback.
-
Slack alerter URLs are initialized when ElastAlert 2 starts up and loads the rule into memory. At that time the Alerter class is initialized with the configured URL. So changing the rule object's slack URL at runtime won't make a difference since the alerter instance was already initialized. The Slack alerter supports dynamically changing rooms/channels, but not the actual Slack webhook itself. To do what you're attempting would require manipulating the URL in the alerter instance, not the rule instance. Ex:
Also, the slack_webhook_url is always converted to a list, so don't try assigned a raw string to that property. Finally, doing this is risky because the next alert will be using your new URL, even if it didn't match your conditions. Your enhancement would need to always set the desired URL and never rely on what was provided in the rule yaml file. |
Beta Was this translation helpful? Give feedback.
Slack alerter URLs are initialized when ElastAlert 2 starts up and loads the rule into memory. At that time the Alerter class is initialized with the configured URL. So changing the rule object's slack URL at runtime won't make a difference since the alerter instance was already initialized.
The Slack alerter supports dynamically changing rooms/channels, but not the actual Slack webhook itself.
To do what you're attempting would require manipulating the URL in the alerter instance, not the rule instance. Ex:
Also, the slack_webhook_url is …