Commit 793e1a77 authored by Frank Vissing's avatar Frank Vissing
Browse files

adding option to skip rebooting during weekends

parent b27aaa1b
...@@ -70,6 +70,7 @@ Flags: ...@@ -70,6 +70,7 @@ Flags:
--reboot-sentinel string path to file whose existence signals need to reboot (default "/var/run/reboot-required") --reboot-sentinel string path to file whose existence signals need to reboot (default "/var/run/reboot-required")
--slack-hook-url string slack hook URL for reboot notfications --slack-hook-url string slack hook URL for reboot notfications
--slack-username string slack username for reboot notfications (default "kured") --slack-username string slack username for reboot notfications (default "kured")
--no-weekends-reboot bool option to not restart during weekends (default "false")
``` ```
### Reboot Sentinel File & Period ### Reboot Sentinel File & Period
......
...@@ -26,15 +26,16 @@ var ( ...@@ -26,15 +26,16 @@ var (
version = "unreleased" version = "unreleased"
// Command line flags // Command line flags
period time.Duration period time.Duration
dsNamespace string dsNamespace string
dsName string dsName string
lockAnnotation string lockAnnotation string
prometheusURL string prometheusURL string
alertFilter *regexp.Regexp alertFilter *regexp.Regexp
rebootSentinel string rebootSentinel string
slackHookURL string slackHookURL string
slackUsername string slackUsername string
noWeekendReboot bool
// Metrics // Metrics
rebootRequiredGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ rebootRequiredGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
...@@ -73,6 +74,7 @@ func main() { ...@@ -73,6 +74,7 @@ func main() {
"slack hook URL for reboot notfications") "slack hook URL for reboot notfications")
rootCmd.PersistentFlags().StringVar(&slackUsername, "slack-username", "kured", rootCmd.PersistentFlags().StringVar(&slackUsername, "slack-username", "kured",
"slack username for reboot notfications") "slack username for reboot notfications")
rootCmd.PersistentFlags().BoolVar(&noWeekendReboot, "no-weekends-reboot", false, "if true no reboots will be performed during weekends")
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
log.Fatal(err) log.Fatal(err)
...@@ -122,6 +124,11 @@ func rebootRequired() bool { ...@@ -122,6 +124,11 @@ func rebootRequired() bool {
func rebootBlocked() bool { func rebootBlocked() bool {
if prometheusURL != "" { if prometheusURL != "" {
alertNames, err := alerts.PrometheusActiveAlerts(prometheusURL, alertFilter) alertNames, err := alerts.PrometheusActiveAlerts(prometheusURL, alertFilter)
weekday := time.Now().Weekday()
if noWeekendReboot && (int(weekday) == 0 || int(weekday) == 6) {
log.Warnf("Reboot blocked: day of week: %v",weekday)
return true
}
if err != nil { if err != nil {
log.Warnf("Reboot blocked: prometheus query error: %v", err) log.Warnf("Reboot blocked: prometheus query error: %v", err)
return true return true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment