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 BackupInfo
- type BackupPayload
- type ClientInfo
- type Config
- func (c *Config) DelValue(keys ...string) error
- func (c *Config) DelValueContext(ctx context.Context, keys ...string) error
- func (c *Config) GetClientInfo() (*ClientInfo, error)
- func (c *Config) GetHostInfoUID() (*host.InfoStat, error)
- func (c *Config) GetSessions(wait bool) (*plex.Sessions, error)
- func (c *Config) GetValue(keys ...string) (map[string][]byte, error)
- func (c *Config) GetValueContext(ctx context.Context, keys ...string) (map[string][]byte, error)
- func (c *Config) HostInfoNoError() *host.InfoStat
- func (c *Config) Info() map[string]interface{}
- func (c *Config) PlexHandler(w http.ResponseWriter, r *http.Request)
- func (c *Config) SendData(uri string, payload interface{}, log bool) (*Response, error)
- func (c *Config) SetValue(key string, value []byte) error
- func (c *Config) SetValueContext(ctx context.Context, key string, value []byte) error
- func (c *Config) SetValues(values map[string][]byte) error
- func (c *Config) SetValuesContext(ctx context.Context, values map[string][]byte) error
- func (c *Config) Setup(mode string) string
- func (c *Config) Start()
- func (c *Config) Stop(event EventType)
- type EventType
- type IntList
- type ItemList
- type ListItem
- type Payload
- type QueuePayload
- type RadarrTrashPayload
- type Response
- type Route
- type ServiceCheck
- type ServiceConfig
- type SonarrTrashPayload
- type Sortable
- type SortableList
- type State
- type States
- type Timer
- type TriggerName
- type Triggers
- func (t *Triggers) Backup(event EventType, app starr.App) error
- func (t *Triggers) Corruption(event EventType, app starr.App) error
- func (t *Triggers) SendDashboardState(event EventType)
- func (t *Triggers) SendGaps(event EventType)
- func (t *Triggers) SendPlexSessions(event EventType)
- func (t *Triggers) SendSnapshot(event EventType)
- func (t *Triggers) SendStuckQueueItems(event EventType)
- func (t *Triggers) SyncCF(event EventType)
Constants ¶
const ( ModeDev = "development" ModeProd = "production" )
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") ErrInvalidApp = fmt.Errorf("invalid application provided") )
Errors returned by this library.
var ErrNoChannel = fmt.Errorf("no channel to send session request")
var (
ErrNoDBInBackup = fmt.Errorf("no database file found in backup")
)
Errors returned by this package.
Functions ¶
This section is empty.
Types ¶
type BackupInfo ¶ added in v0.2.5
type BackupInfo struct { App starr.App `json:"app"` Int int `json:"instance"` Name string `json:"name"` File string `json:"file,omitempty"` Ver string `json:"version,omitempty"` Integ string `json:"integrity,omitempty"` Quick string `json:"quick,omitempty"` Rows int `json:"rows,omitempty"` Size int64 `json:"bytes,omitempty"` Tables int64 `json:"tables,omitempty"` Date time.Time `json:"date,omitempty"` }
BackupInfo contains a pile of information about a Starr database (backup). This is the data sent to notifiarr.com.
type BackupPayload ¶ added in v0.2.5
type BackupPayload struct { App starr.App `json:"app"` Int int `json:"instance"` Name string `json:"name"` Files []*starr.BackupFile `json:"backups"` }
BackupPayload is the data we send to notifiarr.
type ClientInfo ¶ added in v0.1.6
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 *plex.Server `json:"plex"` // optional Apps appConfigs `json:"apps"` // unused yet! Dashboard dashConfig `json:"dashboard"` // now in use. Sync syncConfig `json:"sync"` // in use (cfsync) Gaps gapsConfig `json:"gaps"` // radarr collection gaps Custom []*timerConfig `json:"custom"` // custom GET timers Snapshot *snapshot.Config `json:"snapshot"` // optional } `json:"actions"` }
ClientInfo is the client's startup data received from the website.
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 `json:"apps"` // has API key Plex *plex.Server `json:"plex"` // plex sessions Snap *snapshot.Config `json:"snapshots"` // system snapshot data Services *ServiceConfig `json:"services"` Serial bool `json:"serial"` Retries int `json:"retries"` BaseURL string `json:"-"` Timeout cnfg.Duration `json:"timeout"` Trigger Triggers `json:"-"` MaxBody int `json:"maxBody"` Sighup chan os.Signal `json:"-"` *logs.Logger `json:"-"` // log file writer // contains filtered or unexported fields }
Config is the input data needed to send payloads to notifiarr.
func (*Config) DelValueContext ¶ added in v0.3.0
DelValueContext deletes a value stored in the website database.
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) GetHostInfoUID ¶ added in v0.2.0
GetHostInfoUID attempts to make a unique machine identifier...
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) GetValueContext ¶ added in v0.3.0
GetValueContext gets a value stored in the website database.
func (*Config) HostInfoNoError ¶ added in v0.2.0
HostInfoNoError will return nil if there is an error, otherwise a copy of the host 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) SetValueContext ¶ added in v0.3.0
SetValueContext sets a value stored in the website database.
func (*Config) SetValuesContext ¶ added in v0.3.0
SetValuesContext sets values stored in the website database.
type EventType ¶ added in v0.2.0
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" )
These are all our known event types.
type Payload ¶
type Payload struct { 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 RadarrTrashPayload ¶ added in v0.2.7
type RadarrTrashPayload struct { Instance int `json:"instance"` Name string `json:"name"` CustomFormats []*radarr.CustomFormat `json:"customFormats,omitempty"` QualityProfiles []*radarr.QualityProfile `json:"qualityProfiles,omitempty"` Error string `json:"error"` // Purposely not exported so as to not use it externally. NewMaps *cfMapIDpayload `json:"newMaps,omitempty"` }
RadarrTrashPayload is the payload sent and received to/from notifarr.com when updating custom formats for Radarr. This is used in other places, like the trash API handler in the 'client' module.
type Response ¶ added in v0.2.0
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.
type Route ¶ added in v0.2.0
type Route string
Route is used to give us methods on our route paths.
const ( BaseURL = "https://notifiarr.com" DevBaseURL = "https://dev.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" )
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
type ServiceCheck ¶ added in v0.2.0
type ServiceCheck struct { Name string `json:"name"` Type string `json:"type"` Expect string `json:"expect"` Timeout cnfg.Duration `json:"timeout"` Interval cnfg.Duration `json:"interval"` }
ServiceCheck comes from the services package. It's only used for display on the website.
type ServiceConfig ¶ added in v0.2.0
type ServiceConfig struct { Interval cnfg.Duration `json:"interval"` Parallel uint `json:"parallel"` Disabled bool `json:"disabled"` Checks []*ServiceCheck `json:"checks"` }
ServiceConfig comes from the services package. It's only used for display on the website.
type SonarrTrashPayload ¶ added in v0.2.7
type SonarrTrashPayload struct { Instance int `json:"instance"` Name string `json:"name"` ReleaseProfiles []*sonarr.ReleaseProfile `json:"releaseProfiles,omitempty"` QualityProfiles []*sonarr.QualityProfile `json:"qualityProfiles,omitempty"` Error string `json:"error"` // Purposely not exported so as to not use it externally. NewMaps *cfMapIDpayload `json:"newMaps,omitempty"` }
SonarrTrashPayload 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
SortableList allows sorting a list.
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"` OnDisk int64 `json:"onDisk,omitempty"` Elapsed cnfg.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"` Month int64 `json:"month,omitempty"` Week int64 `json:"week,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"` SabNZB []*State `json:"sabnzbd"` Plex *plex.Sessions `json:"plexSessions"` }
States is our compiled states for the dashboard.
type Timer ¶ added in v0.1.15
type Timer struct {
// contains filtered or unexported fields
}
Timer is used to set a cooldown time.
type TriggerName ¶ added in v0.2.5
type TriggerName string
TriggerName makes sure triggers have a known name.
const ( TrigLidarrBackup TriggerName = "Sending Lidarr Backup File List to Notifiarr." TrigProwlarrBackup TriggerName = "Sending Prowlarr Backup File List to Notifiarr." TrigRadarrBackup TriggerName = "Sending Radarr Backup File List to Notifiarr." TrigReadarrBackup TriggerName = "Sending Readarr Backup File List to Notifiarr." TrigSonarrBackup TriggerName = "Sending Sonarr Backup File List to Notifiarr." )
Used to find and identiy each trigger in the trigger list.
const ( TrigLidarrCorrupt TriggerName = "Checking Lidarr for database backup corruption." TrigProwlarrCorrupt TriggerName = "Checking Prowlarr for database backup corruption." TrigRadarrCorrupt TriggerName = "Checking Radarr for database backup corruption." TrigReadarrCorrupt TriggerName = "Checking Readarr for database backup corruption." TrigSonarrCorrupt TriggerName = "Checking Sonarr for database backup corruption." )
Trigger Types.
const ( TrigSnapshot TriggerName = "Gathering and sending System Snapshot." TrigDashboard TriggerName = "Initiating State Collection for Dashboard." TrigCFSync TriggerName = "Starting Radarr CF and Sonarr QP TRaSH sync." TrigCollectionGaps TriggerName = "Sending Radarr Collection Gaps." TrigPlexSessions TriggerName = "Gathering and sending Plex Sessions." TrigStuckItems TriggerName = "Checking app queues and sending stuck items." TrigPollSite TriggerName = "Polling Notifiarr for new settings." TrigStop TriggerName = "Stopping all triggers and timers (reload)." )
Identified Action Triggers. Name and explanation.
type Triggers ¶ added in v0.1.15
type Triggers struct { List []*action // List of action triggers // contains filtered or unexported fields }
Triggers allow trigger actions in the timer routine.
func (*Triggers) Corruption ¶ added in v0.2.5
func (*Triggers) SendDashboardState ¶ added in v0.2.0
SendDashboardState sends the current states for the dashboard.
func (*Triggers) SendPlexSessions ¶ added in v0.1.15
SendPlexSessions sends plex sessions in a go routine through a channel.