Skip to content

Commit

Permalink
Minor services payload changes and a bug fix. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall authored Mar 30, 2021
1 parent cef707a commit 475b05a
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/client/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions pkg/notifiarr/notifiarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}()
Expand All @@ -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()
Expand Down
12 changes: 7 additions & 5 deletions pkg/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()

Expand All @@ -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.
Expand Down
14 changes: 6 additions & 8 deletions pkg/snapshot/raid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -27,18 +28,17 @@ md1 : active raid1 sdd2[3] sdb2[1] sdc2[2] sda2[0]
bitmap: 3/4 pages [12KB], 65536KB chunk
unused devices: <none>
*/

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:]
}

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)
Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/ui/dlgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion pkg/ui/ui_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/ui_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ REPO="Go-Lift-TV/notifiarr"
HBREPO="golift/homebrew-mugs"
MAINT="David Newhall II <david at sleepers dot pro>"
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"
Expand Down

0 comments on commit 475b05a

Please sign in to comment.