From d1315c691ec1e9810fae1fc4bfa1525f73cdeaea Mon Sep 17 00:00:00 2001 From: Maximilian Zollneritsch Date: Wed, 11 Sep 2019 13:59:09 +0200 Subject: [PATCH 1/2] Added slack channel name configuration --- cmd/kured/main.go | 7 +++++-- pkg/notifications/slack/slack.go | 12 +++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/kured/main.go b/cmd/kured/main.go index cffa09d..1d6ee0d 100644 --- a/cmd/kured/main.go +++ b/cmd/kured/main.go @@ -36,6 +36,7 @@ var ( rebootSentinel string slackHookURL string slackUsername string + slackChannel string podSelectors []string // Metrics @@ -75,6 +76,8 @@ func main() { "slack hook URL for reboot notfications") rootCmd.PersistentFlags().StringVar(&slackUsername, "slack-username", "kured", "slack username for reboot notfications") + rootCmd.PersistentFlags().StringVar(&slackChannel, "slack-channel", "", + "slack channel for reboot notfications") rootCmd.PersistentFlags().StringArrayVar(&podSelectors, "blocking-pod-selector", nil, "label selector identifying pods whose presence should prevent reboots") @@ -212,7 +215,7 @@ func drain(nodeID string) { log.Infof("Draining node %s", nodeID) if slackHookURL != "" { - if err := slack.NotifyDrain(slackHookURL, slackUsername, nodeID); err != nil { + if err := slack.NotifyDrain(slackHookURL, slackUsername, slackChannel, nodeID); err != nil { log.Warnf("Error notifying slack: %v", err) } } @@ -237,7 +240,7 @@ func commandReboot(nodeID string) { log.Infof("Commanding reboot") if slackHookURL != "" { - if err := slack.NotifyReboot(slackHookURL, slackUsername, nodeID); err != nil { + if err := slack.NotifyReboot(slackHookURL, slackUsername, slackChannel, nodeID); err != nil { log.Warnf("Error notifying slack: %v", err) } } diff --git a/pkg/notifications/slack/slack.go b/pkg/notifications/slack/slack.go index 9af0b11..30ac4c5 100644 --- a/pkg/notifications/slack/slack.go +++ b/pkg/notifications/slack/slack.go @@ -15,12 +15,14 @@ var ( type body struct { Text string `json:"text,omitempty"` Username string `json:"username,omitempty"` + Channel string `json:"channel,omitempty"` } -func notify(hookURL, username, message string) error { +func notify(hookURL, username, channel, message string) error { msg := body{ Text: message, Username: username, + Channel: channel, } var buf bytes.Buffer @@ -41,10 +43,10 @@ func notify(hookURL, username, message string) error { return nil } -func NotifyDrain(hookURL, username, nodeID string) error { - return notify(hookURL, username, fmt.Sprintf("Draining node %s", nodeID)) +func NotifyDrain(hookURL, username, channel, nodeID string) error { + return notify(hookURL, username, channel, fmt.Sprintf("Draining node %s", nodeID)) } -func NotifyReboot(hookURL, username, nodeID string) error { - return notify(hookURL, username, fmt.Sprintf("Rebooting node %s", nodeID)) +func NotifyReboot(hookURL, username, channel, nodeID string) error { + return notify(hookURL, username, channel, fmt.Sprintf("Rebooting node %s", nodeID)) } From 7944fd26398931ee513daea11afc64eeed0fed5a Mon Sep 17 00:00:00 2001 From: Maximilian Zollneritsch Date: Wed, 11 Sep 2019 14:03:13 +0200 Subject: [PATCH 2/2] Updated readme and daemonset with slack channel parameter --- README.md | 1 + kured-ds.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 4e01df3..78c5764 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Flags: --period duration reboot check period (default 1h0m0s) --prometheus-url string Prometheus instance to probe for active alerts --reboot-sentinel string path to file whose existence signals need to reboot (default "/var/run/reboot-required") + --slack-channel string slack channel for reboot notfications --slack-hook-url string slack hook URL for reboot notfications --slack-username string slack username for reboot notfications (default "kured") ``` diff --git a/kured-ds.yaml b/kured-ds.yaml index da8363b..42879f3 100644 --- a/kured-ds.yaml +++ b/kured-ds.yaml @@ -57,3 +57,4 @@ spec: # - --reboot-sentinel=/var/run/reboot-required # - --slack-hook-url=https://hooks.slack.com/... # - --slack-username=prod +# - --slack-channel=alerting