Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

October Surprise #838

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apps/apppkg/plex/plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Server) reqPlexURL(
}

if resp.StatusCode != http.StatusOK {
return body, ErrBadStatus
return body, fmt.Errorf("%w: %s", ErrBadStatus, resp.Status)
}

return body, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/bindata/files/js/golists.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function testInstance(from, instanceType, index)
toast('Web Server Error',
'Notifiarr client appears to be down! Hard refresh recommended.', 'error', 30000);
} else {
toast(instanceType+' Check Error', error+': '+response.responseText, 'error', 15000);
toast(instanceType+' Check Error', response.responseText, 'error', 15000);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion pkg/bindata/templates/snapshot/mysql.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h3><i class="fas fa-comment text-orange"></i> MySQL Notes</h3>
<li><i class="fas fa-star"></i> You may add MySQL credentials to your Notifiarr client configuration to snapshot MySQL service health.</li>
<li><i class="fas fa-star"></i> This feature snapshots <code>SHOW PROCESSLIST</code> and <code>SHOW STATUS</code> data.</li>
<li><i class="fas fa-star"></i>Access to a database is not required. Example Grant: <code>GRANT PROCESS ON *.* to 'notifiarr'@'localhost'</code></li>
<li><i class="fas fa-star"></i> Access to a database is not required. Example Grant: <code>GRANT PROCESS ON *.* to 'notifiarr'@'localhost'</code></li>
</p>
<div class="table-responsive">
<table class="table bk-dark table-bordered">
Expand Down
7 changes: 6 additions & 1 deletion pkg/bindata/templates/snapshot/nvidia.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<div class="table-responsive">
</p>
<h3><i class="fas fa-comment text-orange"></i> Nvidia Notes</h3>
<li><i class="fas fa-star"></i> This integration displays Nvidia CUDA info in Snapshot notifications.</li>
<li><i class="fas fa-star"></i> To use this feature in Docker, you must use the CUDA image: <code>ghcr.io/notifiarr/notifiarr:cuda</code></li>
</p>
<div class="table-responsive">
<table class="table bk-dark table-bordered">
<thead>
<tr>
Expand Down
18 changes: 9 additions & 9 deletions pkg/checkapp/downloaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
func testQbit(ctx context.Context, config *apps.QbitConfig) (string, int) {
qbit, err := qbit.New(ctx, config.Config)
if err != nil {
return connecting + err.Error(), http.StatusBadGateway
return connecting + err.Error(), http.StatusBadRequest
}

xfers, err := qbit.GetXfersContext(ctx)
if err != nil {
return "Getting Transfers: " + err.Error(), http.StatusBadGateway
return "Getting Transfers: " + err.Error(), http.StatusBadRequest
}

return fmt.Sprintf("Connection Successful! %d Transfers", len(xfers)), http.StatusOK
Expand All @@ -34,7 +34,7 @@ func testRtorrent(_ context.Context, config *apps.RtorrentConfig) (string, int)

result, err := config.Client.Call("system.hostname")
if err != nil {
return "Getting Server Name: " + err.Error(), http.StatusBadGateway
return "Getting Server Name: " + err.Error(), http.StatusFailedDependency
}

if names, ok := result.([]any); ok {
Expand All @@ -45,15 +45,15 @@ func testRtorrent(_ context.Context, config *apps.RtorrentConfig) (string, int)
return "Connection Successful! Server name: " + name, http.StatusOK
}

return "Getting Server Name: result was not a string?", http.StatusBadGateway
return "Getting Server Name: result was not a string?", http.StatusFailedDependency
}

func testSabNZB(ctx context.Context, app *apps.SabNZBConfig) (string, int) {
app.Setup(0, nil)

sab, err := app.GetQueue(ctx)
if err != nil {
return "Getting Queue: " + err.Error(), http.StatusBadGateway
return "Getting Queue: " + err.Error(), http.StatusFailedDependency
}

return success + sab.Version, http.StatusOK
Expand All @@ -62,7 +62,7 @@ func testSabNZB(ctx context.Context, app *apps.SabNZBConfig) (string, int) {
func testNZBGet(ctx context.Context, config *apps.NZBGetConfig) (string, int) {
ver, err := nzbget.New(config.Config).VersionContext(ctx)
if err != nil {
return "Getting Version: " + err.Error(), http.StatusBadGateway
return "Getting Version: " + err.Error(), http.StatusFailedDependency
}

return fmt.Sprintf("%s%s", success, ver), http.StatusOK
Expand All @@ -71,7 +71,7 @@ func testNZBGet(ctx context.Context, config *apps.NZBGetConfig) (string, int) {
func testDeluge(ctx context.Context, config *apps.DelugeConfig) (string, int) {
deluge, err := deluge.New(ctx, config.Config)
if err != nil {
return connecting + err.Error(), http.StatusBadGateway
return connecting + err.Error(), http.StatusFailedDependency
}

return fmt.Sprintf("%s%s", success, deluge.Version), http.StatusOK
Expand All @@ -80,7 +80,7 @@ func testDeluge(ctx context.Context, config *apps.DelugeConfig) (string, int) {
func testTransmission(ctx context.Context, config *apps.XmissionConfig) (string, int) {
endpoint, err := url.Parse(config.URL)
if err != nil {
return "parsing url: " + err.Error(), http.StatusBadGateway
return "parsing url: " + err.Error(), http.StatusFailedDependency
} else if config.User != "" {
endpoint.User = url.UserPassword(config.User, config.Pass)
}
Expand All @@ -91,7 +91,7 @@ func testTransmission(ctx context.Context, config *apps.XmissionConfig) (string,

args, err := client.SessionArgumentsGetAll(ctx)
if err != nil {
return "Getting Server Version: " + err.Error(), http.StatusBadGateway
return "Getting Server Version: " + err.Error(), http.StatusFailedDependency
}

return "Transmission Server version: " + *args.Version, http.StatusOK
Expand Down
4 changes: 2 additions & 2 deletions pkg/checkapp/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func testPlex(ctx context.Context, app *apps.PlexConfig) (string, int) {

info, err := app.GetInfo(ctx)
if err != nil {
return "Getting Info: " + err.Error(), http.StatusBadGateway
return "Getting Info: " + err.Error(), http.StatusFailedDependency
}

return "Plex OK! Version: " + info.Version, http.StatusOK
Expand All @@ -24,7 +24,7 @@ func testTautulli(ctx context.Context, app *apps.TautulliConfig) (string, int) {

users, err := app.GetUsers(ctx)
if err != nil {
return "Getting Users: " + err.Error(), http.StatusBadGateway
return "Getting Users: " + err.Error(), http.StatusFailedDependency
}

return fmt.Sprintf("Tautulli OK! Users: %d", len(users.Response.Data)), http.StatusOK
Expand Down
8 changes: 4 additions & 4 deletions pkg/checkapp/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func testTCP(ctx context.Context, svc *services.Service) (string, int) {

res := svc.CheckOnly(ctx)
if res.State != services.StateOK {
return res.State.String() + " " + res.Output.String(), http.StatusBadGateway
return res.State.String() + " " + res.Output.String(), http.StatusFailedDependency
}

return "TCP Port is OPEN and reachable: " + res.Output.String(), http.StatusOK
Expand All @@ -27,7 +27,7 @@ func testHTTP(ctx context.Context, svc *services.Service) (string, int) {

res := svc.CheckOnly(ctx)
if res.State != services.StateOK {
return res.State.String() + " " + res.Output.String(), http.StatusBadGateway
return res.State.String() + " " + res.Output.String(), http.StatusFailedDependency
}

// add test
Expand All @@ -41,7 +41,7 @@ func testProcess(ctx context.Context, svc *services.Service) (string, int) {

res := svc.CheckOnly(ctx)
if res.State != services.StateOK {
return res.State.String() + " " + res.Output.String(), http.StatusBadGateway
return res.State.String() + " " + res.Output.String(), http.StatusFailedDependency
}

return "Process Tested OK: " + res.Output.String(), http.StatusOK
Expand All @@ -54,7 +54,7 @@ func testPing(ctx context.Context, svc *services.Service) (string, int) {

res := svc.CheckOnly(ctx)
if res.State != services.StateOK {
return res.State.String() + " " + res.Output.String(), http.StatusBadGateway
return res.State.String() + " " + res.Output.String(), http.StatusFailedDependency
}

return "Ping Tested OK: " + res.Output.String(), http.StatusOK
Expand Down
2 changes: 1 addition & 1 deletion pkg/checkapp/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func testNvidia(ctx context.Context, config *snapshot.NvidiaConfig) (string, int
config.Disabled = false

if err := snaptest.GetNvidia(ctx, config); err != nil {
return err.Error(), http.StatusBadGateway
return err.Error(), http.StatusFailedDependency
}

msg := fmt.Sprintf("SMI found %d Graphics Adapter", len(snaptest.Nvidia))
Expand Down
10 changes: 5 additions & 5 deletions pkg/checkapp/starr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func testLidarr(ctx context.Context, config *apps.LidarrConfig) (string, int) {
status, err := lidarr.New(config.Config).GetSystemStatusContext(ctx)
if err != nil {
return connecting + err.Error(), http.StatusBadGateway
return connecting + err.Error(), http.StatusFailedDependency
}

return success + status.Version, http.StatusOK
Expand All @@ -24,7 +24,7 @@ func testLidarr(ctx context.Context, config *apps.LidarrConfig) (string, int) {
func testProwlarr(ctx context.Context, config *apps.ProwlarrConfig) (string, int) {
status, err := prowlarr.New(config.Config).GetSystemStatusContext(ctx)
if err != nil {
return connecting + err.Error(), http.StatusBadGateway
return connecting + err.Error(), http.StatusFailedDependency
}

return success + status.Version, http.StatusOK
Expand All @@ -33,7 +33,7 @@ func testProwlarr(ctx context.Context, config *apps.ProwlarrConfig) (string, int
func testRadarr(ctx context.Context, config *apps.RadarrConfig) (string, int) {
status, err := radarr.New(config.Config).GetSystemStatusContext(ctx)
if err != nil {
return connecting + err.Error(), http.StatusBadGateway
return connecting + err.Error(), http.StatusFailedDependency
}

return success + status.Version, http.StatusOK
Expand All @@ -42,7 +42,7 @@ func testRadarr(ctx context.Context, config *apps.RadarrConfig) (string, int) {
func testReadarr(ctx context.Context, config *apps.ReadarrConfig) (string, int) {
status, err := readarr.New(config.Config).GetSystemStatusContext(ctx)
if err != nil {
return connecting + err.Error(), http.StatusBadGateway
return connecting + err.Error(), http.StatusFailedDependency
}

return success + status.Version, http.StatusOK
Expand All @@ -51,7 +51,7 @@ func testReadarr(ctx context.Context, config *apps.ReadarrConfig) (string, int)
func testSonarr(ctx context.Context, config *apps.SonarrConfig) (string, int) {
status, err := sonarr.New(config.Config).GetSystemStatusContext(ctx)
if err != nil {
return connecting + err.Error(), http.StatusBadGateway
return connecting + err.Error(), http.StatusFailedDependency
}

return success + status.Version, http.StatusOK
Expand Down
3 changes: 3 additions & 0 deletions pkg/client/handlers_gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ func (c *Client) mergeAndValidateNewConfig(config *configfile.Config, request *h
config.Apps.SabNZB = nil
config.Apps.NZBGet = nil
config.Apps.Tautulli = nil
config.Apps.Transmission = nil
config.Apps.Qbit = nil
config.Apps.Plex = nil
}

config.SSLCrtFile = ""
Expand Down
4 changes: 2 additions & 2 deletions pkg/services/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ func (s *Service) checkTCP() *result {
return res
}

func (s *Service) Due() bool {
func (s *Service) Due(now time.Time) bool {
s.svc.RLock()
defer s.svc.RUnlock()

return time.Since(s.svc.LastCheck) > s.Interval.Duration
return now.Sub(s.svc.LastCheck) > s.Interval.Duration
}
17 changes: 11 additions & 6 deletions pkg/services/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package services
import (
"errors"
"fmt"
"time"

"github.com/Notifiarr/notifiarr/pkg/website"
)
Expand Down Expand Up @@ -44,8 +45,8 @@ func (c *Config) RunCheck(source website.EventType, name string) error {
}

// runCheck runs a service check if it is due. Passing force runs it regardless.
func (c *Config) runCheck(svc *Service, force bool) bool {
if force || svc.Due() {
func (c *Config) runCheck(svc *Service, force bool, now time.Time) bool {
if force || svc.Due(now) {
c.checks <- svc
return <-c.done
}
Expand All @@ -54,23 +55,27 @@ func (c *Config) runCheck(svc *Service, force bool) bool {
}

// runChecks runs checks that are due. Passing true, runs them even if they're not due.
func (c *Config) runChecks(forceAll bool) {
// Returns true if any service state changed.
func (c *Config) runChecks(forceAll bool, now time.Time) bool {
if c.checks == nil || c.done == nil {
return
return false
}

count := 0
changes := false

for s := range c.services {
if forceAll || c.services[s].Due() {
if forceAll || c.services[s].Due(now) {
count++
c.checks <- c.services[s]
}
}

for ; count > 0; count-- {
<-c.done
changes = <-c.done || changes
}

return changes
}

// GetResults creates a copy of all the results and returns them.
Expand Down
28 changes: 14 additions & 14 deletions pkg/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/Notifiarr/notifiarr/pkg/mnd"
"github.com/Notifiarr/notifiarr/pkg/website"
"github.com/gorilla/mux"
"golift.io/version"
)

func (c *Config) Setup(services []*Service) error {
Expand Down Expand Up @@ -184,17 +185,13 @@ func (c *Config) runServiceChecker() { //nolint:cyclop
c.stopChan <- struct{}{} // signal we're finished.
}()

ticker := &time.Ticker{C: make(<-chan time.Time)}
second := &time.Ticker{C: make(<-chan time.Time)}
checker := &time.Ticker{C: make(<-chan time.Time)}

if !c.Disabled {
ticker = time.NewTicker(c.Interval.Duration)
defer ticker.Stop()
checker = time.NewTicker(time.Second)
defer checker.Stop()

second = time.NewTicker(10 * time.Second) //nolint:mnd
defer second.Stop()

c.runChecks(true)
c.runChecks(true, version.Started)
c.SendResults(&Results{What: website.EventStart, Svcs: c.GetResults()})
}

Expand All @@ -207,15 +204,16 @@ func (c *Config) runServiceChecker() { //nolint:cyclop
}

return
case <-ticker.C:
c.SendResults(&Results{What: website.EventCron, Svcs: c.GetResults()})
case event := <-c.checkChan:
c.Printf("Running service check '%s' via event: %s, buffer: %d/%d",
event.Service.Name, event.Source, len(c.checks), cap(c.checks))
c.runCheck(event.Service, true)

if c.runCheck(event.Service, true, time.Now()) {
c.SendResults(&Results{What: event.Source, Svcs: c.GetResults()})
}
case event := <-c.triggerChan:
c.Debugf("Running all service checks via event: %s, buffer: %d/%d", event, len(c.checks), cap(c.checks))
c.runChecks(true)
c.runChecks(true, time.Now())

if event != "log" {
c.SendResults(&Results{What: event, Svcs: c.GetResults()})
Expand All @@ -229,8 +227,10 @@ func (c *Config) runServiceChecker() { //nolint:cyclop
}

c.Debug("Service Checks Payload (log only):", string(data))
case <-second.C:
c.runChecks(false)
case now := <-checker.C:
if c.runChecks(false, now) {
c.SendResults(&Results{What: website.EventCron, Svcs: c.GetResults()})
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/diskio.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s *Snapshot) getIoStat(ctx context.Context, run bool) error {
}

cmd := exec.CommandContext(ctx, cmdPath, "-x", "-d", "-o", "JSON")
sysCallSettings(cmd)
SysCallSettings(cmd)

stderr := &bytes.Buffer{}
stdout := &bytes.Buffer{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/helpers_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import (
"os/exec"
)

func sysCallSettings(_ *exec.Cmd) {}
func SysCallSettings(_ *exec.Cmd) {}
2 changes: 1 addition & 1 deletion pkg/snapshot/helpers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import (
"syscall"
)

func sysCallSettings(cmd *exec.Cmd) {
func SysCallSettings(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: 0x08000000} //nolint:mnd
}
2 changes: 1 addition & 1 deletion pkg/snapshot/ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *Snapshot) GetIPMI(ctx context.Context, run, useSudo bool) error {
defer cancel()

cmd := exec.CommandContext(ctx, tool, args...)
sysCallSettings(cmd)
SysCallSettings(cmd)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand Down
Loading
Loading