notifiarr

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package notifiarr provides a standard interface for sending data to notifiarr.com. Several methods are exported to make POSTing data to notifarr easier. This package also handles the "crontab" timers for plex sessions, snapshots, custom format sync for Radarr and release profile sync for Sonarr. This package's cofiguration is provided by the configfile package.

Index

Constants

View Source
const (
	BaseURL     = "https://notifiarr.com"
	ProdURL     = BaseURL + "/notifier.php"
	TestURL     = BaseURL + "/notifierTest.php"
	DevBaseURL  = "http://dev.notifiarr.com"
	DevURL      = DevBaseURL + "/notifier.php"
	ClientRoute = "/api/v1/user/client"
	// CFSyncRoute is the webserver route to send sync requests to.
	CFSyncRoute = "/api/v1/user/trash"
)

Notifiarr URLs.

View Source
const (
	PlexCron = "plexcron"
	SnapCron = "snapcron"
	PlexHook = "plexhook"
	LogLocal = "loglocal"
)

These are used as 'source' values in json payloads sent to the webserver.

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
)

Variables

View Source
var (
	ErrNon200          = fmt.Errorf("return code was not 200")
	ErrInvalidResponse = fmt.Errorf("invalid response")
)

Errors returned by this library.

Functions

This section is empty.

Types

type ClientInfo added in v0.1.6

type ClientInfo struct {
	Status  string `json:"status"`
	Message struct {
		Text       string `json:"text"`
		Subscriber bool   `json:"subscriber"`
		CFSync     int64  `json:"cfSync"`
		RPSync     int64  `json:"rpSync"`
	} `json:"message"`
}

ClientInfo is the reply from the ClienRoute endpoint.

func (*ClientInfo) IsASub added in v0.1.6

func (c *ClientInfo) IsASub() bool

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

func (*ClientInfo) String added in v0.1.6

func (c *ClientInfo) String() string

String returns the message text for a client info response.

type Config

type Config struct {
	Apps         *apps.Apps       // has API key
	Plex         *plex.Server     // plex sessions
	Snap         *snapshot.Config // system snapshot data
	Retries      int
	URL          string
	BaseURL      string
	Timeout      time.Duration
	ClientInfo   *ClientInfo
	*logs.Logger // log file writer
	// contains filtered or unexported fields
}

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

func (*Config) GetClientInfo added in v0.1.6

func (c *Config) GetClientInfo() (*ClientInfo, error)

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

func (*Config) GetMetaSnap

func (c *Config) GetMetaSnap(ctx context.Context) *snapshot.Snapshot

GetMetaSnap grabs some basic system info: cpu, memory, username.

func (*Config) SendData

func (c *Config) SendData(url string, payload interface{}, pretty bool) (*http.Response, []byte, error)

SendData sends raw data to a notifiarr URL as JSON.

func (*Config) SendFinishedQueueItems added in v0.1.9

func (c *Config) SendFinishedQueueItems(url string)

func (*Config) SendJSON

func (c *Config) SendJSON(url string, data []byte) (*http.Response, []byte, error)

SendJSON posts a JSON payload to a URL. Returns the response body or an error.

func (*Config) SendMeta

func (c *Config) SendMeta(eventType, url string, hook *plex.Webhook, wait time.Duration) ([]byte, error)

SendMeta is kicked off by the webserver in go routine. It's also called by the plex cron (with webhook set to nil). This runs after Plex drops off a webhook telling us someone did something. This gathers cpu/ram, and waits 10 seconds, then grabs plex sessions. It's all POSTed to notifiarr. May be used with a nil Webhook.

func (*Config) Start

func (c *Config) Start(mode string)

Start (and log) snapshot and plex cron jobs if they're configured.

func (*Config) Stop

func (c *Config) Stop()

Stop snapshot and plex cron jobs.

func (*Config) SyncCF added in v0.1.12

func (c *Config) SyncCF(wait bool)

type ItemList added in v0.1.9

type ItemList map[int]custom

func (ItemList) Empty added in v0.1.9

func (i ItemList) Empty() bool

func (ItemList) Len added in v0.1.9

func (i ItemList) Len() (count int)

type Payload

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

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

type QueuePayload added in v0.1.9

type QueuePayload struct {
	Type    string   `json:"type"`
	Lidarr  ItemList `json:"lidarr,omitempty"`
	Radarr  ItemList `json:"radarr,omitempty"`
	Readarr ItemList `json:"readarr,omitempty"`
	Sonarr  ItemList `json:"sonarr,omitempty"`
}

type RadarrCustomFormatPayload added in v0.1.6

type RadarrCustomFormatPayload struct {
	Instance        int                      `json:"instance"`
	CustomFormats   []*radarr.CustomFormat   `json:"customFormats,omitempty"`
	QualityProfiles []*radarr.QualityProfile `json:"qualityProfiles,omitempty"`
	NewMaps         *cfMapIDpayload          `json:"newMaps,omitempty"`
}

RadarrCustomFormatPayload is the payload sent and received to/from notifarr.com when updating custom formats for Radarr.

type SonarrCustomFormatPayload added in v0.1.6

type SonarrCustomFormatPayload struct {
	Instance        int                      `json:"instance"`
	ReleaseProfiles []*sonarr.ReleaseProfile `json:"releaseProfiles,omitempty"`
	QualityProfiles []*sonarr.QualityProfile `json:"qualityProfiles,omitempty"`
	NewMaps         *cfMapIDpayload          `json:"newMaps,omitempty"`
}

SonarrCustomFormatPayload is the payload sent and received to/from notifarr.com when updating custom formats for Sonarr.

Jump to

Keyboard shortcuts

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