notifiarr

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 24 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 incoming Plex webhook as well as the "crontab" timers for plex sessions, snapshots, dashboard state, 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"
	DashRoute   = "/api/v1/user/dashboard"
	GapsRoute   = "/api/v1/user/gaps"
)

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.

View Source
var ErrNoChannel = fmt.Errorf("no channel to send session request")

Functions

This section is empty.

Types

type ClientInfo added in v0.1.6

type ClientInfo struct {
	Status  string  `json:"status"`
	Timers  []timer `json:"timers"`
	Message struct {
		Text       string `json:"text"`
		Subscriber bool   `json:"subscriber"`
		Patron     bool   `json:"patron"`
		Gaps       gaps   `json:"gaps"`
		CFSync     int64  `json:"cfSync"`
		RPSync     int64  `json:"rpSync"`
	} `json:"message"`
}

ClientInfo is the reply from the ClientRoute endpoint.

func (*ClientInfo) IsPatron added in v0.1.13

func (c *ClientInfo) IsPatron() bool

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

func (*ClientInfo) IsSub added in v0.1.13

func (c *ClientInfo) IsSub() bool

IsSub 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
	DashDur      time.Duration
	Retries      int
	URL          string
	BaseURL      string
	Timeout      time.Duration
	Trigger      Triggers
	*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) GetData added in v0.1.16

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

func (*Config) GetMetaSnap

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

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

func (*Config) GetSessions added in v0.1.16

func (c *Config) GetSessions(wait bool) (*plex.Sessions, error)

GetSessions returns the plex sessions. This uses a channel so concurrent requests are avoided. Passing wait=true makes sure the results are current. Waits up to 10 seconds before requesting. Passing wait=false will allow for sessions up to 10 seconds old. This may return faster.

func (*Config) Info added in v0.1.14

func (c *Config) Info() map[string]interface{}

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

func (*Config) PlexHandler added in v0.1.15

func (c *Config) PlexHandler(w http.ResponseWriter, r *http.Request)

PlexHandler handles an incoming webhook from Plex.

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) 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 *plexIncomingWebhook, wait bool) ([]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) VersionHandler added in v0.1.15

func (c *Config) VersionHandler(r *http.Request) (int, interface{})

VersionHandler returns application run and build time data and application statuses: /api/version.

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 *plexIncomingWebhook `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"`
	Name            string                   `json:"name"`
	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"`
	Name            string                   `json:"name"`
	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.

type Sortable added in v0.1.13

type Sortable struct {
	Name    string    `json:"name"`
	Sub     string    `json:"subName,omitempty"`
	Date    time.Time `json:"date"`
	Season  int64     `json:"season,omitempty"`
	Episode int64     `json:"episode,omitempty"`
	// contains filtered or unexported fields
}

Sortable holds data about any Starr item. Kind of a generic data store.

type SortableList added in v0.1.13

type SortableList []*Sortable

func (*SortableList) Shrink added in v0.1.13

func (s *SortableList) Shrink(size int)

Shrink a sortable list.

type State added in v0.1.13

type State struct {
	// Shared
	Error    string        `json:"error"`
	Instance int           `json:"instance"`
	Missing  int64         `json:"missing,omitempty"`
	Size     int64         `json:"size"`
	Percent  float64       `json:"percent,omitempty"`
	Upcoming int64         `json:"upcoming,omitempty"`
	Next     SortableList  `json:"next,omitempty"`
	Latest   SortableList  `json:"latest,omitempty"`
	Elapsed  time.Duration `json:"elapsed"` // How long it took.
	Name     string        `json:"name"`
	// Radarr
	Movies int64 `json:"movies,omitempty"`
	// Sonarr
	Shows    int64 `json:"shows,omitempty"`
	Episodes int64 `json:"episodes,omitempty"`
	// Readarr
	Authors  int   `json:"authors,omitempty"`
	Books    int64 `json:"books,omitempty"`
	Editions int   `json:"editions,omitempty"`
	// Lidarr
	Artists int   `json:"artists,omitempty"`
	Albums  int64 `json:"albums,omitempty"`
	Tracks  int64 `json:"tracks,omitempty"`
	// Downloader
	Downloads   int   `json:"downloads,omitempty"`
	Uploaded    int64 `json:"uploaded,omitempty"`
	Incomplete  int64 `json:"incomplete,omitempty"`
	Downloaded  int64 `json:"downloaded,omitempty"`
	Uploading   int64 `json:"uploading,omitempty"`
	Downloading int64 `json:"downloading,omitempty"`
	Seeding     int64 `json:"seeding,omitempty"`
	Paused      int64 `json:"paused,omitempty"`
	Errors      int64 `json:"errors,omitempty"`
}

State is partially filled out once for each app instance.

type States added in v0.1.13

type States struct {
	Lidarr  []*State `json:"lidarr"`
	Radarr  []*State `json:"radarr"`
	Readarr []*State `json:"readarr"`
	Sonarr  []*State `json:"sonarr"`
	Qbit    []*State `json:"qbit"`
	Deluge  []*State `json:"deluge"`
}

type Timer added in v0.1.15

type Timer struct {
	// contains filtered or unexported fields
}

Timer is used to set a cooldown time.

func (*Timer) Active added in v0.1.15

func (t *Timer) Active(d time.Duration) bool

Active returns true if a timer is active, otherwise it becomes active.

type Triggers added in v0.1.15

type Triggers struct {
	// contains filtered or unexported fields
}

Triggers allow trigger actions in the timer routine.

func (*Triggers) GetState added in v0.1.15

func (t *Triggers) GetState()

func (*Triggers) SendFinishedQueueItems added in v0.1.15

func (t *Triggers) SendFinishedQueueItems(url string)

func (*Triggers) SendGaps added in v0.1.16

func (t *Triggers) SendGaps(source string)

func (*Triggers) SendPlexSessions added in v0.1.15

func (t *Triggers) SendPlexSessions(source string)

SendPlexSessions sends plex sessions in a go routine through a channel.

func (*Triggers) SendSnapshot added in v0.1.15

func (t *Triggers) SendSnapshot(source string)

func (*Triggers) SyncCF added in v0.1.15

func (t *Triggers) SyncCF(wait bool)

Jump to

Keyboard shortcuts

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