Documentation
¶
Overview ¶
Package webserver is a UniFi Poller plugin that exports running data to a web interface.
Index ¶
- Constants
- func NewInputEvent(name, id string, event *Event)
- func NewOutputEvent(name, id string, event *Event)
- func UpdateInput(config *Input)
- func UpdateInputCounter(plugin, label string, values ...int64)
- func UpdateOutput(config *Output)
- func UpdateOutputCounter(plugin, label string, values ...int64)
- type Client
- type Clients
- type Config
- type Device
- type Devices
- type Event
- type EventGroup
- type Events
- type Input
- type Output
- type ResponseWriter
- type Server
- func (s *Server) DebugOutput() (bool, error)
- func (s *Server) Enabled() bool
- func (s *Server) LogDebugf(msg string, v ...any)
- func (s *Server) LogErrorf(msg string, v ...any)
- func (s *Server) Logf(msg string, v ...any)
- func (s *Server) Run(c poller.Collect) error
- func (s *Server) Start() (err error)
- type Site
- type Sites
Constants ¶
const ( // PluginName identifies this output plugin. PluginName = "WebServer" // DefaultPort is the default web http port. DefaultPort = 37288 // DefaultEvents is the default number of events stored per plugin. DefaultEvents = 200 )
Variables ¶
This section is empty.
Functions ¶
func NewInputEvent ¶
NewInputEvent adds an event for an input plugin.
func NewOutputEvent ¶
NewOutputEvent adds an event for an output plugin.
func UpdateInput ¶
func UpdateInput(config *Input)
UpdateInput allows an input plugin to create an entry or update an existing entry.
func UpdateInputCounter ¶
UpdateInputCounter allows an input plugin to update a counter's value. Set any arbitrary counter. These are displayed on the web interface.
func UpdateOutput ¶
func UpdateOutput(config *Output)
UpdateOutput allows an output plugin to create an entry or update an existing entry.
func UpdateOutputCounter ¶
UpdateOutputCounter allows an output plugin to update a counter's value.
Types ¶
type Client ¶
type Client struct {
Rx int64 `json:"rx_bytes"`
Tx int64 `json:"tx_bytes"`
Name string `json:"name"`
SiteID string `json:"site_id"`
Source string `json:"source"`
Controller string `json:"controller"`
MAC string `json:"mac"`
IP string `json:"ip"`
Type string `json:"type"`
DeviceMAC string `json:"device_mac"`
Since time.Time `json:"since"`
Last time.Time `json:"last"`
}
Client holds the data for a network client.
type Config ¶
type Config struct {
Enable bool `json:"enable" toml:"enable" xml:"enable,attr" yaml:"enable"`
SSLCrtPath string `json:"ssl_cert_path" toml:"ssl_cert_path" xml:"ssl_cert_path" yaml:"ssl_cert_path"`
SSLKeyPath string `json:"ssl_key_path" toml:"ssl_key_path" xml:"ssl_key_path" yaml:"ssl_key_path"`
Port uint `json:"port" toml:"port" xml:"port" yaml:"port"`
Accounts accounts `json:"accounts" toml:"accounts" xml:"accounts" yaml:"accounts"`
HTMLPath string `json:"html_path" toml:"html_path" xml:"html_path" yaml:"html_path"`
MaxEvents uint `json:"max_events" toml:"max_events" xml:"max_events" yaml:"max_events"`
}
Config is the webserver library input config.
type Device ¶
type Device struct {
Clients int `json:"clients"`
Uptime int `json:"uptime"`
Name string `json:"name"`
SiteID string `json:"site_id"`
Source string `json:"source"`
Controller string `json:"controller"`
MAC string `json:"mac"`
IP string `json:"ip"`
Type string `json:"type"`
Model string `json:"model"`
Version string `json:"version"`
Config any `json:"config,omitempty"`
}
Device holds the data for a network device.
type Event ¶
type Event struct {
Ts time.Time `json:"ts"` // nolint: stylecheck
Msg string `json:"msg"`
Tags map[string]string `json:"tags,omitempty"`
}
Event is like a log message.
type EventGroup ¶
EventGroup allows each plugin to have a map of events. ie. one map per controller.
type Events ¶
type Events map[string]*EventGroup
Events is all the events a plugin has. string = SiteID + text, or plugin name, or "whatever".
type Input ¶
type Input struct {
Name string
Sites Sites
Events Events
Devices Devices
Clients Clients
Config any
Counter map[string]int64
sync.RWMutex // Locks this data structure.
}
Input is the data tracked for intput plugins. An input plugin should fill this data every time it polls this data. Partial update are OK. Set non-updated fields to nil and they're ignored.
type Output ¶
type Output struct {
Name string
Events Events
Config any
Counter map[string]int64
sync.RWMutex // Locks this data structure.
}
Output is the data tracked for output plugins. Output plugins should fill this data on startup, and regularly update counters for things worth counting. Setting Config will overwrite previous value.
type ResponseWriter ¶
type ResponseWriter struct {
Code int
Size int
Error string
Start time.Time
Writer http.ResponseWriter
}
ResponseWriter is used to override http.ResponseWriter in our http.FileServer. This allows us to catch and log the response code, size and error; maybe others.
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header() http.Header
Header sends a header to a client. Satisfies http.ResponseWriter interface.
func (*ResponseWriter) Write ¶
func (w *ResponseWriter) Write(b []byte) (int, error)
Write sends bytes to the client. Satisfies http.ResponseWriter interface. This also adds the written byte count to our size total.
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(code int)
WriteHeader sends an http StatusCode to a client. Satisfies http.ResponseWriter interface. This custom override method also saves the status code, and any error message (for logs).
type Server ¶
type Server struct {
*Config `json:"webserver" toml:"webserver" xml:"webserver" yaml:"webserver"`
Collect poller.Collect
// contains filtered or unexported fields
}
Server is the main library struct/data.