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
- Variables
- type ClientInfo
- type Config
- func (c *Config) GetClientInfo() (*ClientInfo, error)
- func (c *Config) GetData(url string) (*http.Response, []byte, error)
- func (c *Config) GetMetaSnap(ctx context.Context) *snapshot.Snapshot
- func (c *Config) GetSessions(wait bool) (*plex.Sessions, error)
- func (c *Config) Info() map[string]interface{}
- func (c *Config) PlexHandler(w http.ResponseWriter, r *http.Request)
- func (c *Config) SendData(url string, payload interface{}, pretty bool) (*http.Response, []byte, error)
- func (c *Config) SendJSON(url string, data []byte) (*http.Response, []byte, error)
- func (c *Config) SendMeta(eventType, url string, hook *plexIncomingWebhook, wait bool) ([]byte, error)
- func (c *Config) Start(mode string)
- func (c *Config) Stop()
- func (c *Config) VersionHandler(r *http.Request) (int, interface{})
- type ItemList
- type Payload
- type QueuePayload
- type RadarrCustomFormatPayload
- type SonarrCustomFormatPayload
- type Sortable
- type SortableList
- type State
- type States
- type Timer
- type Triggers
Constants ¶
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.
const ( PlexCron = "plexcron" SnapCron = "snapcron" PlexHook = "plexhook" LogLocal = "loglocal" )
These are used as 'source' values in json payloads sent to the webserver.
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 ¶
var ( ErrNon200 = fmt.Errorf("return code was not 200") ErrInvalidResponse = fmt.Errorf("invalid response") )
Errors returned by this library.
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) GetMetaSnap ¶
GetMetaSnap grabs some basic system info: cpu, memory, username.
func (*Config) GetSessions ¶ added in v0.1.16
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) 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 ¶
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.
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 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 Timer ¶ added in v0.1.15
type Timer struct {
// contains filtered or unexported fields
}
Timer is used to set a cooldown time.
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) SendFinishedQueueItems ¶ added in v0.1.15
func (*Triggers) SendPlexSessions ¶ added in v0.1.15
SendPlexSessions sends plex sessions in a go routine through a channel.