diff --git a/pkg/client/configfile.go b/pkg/client/configfile.go index ccf89f9fc..4c7171dae 100644 --- a/pkg/client/configfile.go +++ b/pkg/client/configfile.go @@ -171,7 +171,7 @@ func (c *Client) reloadConfiguration(msg string) { c.Print("==> Configuration Reloaded!") if failed := c.checkPlex(); failed { - _, _ = ui.Info(Title, "Configuration Reloaded!\nERROOR: Plex DISABLED due to bad config.") + _, _ = ui.Info(Title, "Configuration Reloaded!\nERROR: Plex DISABLED due to bad config.") } else { _, _ = ui.Info(Title, "Configuration Reloaded!") } diff --git a/pkg/client/start.go b/pkg/client/start.go index 2c1a9722c..ea93d7b6d 100644 --- a/pkg/client/start.go +++ b/pkg/client/start.go @@ -206,7 +206,7 @@ func (c *Client) run(newConfig bool) error { func (c *Client) checkPlex() bool { var err error - if c.Config.Plex != nil { + if c.Config.Plex != nil && c.Config.Plex.URL != "" && c.Config.Plex.Token != "" { if err = c.Config.Plex.Validate(); err != nil { c.Errorf("plex config: %v (plex DISABLED)", err) c.Config.Plex = nil diff --git a/pkg/client/tray.go b/pkg/client/tray.go index adf78d224..f509c0c62 100644 --- a/pkg/client/tray.go +++ b/pkg/client/tray.go @@ -161,21 +161,21 @@ func (c *Client) watchGuiChannels() { } } -func (c *Client) watchNotifiarrMenu() { +func (c *Client) watchNotifiarrMenu() { //nolint:cyclop for { select { case <-c.menu["snap_log"].Clicked(): c.logSnaps() case <-c.menu["svcs_log"].Clicked(): c.Printf("[user requested] Checking services and logging results.") - data, _ := json.MarshalIndent(c.Config.Services.RunChecks(), "", " ") + data, _ := json.MarshalIndent(c.Config.Services.RunChecks("user"), "", " ") c.Print("Payload (log only):", string(data)) case <-c.menu["svcs_prod"].Clicked(): c.Printf("[user requested] Checking services and sending results to Notifiarr.") - c.Config.Services.SendResults(c.Config.Services.RunChecks(), notifiarr.ProdURL) + c.Config.Services.SendResults(c.Config.Services.RunChecks("user"), notifiarr.ProdURL) case <-c.menu["svcs_test"].Clicked(): c.Printf("[user requested] Checking services and sending results to Notifiarr Test.") - c.Config.Services.SendResults(c.Config.Services.RunChecks(), notifiarr.TestURL) + c.Config.Services.SendResults(c.Config.Services.RunChecks("user"), notifiarr.TestURL) case <-c.menu["plex_test"].Clicked(): c.sendPlexSessions(notifiarr.TestURL) case <-c.menu["snap_test"].Clicked(): diff --git a/pkg/notifiarr/notifiarr.go b/pkg/notifiarr/notifiarr.go index 33724956b..3d7a36fdf 100644 --- a/pkg/notifiarr/notifiarr.go +++ b/pkg/notifiarr/notifiarr.go @@ -105,7 +105,7 @@ func (c *Config) SendMeta(eventType, url string, hook *plex.Webhook, wait time.D go func() { for err := range rep { if err != nil { // maybe move this out of this method? - c.Errorf("metadata: %v", err) + c.Errorf("Building Metadata: %v", err) } } }() @@ -130,7 +130,7 @@ func (c *Config) SendMeta(eventType, url string, hook *plex.Webhook, wait time.D var err error if payload.Plex, err = c.Plex.GetSessions(); err != nil { - return nil, nil, fmt.Errorf("getting sessions: %w", err) + rep <- fmt.Errorf("getting sessions: %w", err) } wg.Wait() diff --git a/pkg/services/services.go b/pkg/services/services.go index 9ab0c370a..61d8163f4 100644 --- a/pkg/services/services.go +++ b/pkg/services/services.go @@ -67,8 +67,10 @@ const ( // Results is sent to Notifiarr. type Results struct { - Type string `json:"eventType"` - Svcs []*CheckResult `json:"services"` + Type string `json:"eventType"` + What string `json:"what"` + Interval float64 `json:"interval"` + Svcs []*CheckResult `json:"services"` } // CheckResult represents the status of a service. @@ -134,7 +136,7 @@ func (c *Config) runServiceChecker() { for { select { case <-ticker.C: - c.SendResults(c.RunChecks(), notifiarr.ProdURL) + c.SendResults(c.RunChecks("timer"), notifiarr.ProdURL) case <-c.stopChan: return } @@ -228,7 +230,7 @@ func (c *Config) collectApps() []*Service { } // RunChecks forces all checks to run right now. -func (c *Config) RunChecks() *Results { +func (c *Config) RunChecks(what string) *Results { c.mu.Lock() defer c.mu.Unlock() @@ -254,7 +256,7 @@ func (c *Config) RunChecks() *Results { }) } - return &Results{Type: "service_checks", Svcs: svcs} + return &Results{Type: "service_checks", Svcs: svcs, What: what, Interval: c.Interval.Seconds()} } // SendResults sends a set of Results to Notifiarr. diff --git a/pkg/snapshot/raid.go b/pkg/snapshot/raid.go index d12449495..16f115afc 100644 --- a/pkg/snapshot/raid.go +++ b/pkg/snapshot/raid.go @@ -19,6 +19,7 @@ func (s *Snapshot) getRaidData(ctx context.Context, useSudo, run bool) error { return s.getRaidMegaCLI(ctx, useSudo) } +// getRaidMDstat parses this: /* four drive raid1: $ cat /proc/mdstat Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] @@ -27,10 +28,9 @@ md1 : active raid1 sdd2[3] sdb2[1] sdc2[2] sda2[0] bitmap: 3/4 pages [12KB], 65536KB chunk unused devices: */ - func (s *Snapshot) getRaidMDstat() { b, _ := ioutil.ReadFile("/proc/mdstat") - // Remove the first line "Personalities" and replace the rest of the newlines with spaces. + // Remove the first line "Personalities". if i := bytes.IndexByte(b, '\n'); i != -1 && len(b) > i+1 { b = b[i+1:] } @@ -38,7 +38,7 @@ func (s *Snapshot) getRaidMDstat() { s.Raid.MDstat = string(b) } -/* +/* getRaidMegaCLI parses this: [root@server]# MegaCli -LDInfo -Lall -aALL Adapter 0 -- Virtual Drive Information: Virtual Drive: 0 (Target Id: 0) @@ -58,13 +58,11 @@ Default Access Policy: Read/Write Current Access Policy: Read/Write Disk Cache Policy : Enabled Encryption Type : None -Is VD Cached: No +Is VD Cached: No. */ - func (s *Snapshot) getRaidMegaCLI(ctx context.Context, useSudo bool) error { - // The megacli code is barely tested. - megacli, err := exec.LookPath("MegaCli") - for _, s := range []string{"MegaCli64", "megacli", "megacli64"} { + megacli, err := exec.LookPath("MegaCli64") + for _, s := range []string{"MegaCli", "megacli", "megacli64"} { if err == nil { break } diff --git a/pkg/ui/dlgs.go b/pkg/ui/dlgs.go index 222a8ce68..7e959cd52 100644 --- a/pkg/ui/dlgs.go +++ b/pkg/ui/dlgs.go @@ -10,7 +10,7 @@ func Warning(title, msg string) (bool, error) { return true, nil } - return dlgs.Warning(title, msg) //nolint:nolint,wrapcheck + return dlgs.Warning(title, msg) //nolint:wrapcheck } // Error wraps dlgs.Error. @@ -19,7 +19,7 @@ func Error(title, msg string) (bool, error) { return true, nil } - return dlgs.Error(title, msg) //nolint:nolint,wrapcheck + return dlgs.Error(title, msg) //nolint:wrapcheck } // Info wraps dlgs.Info. @@ -28,7 +28,7 @@ func Info(title, msg string) (bool, error) { return true, nil } - return dlgs.Info(title, msg) //nolint:nolint,wrapcheck + return dlgs.Info(title, msg) //nolint:wrapcheck } // Entry wraps dlgs.Entry. @@ -37,7 +37,7 @@ func Entry(title, msg, val string) (string, bool, error) { return val, true, nil } - return dlgs.Entry(title, msg, val) //nolint:nolint,wrapcheck + return dlgs.Entry(title, msg, val) //nolint:wrapcheck } // Question wraps dlgs.Question. @@ -46,5 +46,5 @@ func Question(title, text string, defaultCancel bool) (bool, error) { return true, nil } - return dlgs.Question(title, text, defaultCancel) //nolint:nolint,wrapcheck + return dlgs.Question(title, text, defaultCancel) //nolint:wrapcheck } diff --git a/pkg/ui/ui_other.go b/pkg/ui/ui_other.go index c66cae2eb..6a75be11f 100644 --- a/pkg/ui/ui_other.go +++ b/pkg/ui/ui_other.go @@ -25,7 +25,7 @@ func StartCmd(c string, v ...string) error { cmd.Stdout = ioutil.Discard cmd.Stderr = ioutil.Discard - return cmd.Start() //nolint:nolint,wrapcheck + return cmd.Start() //nolint:wrapcheck } // ErrUnsupported is just an error. diff --git a/pkg/ui/ui_windows.go b/pkg/ui/ui_windows.go index d7c7fa82f..f81fd4f41 100644 --- a/pkg/ui/ui_windows.go +++ b/pkg/ui/ui_windows.go @@ -32,7 +32,7 @@ func StartCmd(c string, v ...string) error { cmd.Stderr = ioutil.Discard cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} - return cmd.Start() //nolint:nolint,wrapcheck + return cmd.Start() //nolint:wrapcheck } // OpenCmd opens anything. diff --git a/settings.sh b/settings.sh index f49bf93ea..d282388ea 100644 --- a/settings.sh +++ b/settings.sh @@ -14,7 +14,7 @@ REPO="Go-Lift-TV/notifiarr" HBREPO="golift/homebrew-mugs" MAINT="David Newhall II " DESC="Unified Client for Notifiarr.com" -GOLANGCI_LINT_ARGS="--enable-all -D exhaustivestruct,nlreturn,forbidigo,cyclop" +GOLANGCI_LINT_ARGS="--enable-all -D exhaustivestruct,nlreturn,forbidigo,cyclop,godot" # Example must exist at examples/$CONFIG_FILE.example CONFIG_FILE="notifiarr.conf" LICENSE="MIT"