zedhook

package
v0.0.0-...-a44f053 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package zedhook implements client and server logic for the zedhookd system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

A Client is a client for the zedhookd server.

func NewClient

func NewClient(addr string, c *http.Client) (*Client, error)

NewClient creates a Client for the zedhookd server specified by addr.

If addr is empty, the default zedhookd addresses will be tried in order:

If a non-empty addr is set, that address will be used and no fallback paths will be attempted.

If c is nil, a default HTTP client which supports "http", "https", "http+unix", and "https+unix" address schemes (see https://github.com/peterbourgon/unixtransport) will be configured.

func (*Client) Push

func (c *Client) Push(ctx context.Context) error

Push gathers a Payload from environment variables set by ZED and pushes that payload to an instance of zedhookd. It may also invoke ZFS shell commands as necessary to gather additional context.

type Event

type Event struct {
	// Core metadata about an Event.
	ID, EventID  int
	Timestamp    time.Time
	Class, Zpool string

	// Unprocessed variables associated with the Event.
	Variables []Variable

	// Optional zpool status output logged with the Event.
	Status *Status
}

An Event is the processed version of a client Payload.

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON object for an Event.

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(b []byte) error

UnmarshalJSON unpacks the JSON for an Event.

type Handler

type Handler struct {
	// OnPayload is an optional hook which is fired when a valid zedhook payload
	// push request is sent to a Server. If not nil, the callback will be fired
	// with the contents of the Payload.
	OnPayload func(p Payload)
	// contains filtered or unexported fields
}

A Handler is an http.Handler for zedhookd logic.

func NewHandler

func NewHandler(ctx context.Context, s *Storage, ll *log.Logger, reg *prometheus.Registry) (*Handler, error)

NewHandler constructs a Handler and prepares it for use with the Server. If any of its dependencies are nil, defaults will be used.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type ListEventsOptions

type ListEventsOptions struct {
	Zpool, Class  string
	Offset, Limit int
}

ListEventsOptions provides arguments for the Storage.ListEvents method.

type Payload

type Payload struct {
	// Environment variable key/value pairs set by ZED and gathered by a Client.
	Variables []Variable

	// Optional data gathered by executing the zpool command.
	Zpool *ZpoolPayload
	// contains filtered or unexported fields
}

A Payload is the top-level zedhook payload container.

func (Payload) MarshalJSON

func (p Payload) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Payload) UnmarshalJSON

func (p *Payload) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (Payload) Version

func (p Payload) Version() Version

Version returns the Version value embedded in this Payload.

type Server

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

A Server is the zedhookd server entry point.

func NewServer

func NewServer(handler http.Handler, ll *log.Logger) *Server

NewServer constructs a Server which serves traffic using the input Handler.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve serves the zedhookd receiver and blocks until the context is canceled.

type Status

type Status struct {
	ID     int    `json:"id"`
	Status []byte `json:"status"`
}

A Status is a raw zpool status output.

type Storage

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

Storage is persistent storage backed by sqlite3.

func MemoryStorage

func MemoryStorage() *Storage

MemoryStorage creates ephemeral sqlite-backed in-memory storage.

func NewStorage

func NewStorage(ctx context.Context, dsn string) (*Storage, error)

NewStorage creates a sqlite-backed persistent storage using the input DSN.

func (*Storage) Close

func (s *Storage) Close() error

Close implements Storage.

func (*Storage) GetEvent

func (s *Storage) GetEvent(ctx context.Context, id int) (Event, error)

GetEvent gets an Event and its associated data by ID from the database.

func (*Storage) LatestEvents

func (s *Storage) LatestEvents(ctx context.Context) ([]Event, error)

LatestEvents lists the latest event of each unique class for each zpool from the database.

func (*Storage) ListEvents

func (s *Storage) ListEvents(ctx context.Context, o ListEventsOptions) ([]Event, error)

ListEvents lists Events from the database given a set of options.

func (*Storage) SaveEvent

func (s *Storage) SaveEvent(ctx context.Context, e Event) error

SaveEvent saves an Event in the database.

type Variable

type Variable struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

A Variable is a key/value pair for an environment variable passed by ZED.

type Version

type Version int

A Version is the version number for a Payload produced by a Client.

const V0 Version = iota

V0 is the initial, unstable version for zedhook Payload values.

type ZpoolPayload

type ZpoolPayload struct {
	// The raw output of 'zpool status tank'.
	RawStatus []byte `json:"raw_status"`
}

A ZpoolPayload contains information from executing a zpool command.

Jump to

Keyboard shortcuts

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