Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: allow notifying multiple Slack channels #41

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions src/slack-notifications/slack-notifications-command.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ object NotificationCommand "slack-notifications-command" {
var plugin_output_max_length = Math.round(plugin_output_max_length_from_config)
var slack_webhook_url = macro("$slack_notifications_webhook_url$")
var slack_proxy = macro("$slack_notifications_proxy$")
var slack_channel = macro("$slack_notifications_channel$")
var slack_channels = macro("$slack_notifications_channels$")
var slack_botname = macro("$slack_notifications_botname$")
var icinga2_base_url = macro("$slack_notifications_icinga2_base_url$")
var slack_icon_dictionary = macro("$slack_notifications_icon_dictionary$")
var slack_color_dictionary = macro("$slack_notifications_color_dictionary$")
var configuration = {
"vars.slack_notifications_plugin_output_max_length" = plugin_output_max_length,
"vars.slack_notifications_webhook_url" = slack_webhook_url,
"vars.slack_notifications_channel" = slack_channel,
"vars.slack_notifications_channels" = slack_channels,
"vars.slack_notifications_proxy" = slack_proxy,
"vars.slack_notifications_botname" = slack_botname,
"vars.slack_notifications_icinga2_base_url" = icinga2_base_url
Expand Down Expand Up @@ -159,26 +159,30 @@ object NotificationCommand "slack-notifications-command" {
log(LogDebug, "slack-notifications", attachments)

log(LogDebug, "slack-notifications", "Generating notification command")
var payload_dictionary = {
"channel" = slack_channel,
"username" = slack_botname,
"attachments" = attachments
}
var payload_json = Json.encode(payload_dictionary)
var slack_payload = "payload=" + payload_json
var payload_argument = escape_shell_arg(slack_payload)
var slack_webhook_url_argument = escape_shell_arg(slack_webhook_url)
var cmd = [
"curl",
cmd_proxy,
"--fail",
"--connect-timeout", "30",
"--max-time", "60",
"--silent", "--show-error",
"-X", "POST",
"--data-urlencode", payload_argument,
slack_webhook_url_argument
]

for (slack_channel in slack_channels) {
var payload_dictionary = {
"channel" = slack_channel,
"username" = slack_botname,
"attachments" = attachments
}
var payload_json = Json.encode(payload_dictionary)
var slack_payload = "payload=" + payload_json
var payload_argument = escape_shell_arg(slack_payload)
var cmd = [
"curl",
cmd_proxy,
"--fail",
"--connect-timeout", "30",
"--max-time", "60",
"--silent", "--show-error",
"-X", "POST",
"--data-urlencode", payload_argument,
slack_webhook_url_argument,
";"
]
}
var notification_command = cmd.join(" ")
log(LogDebug, "slack-notifications", "Generated notification command successfully: " + notification_command)

Expand Down