website

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRetries is the number of times to attempt a request to notifiarr.com.
	// 4 means 5 total tries: 1 try + 4 retries.
	DefaultRetries = 4
	// RetryDelay is how long to Sleep between retries.
	RetryDelay = 222 * time.Millisecond
)
View Source
const (
	ModeDev  = "development"
	ModeProd = "production"
)

Possible application modes.

Variables

View Source
var (
	ErrNon200          = fmt.Errorf("return code was not 200")
	ErrInvalidResponse = fmt.Errorf("invalid response")
	ErrNoChannel       = fmt.Errorf("the website send-data channel is closed")
)

Errors returned by this library.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Instance int           `json:"instance"`
	Name     string        `json:"name"`
	Stuck    bool          `json:"stuck"`
	Corrupt  string        `json:"corrupt"`
	Backup   string        `json:"backup"`
	Interval cnfg.Duration `json:"interval"`
}

AppConfig is the data that comes from the website for each Starr app.

type AppConfigs

type AppConfigs struct {
	Lidarr   []*AppConfig `json:"lidarr"`
	Prowlarr []*AppConfig `json:"prowlarr"`
	Radarr   []*AppConfig `json:"radarr"`
	Readarr  []*AppConfig `json:"readarr"`
	Sonarr   []*AppConfig `json:"sonarr"`
}

AppConfigs is the configuration returned from the notifiarr website for Starr apps.

type ClientInfo

type ClientInfo struct {
	User struct {
		WelcomeMSG string `json:"welcome"`
		Subscriber bool   `json:"subscriber"`
		Patron     bool   `json:"patron"`
		DevAllowed bool   `json:"devAllowed"`
	} `json:"user"`
	Actions struct {
		Poll      bool             `json:"poll"`
		Plex      PlexConfig       `json:"plex"`      // Site Config for Plex.
		Apps      AppConfigs       `json:"apps"`      // Site Config for Starr.
		Dashboard DashConfig       `json:"dashboard"` // Site Config for Dashboard.
		Sync      SyncConfig       `json:"sync"`      // Site Config for TRaSH Sync.
		Gaps      GapsConfig       `json:"gaps"`      // Site Config for Radarr Gaps.
		Custom    []*CronConfig    `json:"custom"`    // Site config for Custom Crons.
		Snapshot  *snapshot.Config `json:"snapshot"`  // Site Config for System Snapshot.
	} `json:"actions"`
}

ClientInfo is the client's startup data received from the website.

func (*ClientInfo) IsPatron

func (c *ClientInfo) IsPatron() bool

IsPatron returns true if the client is a patron. False otherwise.

func (*ClientInfo) IsSub

func (c *ClientInfo) IsSub() bool

IsSub returns true if the client is a subscriber. False otherwise.

func (*ClientInfo) String

func (c *ClientInfo) String() string

String returns the message text for a client info response.

type Config

type Config struct {
	Apps       *apps.Apps
	Plex       *plex.Server // plex sessions
	Serial     bool
	Retries    int
	BaseURL    string
	Timeout    cnfg.Duration
	MaxBody    int
	Sighup     chan os.Signal
	Mode       string
	HostID     string
	mnd.Logger // log file writer
}

Config is the input data needed to send payloads to notifiarr.

type CronConfig

type CronConfig struct {
	Name     string        `json:"name"`     // name of action.
	Interval cnfg.Duration `json:"interval"` // how often to GET this URI.
	URI      string        `json:"endpoint"` // endpoint for the URI.
	Desc     string        `json:"description"`
}

CronConfig defines a custom GET timer from the website. Used to offload crons to clients.

type DashConfig

type DashConfig struct {
	Interval cnfg.Duration `json:"interval"` // how often to fire in minutes.
}

DashConfig is the configuration returned from the notifiarr website for the dashboard configuration.

type EventType

type EventType string

EventType identifies the type of event that sent a paylaod to notifiarr.

const (
	EventCron    EventType = "cron"
	EventGUI     EventType = "gui"
	EventUser    EventType = "user"
	EventAPI     EventType = "api"
	EventHook    EventType = "webhook"
	EventStart   EventType = "start"
	EventMovie   EventType = "movie"
	EventEpisode EventType = "episode"
	EventPoll    EventType = "poll"
	EventSignal  EventType = "signal"
	EventFile    EventType = "file"
)

