diff options
| author | Paul Buetow <paul@buetow.org> | 2024-05-02 00:41:48 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-05-02 00:41:48 +0300 |
| commit | 04f43eb1f910b6b48e38532f5d7cb0055db424a3 (patch) | |
| tree | 9dc9f37ac1dcff7b6ed17848640ba6081118e949 | |
| parent | 038546765611dbb3dfab1dd4f1b4a6ff6ac1d3e6 (diff) | |
add -force flag
| -rw-r--r-- | cmd/gogios/main.go | 5 | ||||
| -rw-r--r-- | internal/run.go | 4 | ||||
| -rw-r--r-- | internal/state.go | 5 |
3 files changed, 8 insertions, 6 deletions
diff --git a/cmd/gogios/main.go b/cmd/gogios/main.go index 715a2a5..2d6f536 100644 --- a/cmd/gogios/main.go +++ b/cmd/gogios/main.go @@ -9,12 +9,13 @@ import ( "codeberg.org/snonux/gogios/internal" ) -const versionStr = "v1.0.3" +const versionStr = "v1.1.0-develop" func main() { configFile := flag.String("cfg", "/etc/gogios.json", "The config file") timeout := flag.Int("timeout", 5, "Global timeout in minutes") renotify := flag.Bool("renotify", false, "Renotify all unhandled") + force := flag.Bool("force", false, "Force sending out status") version := flag.Bool("version", false, "Display version") flag.Parse() @@ -28,5 +29,5 @@ func main() { time.Duration(*timeout)*time.Minute) defer cancel() - internal.Run(ctx, *configFile, *renotify) + internal.Run(ctx, *configFile, *renotify, *force) } diff --git a/internal/run.go b/internal/run.go index 00bb129..01f5bae 100644 --- a/internal/run.go +++ b/internal/run.go @@ -5,7 +5,7 @@ import ( "log" ) -func Run(ctx context.Context, configFile string, renotify bool) { +func Run(ctx context.Context, configFile string, renotify, force bool) { conf, err := newConfig(configFile) if err != nil { log.Fatal(err) @@ -26,7 +26,7 @@ func Run(ctx context.Context, configFile string, renotify bool) { notifyError(conf, err) } - if subject, body, doNotify := state.report(renotify); doNotify { + if subject, body, doNotify := state.report(renotify, force); doNotify { if err := notify(conf, subject, body); err != nil { log.Println("error:", err) } diff --git a/internal/state.go b/internal/state.go index f7e03cf..1f92212 100644 --- a/internal/state.go +++ b/internal/state.go @@ -94,7 +94,7 @@ func (s state) persist() error { return os.WriteFile(s.stateFile, jsonData, os.ModePerm) } -func (s state) report(renotify bool) (string, string, bool) { +func (s state) report(renotify, force bool) (string, string, bool) { var sb strings.Builder sb.WriteString("This is the recent Gogios report!\n\n") @@ -117,7 +117,8 @@ func (s state) report(renotify bool) (string, string, bool) { subject := fmt.Sprintf("GOGIOS Report [C:%d W:%d U:%d OK:%d]", numCriticals, numWarnings, numUnknown, numOK) - return subject, sb.String(), changed || (renotify && hasUnhandled) + doNotify := force || (changed || (renotify && hasUnhandled)) + return subject, sb.String(), doNotify } func (s state) reportChanged(sb *strings.Builder) (changed bool) { |
