adding option to skip rebooting during weekends

This commit is contained in:
Frank Vissing
2018-05-15 11:57:38 +02:00
parent b27aaa1b0c
commit 793e1a77d5
2 changed files with 17 additions and 9 deletions

View File

@@ -70,6 +70,7 @@ Flags:
--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-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

View File

@@ -26,15 +26,16 @@ var (
version = "unreleased"
// Command line flags
period time.Duration
dsNamespace string
dsName string
lockAnnotation string
prometheusURL string
alertFilter *regexp.Regexp
rebootSentinel string
slackHookURL string
slackUsername string
period time.Duration
dsNamespace string
dsName string
lockAnnotation string
prometheusURL string
alertFilter *regexp.Regexp
rebootSentinel string
slackHookURL string
slackUsername string
noWeekendReboot bool
// Metrics
rebootRequiredGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -73,6 +74,7 @@ func main() {
"slack hook URL for reboot notfications")
rootCmd.PersistentFlags().StringVar(&slackUsername, "slack-username", "kured",
"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 {
log.Fatal(err)
@@ -122,6 +124,11 @@ func rebootRequired() bool {
func rebootBlocked() bool {
if prometheusURL != "" {
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 {
log.Warnf("Reboot blocked: prometheus query error: %v", err)
return true