website

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 23 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
	// APIKeyLength is the string length of a valid notifiarr API key.
	APIKeyLength = 36
	// MaxTimeout is the maximum timeout for a request to notifiarr.com.
	MaxTimeout = 3 * time.Minute
	// MinTimeout is the minimum timeout for a request to notifiarr.com.
	MinTimeout = 10 * time.Second
)

Variables

View Source
var (
	ErrNon200          = errors.New("return code was not 200")
	ErrInvalidResponse = errors.New("invalid response")
	ErrNoChannel       = errors.New("the website send-data channel is closed")
	ErrInvalidAPIKey   = errors.New("configured notifiarr API key is invalid")
)

Errors returned by this library.

Functions

func DelState added in v0.9.0

func DelState(keys ...string) error

DelState deletes a value stored in the website database.

func GetHostInfo added in v0.9.0

func GetHostInfo(ctx context.Context) (*host.InfoStat, error)

GetHostInfo attempts to make a unique machine identifier...

func GetState added in v0.9.0

func GetState(reqID string, keys ...string) (map[string][]byte, error)

GetState gets a value stored in the website database.

func New

func New(ctx context.Context, config *Config)

func SendData added in v0.9.0

func SendData(req *Request)

SendData puts a POST request to notifiarr.com into a channel queue.

func SetState added in v0.9.0

func SetState(key string, value []byte) error

SetState sets a value stored in the website database.

func SetStates added in v0.9.0

func SetStates(values map[string][]byte) error

SetStates sets values stored in the website database.

func TestApiKey added in v0.9.2

func TestApiKey(ctx context.Context, apiKey string) error

TestApiKey tests if the API key is valid.

func ValidAPIKey added in v0.9.0

func ValidAPIKey() error

ValidAPIKey checks if the API key is valid.

Types

type Config

type Config struct {
	Apps       *apps.Apps
	Retries    int
	Timeout    cnfg.Duration
	HostID     string
	BindAddr   string
	NoCompress bool
}

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

func GetConfig added in v0.9.0

func GetConfig() *Config

GetConfig returns the current website config.

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"
	EventCheck   EventType = "upcheck"
	EventSignal  EventType = "signal"
	EventFile    EventType = "file"
	EventSet     EventType = "setStates"
	EventGet     EventType = "getStates"
)

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 *plex.IncomingWebhook `json:"payload,omitempty"`
}

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

type Request

type Request struct {
	ReqID      string
	Route      Route
	Event      EventType
	Params     []string    // optional.
	Payload    any         // data to send.
	UploadFile *UploadFile // file to send (instead of payload).
	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"`
	// contains filtered or unexported fields
}

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 GetData added in v0.9.0

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

GetData sends data to a notifiarr URL as JSON and returns a response.

func RawGetData added in v0.9.0

func RawGetData(ctx context.Context, req *Request) (*Response, time.Duration, error)

RawGetData sends a request to the website without using a channel. Avoid this method, it can trigger data races. Use it only in cli.go.

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"

	CFSyncRoute   Route = userRoute1 + "/trash"
	GapsRoute     Route = userRoute1 + "/gaps"
	MdbListRoute  Route = userRoute1 + "/mdblist"
	TunnelRoute   Route = userRoute1 + "/tunnel"
	ValidateRoute Route = userRoute1 + "/validate"

	ClientRoute Route = userRoute2 + "/client"

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

	UploadRoute Route = systemRoute + "/upload"
)

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 UploadFile added in v0.7.0

type UploadFile struct {
	FileName string
	io.ReadCloser
}

UploadFile is the file upload identifier in a request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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