These are all our known event types.

type GapsConfig

type GapsConfig struct {
	Instances IntList       `json:"instances"`
	Interval  cnfg.Duration `json:"interval"`
}

GapsConfig is the configuration returned from the notifiarr website for Radarr Collection Gaps.

type IntList

type IntList []int

IntList has a method to abstract lookups.

func (IntList) Has

func (l IntList) Has(instance int) bool

Has returns true if the list has an instance ID.

type Payload

type Payload struct {
	Plex *plex.Sessions        `json:"plex,omitempty"`
	Snap *snapshot.Snapshot    `json:"snapshot,omitempty"`
	Load *plex.IncomingWebhook `json:"payload,omitempty"`
}

Payload is the outbound payload structure that is sent to Notifiarr for Plex and system snapshot data.

type PlexConfig

type PlexConfig struct {
	Interval   cnfg.Duration `json:"interval"`
	TrackSess  bool          `json:"trackSessions"`
	AccountMap string        `json:"accountMap"`
	NoActivity bool          `json:"noActivity"`
	Delay      cnfg.Duration `json:"activityDelay"`
	Cooldown   cnfg.Duration `json:"cooldown"`
	SeriesPC   uint          `json:"seriesPc"`
	MoviesPC   uint          `json:"moviesPc"`
}

PlexConfig is the website-derived configuration for Plex.

type Request

type Request struct {
	Route      Route
	Event      EventType
	Params     []string    // optional.
	Payload    interface{} // data to send.
	LogMsg     string      // if empty, nothing is logged.
	LogPayload bool        // debug log the sent payload
	ErrorsOnly bool        // only log errors.
	// contains filtered or unexported fields
}

Request is used when sending data through a channel.

type Response

type Response struct {
	Result  string `json:"result"`
	Details struct {
		Response json.RawMessage `json:"response"` // can be anything. type it out later.
		Help     string          `json:"help"`
		Started  time.Time       `json:"started"`
		Finished time.Time       `json:"finished"`
		Elapsed  cnfg.Duration   `json:"elapsed"`
	} `json:"details"`
}

Response is what notifiarr replies to our requests with.

try this
{
    "response": "success",
    "message": {
        "response": {
            "instance": 1,
            "debug": null
        },
        "started": "23:57:03",
        "finished": "23:57:03",
        "elapsed": "0s"
    }
}
{
    "response": "success",
    "message": {
        "response": "Service status cron processed.",
        "started": "00:04:15",
        "finished": "00:04:15",
        "elapsed": "0s"
    }
}
{
    "response": "success",
    "message": {
        "response": "Channel stats cron processed.",
        "started": "00:04:31",
        "finished": "00:04:36",
        "elapsed": "5s"
    }
}
{
    "response": "success",
    "message": {
        "response": "Dashboard payload processed.",
        "started": "00:02:04",
        "finished": "00:02:11",
        "elapsed": "7s"
    }
}

nitsua: all responses should be that way.. but response might not always be an object.

func (*Response) String

func (r *Response) String() string

String turns the response into a log entry.

type Route

type Route string

Route is used to give us methods on our route paths.

const (
	BaseURL     = "https://notifiarr.com"
	DevBaseURL  = "https://dev.notifiarr.com"
	TestBaseURL = "https://test.notifiarr.com"

	ClientRoute Route = userRoute2 + "/client"
	CFSyncRoute Route = userRoute1 + "/trash"
	GapsRoute   Route = userRoute1 + "/gaps"

	DashRoute    Route = notifiRoute + "/dashboard"
	StuckRoute   Route = notifiRoute + "/stuck"
	PlexRoute    Route = notifiRoute + "/plex"
	SnapRoute    Route = notifiRoute + "/snapshot"
	SvcRoute     Route = notifiRoute + "/services"
	CorruptRoute Route = notifiRoute + "/corruption"
	BackupRoute  Route = notifiRoute + "/backup"
	TestRoute    Route = notifiRoute + "/test"
	PkgRoute     Route = notifiRoute + "/packageManager"
	LogLineRoute Route = notifiRoute + "/logWatcher"
	CommandRoute Route = notifiRoute + "/command"
)

