From ca051cd1cc883ec2c0f5d0af8101abb829758c38 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Thu, 28 Jun 2018 21:49:52 +0200 Subject: [PATCH] fixes --- README.md | 4 ++-- cmd/{check.go => cmd_check.go} | 0 cmd/{debug.go => cmd_debug.go} | 4 ++-- cmd/{root.go => cmd_root.go} | 0 cmd/{version.go => cmd_version.go} | 0 cmd/{watch.go => cmd_watch.go} | 0 cmd/config.go | 3 ++- core/checkrunner.go | 4 +++- core/healthcheck_measurement_minmax.go | 13 +++++++++---- core/healthchecks.go | 10 +++------- 10 files changed, 21 insertions(+), 17 deletions(-) rename cmd/{check.go => cmd_check.go} (100%) rename cmd/{debug.go => cmd_debug.go} (95%) rename cmd/{root.go => cmd_root.go} (100%) rename cmd/{version.go => cmd_version.go} (100%) rename cmd/{watch.go => cmd_watch.go} (100%) diff --git a/README.md b/README.md index e6278ab..af37e1a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Cross platform command line application to run health checks against sensor stat This tool lets you automatically check if senseBoxes are still runnning correctly, and when that's not the case, notifies you. Currently, email notifications are implemented, but other transports can be added easily. -Implemented health checks are [described below](#possible-values-for-defaulthealthchecksevents), and new ones can be added just as easily (given some knowledge of programming). +Implemented health checks are [described below](#available-healthchecks), and new ones can be added just as easily (given some knowledge of programming). The tool has multiple modes of operation: @@ -61,7 +61,7 @@ Contributions are welcome! Check out the following locations for plugging in new functionality: - new notification transports: [core/notifiers.go](core/notifiers.go) -- new health checks: [core/healthcheck*.go](core/healtchecks.go) +- new health checks: [core/healthcheck*.go](core/healthchecks.go) - new commands: [cmd/](cmd/) Before committing and submitting a pull request, please run `go fmt ./ cmd/ core/`. diff --git a/cmd/check.go b/cmd/cmd_check.go similarity index 100% rename from cmd/check.go rename to cmd/cmd_check.go diff --git a/cmd/debug.go b/cmd/cmd_debug.go similarity index 95% rename from cmd/debug.go rename to cmd/cmd_debug.go index ad1232a..866e281 100644 --- a/cmd/debug.go +++ b/cmd/cmd_debug.go @@ -55,11 +55,11 @@ var debugNotificationsCmd = &cobra.Command{ host, _ := os.Hostname() err = n.Submit(core.Notification{ - Subject: "Test notification from opeSenseMap notifier", + Subject: "Test notification from openSenseMap notifier", Body: fmt.Sprintf("Your notification set up on %s is working fine!", host), }) if err != nil { - notLog.Warnf("could not submit test notification for %s notifier!", transport) + notLog.Warnf("could not submit test notification for %s notifier: %s", transport, err) continue } notLog.Info("Test notification (successfully?) submitted, check the specified inbox") diff --git a/cmd/root.go b/cmd/cmd_root.go similarity index 100% rename from cmd/root.go rename to cmd/cmd_root.go diff --git a/cmd/version.go b/cmd/cmd_version.go similarity index 100% rename from cmd/version.go rename to cmd/cmd_version.go diff --git a/cmd/watch.go b/cmd/cmd_watch.go similarity index 100% rename from cmd/watch.go rename to cmd/cmd_watch.go diff --git a/cmd/config.go b/cmd/config.go index 450e273..83e0b0b 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -4,9 +4,10 @@ import ( "os" "strings" - "github.com/noerw/osem_notify/utils" log "github.com/sirupsen/logrus" "github.com/spf13/viper" + + "github.com/noerw/osem_notify/utils" ) // initConfig reads in config file and ENV variables if set. diff --git a/core/checkrunner.go b/core/checkrunner.go index ac4db93..5b26b26 100644 --- a/core/checkrunner.go +++ b/core/checkrunner.go @@ -42,7 +42,9 @@ func (results BoxCheckResults) Log() { countErr++ } } - if countErr == 0 { + if len(boxResults) == 0 { + boxLog.Infof("%s: no checks defined", box.Name) + } else if countErr == 0 { boxLog.Infof("%s: all is fine!", box.Name) } } diff --git a/core/healthcheck_measurement_minmax.go b/core/healthcheck_measurement_minmax.go index 441d3fd..fa71b59 100644 --- a/core/healthcheck_measurement_minmax.go +++ b/core/healthcheck_measurement_minmax.go @@ -5,8 +5,13 @@ import ( "strconv" ) +const ( + nameMin = "measurement_min" + nameMax = "measurement_max" +) + var checkMeasurementMin = checkType{ - name: "measurement_min", + name: nameMin, toString: func(r CheckResult) string { return fmt.Sprintf("Sensor %s (%s) reads low value of %s", r.TargetName, r.Target, r.Value) }, @@ -14,7 +19,7 @@ var checkMeasurementMin = checkType{ } var checkMeasurementMax = checkType{ - name: "measurement_min", + name: nameMax, toString: func(r CheckResult) string { return fmt.Sprintf("Sensor %s (%s) reads high value of %s", r.TargetName, r.Target, r.Value) }, @@ -41,8 +46,8 @@ func validateMeasurementMinMax(e NotifyEvent, s Sensor, b Box) (CheckResult, err return result, err } - if e.Type == eventMeasurementValMax && val > thresh || - e.Type == eventMeasurementValMin && val < thresh { + if e.Type == nameMax && val > thresh || + e.Type == nameMin && val < thresh { result.Status = CheckErr } diff --git a/core/healthchecks.go b/core/healthchecks.go index 76ce74f..3981cb2 100644 --- a/core/healthchecks.go +++ b/core/healthchecks.go @@ -9,13 +9,9 @@ import ( ) const ( - CheckOk = "OK" - CheckErr = "FAILED" - eventMeasurementAge = "measurement_age" - eventMeasurementValMin = "measurement_min" - eventMeasurementValMax = "measurement_max" - eventMeasurementValFaulty = "measurement_faulty" - eventTargetAll = "all" // if event.Target is this value, all sensors will be checked + CheckOk = "OK" + CheckErr = "FAILED" + eventTargetAll = "all" // if event.Target is this value, all sensors will be checked ) type checkType = struct {