Merge pull request #87 from Nighthawk22/master

Added slack channel name configuration
This commit is contained in:
Bryan Boreham
2019-11-26 16:50:24 +00:00
committed by GitHub
4 changed files with 14 additions and 7 deletions
+1
View File
@@ -82,6 +82,7 @@ Flags:
--prometheus-url string Prometheus instance to probe for active alerts
--reboot-days strings only reboot on these days (default [su,mo,tu,we,th,fr,sa])
--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")
--start-time string only reboot after this time of day (default "0:00")
+5 -2
View File
@@ -37,6 +37,7 @@ var (
rebootSentinel string
slackHookURL string
slackUsername string
slackChannel string
podSelectors []string
rebootDays []string
@@ -81,6 +82,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")
@@ -227,7 +230,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)
}
}
@@ -252,7 +255,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)
}
}
+1
View File
@@ -59,5 +59,6 @@ spec:
# - --reboot-sentinel=/var/run/reboot-required
# - --slack-hook-url=https://hooks.slack.com/...
# - --slack-username=prod
# - --slack-channel=alerting
# - --start-time=0:00
# - --time-zone=UTC
+7 -5
View File
@@ -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))
}