Notifiarr URLs. Data sent to these URLs:

api/v1/notification/plex?event=...

api (was plexcron)
user (was plexcron)
cron (was plexcron)
webhook (was plexhook)
movie
episode

api/v1/notification/services?event=...

api
user
cron
start (only fires on startup)

api/v1/notification/snapshot?event=...

api
user
cron

api/v1/notification/dashboard?event=... (requires interval from website/client endpoint)

api
user
cron

api/v1/notification/stuck?event=...

api
user
cron

api/v1/user/gaps?app=radarr&event=...

api
user
cron

api/v2/user/client?event=start

see description https://github.com/Notifiarr/notifiarr/pull/115

api/v1/user/trash?app=...

radarr
sonarr

func (Route) Path

func (r Route) Path(event EventType, params ...string) string

Path adds parameters to a route path and turns it into a string.

type Server

type Server struct {
	Mode string
	// contains filtered or unexported fields
}

Server is what you get for providing a Config to New().

func New

func New(c *Config) *Server

func (*Server) DelValue

func (s *Server) DelValue(keys ...string) error

DelValue deletes a value stored in the website database.

func (*Server) DelValueContext

func (s *Server) DelValueContext(ctx context.Context, keys ...string) error

DelValueContext deletes a value stored in the website database.

func (*Server) GetClientInfo

func (s *Server) GetClientInfo() (*ClientInfo, error)

GetClientInfo returns an error if the API key is wrong. Returns client info otherwise.

func (*Server) GetData

func (s *Server) GetData(req *Request) (*Response, error)

GetData sends data to a notifiarr URL as JSON.

func (*Server) GetHostInfo

func (s *Server) GetHostInfo() (*host.InfoStat, error)

GetHostInfo attempts to make a unique machine identifier...

func (*Server) GetValue

func (s *Server) GetValue(keys ...string) (map[string][]byte, error)

GetValue gets a value stored in the website database.

func (*Server) GetValueContext

func (s *Server) GetValueContext(ctx context.Context, keys ...string) (map[string][]byte, error)

GetValueContext gets a value stored in the website database.

func (*Server) HaveClientInfo

func (s *Server) HaveClientInfo() bool

func (*Server) Info

func (s *Server) Info() map[string]interface{}

Info is used for JSON input for our outgoing client info.

func (*Server) PollForReload

func (s *Server) PollForReload(event EventType)

func (*Server) RawGetData

func (s *Server) RawGetData(req *Request) (*Response, time.Duration, error)

RawGetData sends a request to the website without using a channel. Avoid this method.

func (*Server) ReloadCh

func (s *Server) ReloadCh(sighup chan os.Signal)

func (*Server) SendData

func (s *Server) SendData(req *Request)

SendData puts a send-data request to notifiarr.com into a channel queue.

func (*Server) SetValue

func (s *Server) SetValue(key string, value []byte) error

SetValue sets a value stored in the website database.

func (*Server) SetValueContext

func (s *Server) SetValueContext(ctx context.Context, key string, value []byte) error

SetValueContext sets a value stored in the website database.

func (*Server) SetValues

func (s *Server) SetValues(values map[string][]byte) error

SetValues sets values stored in the website database.

func (*Server) SetValuesContext

func (s *Server) SetValuesContext(ctx context.Context, values map[string][]byte) error

SetValuesContext sets values stored in the website database.

func (*Server) Start

func (s *Server) Start()

Start runs the website go routine.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the website go routine.

type SyncConfig

type SyncConfig struct {
	Interval        cnfg.Duration `json:"interval"`        // how often to fire in minutes.
	Radarr          int64         `json:"radarr"`          // items in sync
	RadarrInstances IntList       `json:"radarrInstances"` // which instance IDs we sync
	Sonarr          int64         `json:"sonarr"`          // items in sync
	SonarrInstances IntList       `json:"sonarrInstances"` // which instance IDs we sync
}

SyncConfig is the configuration returned from the notifiarr website for CF/RP TraSH sync.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL