edgemax

package module
v0.0.0-...-d19893e Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2018 License: MIT Imports: 15 Imported by: 2

README

edgemax GoDoc Build Status Coverage Status Report Card

Package edgemax implements a client for Ubiquiti EdgeMAX devices. MIT Licensed.

Documentation

Overview

Package edgemax implements a client for Ubiquiti EdgeMAX devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsecureHTTPClient

func InsecureHTTPClient(timeout time.Duration) *http.Client

InsecureHTTPClient creates a *http.Client which does not verify an EdgeMAX device's certificate chain and hostname.

Please think carefully before using this client: it should only be used with self-hosted, internal EdgeMAX devices.

Types

type Client

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

A Client is a client for a Ubiquiti EdgeMAX device.

Client.Login must be called and return a nil error before any additional actions can be performed with a Client.

func NewClient

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

NewClient creates a new Client, using the input EdgeMAX device address and an optional HTTP client. If no HTTP client is specified, a default one will be used.

If working with a self-hosted EdgeMAX device which does not have a valid TLS certificate, InsecureHTTPClient can be used.

Client.Login must be called and return a nil error before any additional actions can be performed with a Client.

func (*Client) Login

func (c *Client) Login(username string, password string) error

Login authenticates against the EdgeMAX device using the specified username and password. Login must be called and return a nil error before any additional actions can be performed.

func (*Client) Stats

func (c *Client) Stats(stats ...StatType) (statC chan Stat, done func() error, err error)

Stats opens a websocket connection to an EdgeMAX device to retrieve statistics which are sent using the socket. The done closure must be invoked to clean up resources from Stats.

type DPIStat

type DPIStat struct {
	IP            net.IP
	Type          string
	Category      string
	ReceiveBytes  int
	ReceiveRate   int
	TransmitBytes int
	TransmitRate  int
}

A DPIStat contains Deep Packet Inspection stats from an EdgeMAX device, for an individual client and traffic type.

type DPIStats

type DPIStats []*DPIStat

DPIStats is a slice of DPIStat values, and contains Deep Packet Inspection stats from an EdgeMAX device.

func (DPIStats) StatType

func (d DPIStats) StatType() StatType

StatType implements the Stats interface.

func (*DPIStats) UnmarshalJSON

func (d *DPIStats) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON into a DPIStats.

type Interface

type Interface struct {
	Name            string
	Up              bool
	Autonegotiation bool
	Duplex          string
	Speed           int
	MAC             net.HardwareAddr
	MTU             int
	Addresses       []net.IP
	Stats           InterfaceStats
}

An Interface is an EdgeMAX network interface.

type InterfaceStats

type InterfaceStats struct {
	ReceivePackets  int
	TransmitPackets int
	ReceiveBytes    int
	TransmitBytes   int
	ReceiveErrors   int
	TransmitErrors  int
	ReceiveDropped  int
	TransmitDropped int
	Multicast       int
	ReceiveBPS      int
	TransmitBPS     int
}

InterfaceStats contains network interface data transmission statistics.

type Interfaces

type Interfaces []*Interface

Interfaces is a slice of Interface values, which contains information about network interfaces for EdgeMAX devices.

func (Interfaces) StatType

func (i Interfaces) StatType() StatType

StatType implements the Stats interface.

func (*Interfaces) UnmarshalJSON

func (i *Interfaces) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON into an Interfaces.

type Stat

type Stat interface {
	StatType() StatType
}

A Stat is a statistic provided by an EdgeMAX device. Type assertions can be used to determine the specific type of a Stat, and to access a Stat's fields.

type StatType

type StatType string

A StatType is a type of Stat. StatType values can be used to retrieve certain types of Stats from Client.Stats

const (
	// StatTypeDPIStats retrieves EdgeMAX deep packet inspection statistics.
	StatTypeDPIStats StatType = "export"

	// StatTypeSystemStats retrieves EdgeMAX system statistics, including
	// system uptime, CPU utilization, and memory utilization.
	StatTypeSystemStats StatType = "system-stats"

	// StatTypeInterfaces retrieves EdgeMAX network interface statistics.
	StatTypeInterfaces StatType = "interfaces"
)

type SystemStats

type SystemStats struct {
	CPU    int
	Uptime time.Duration
	Memory int
}

SystemStats is a Stat which contains system statistics for an EdgeMAX device.

func (*SystemStats) StatType

func (ss *SystemStats) StatType() StatType

StatType implements the Stats interface.

func (*SystemStats) UnmarshalJSON

func (ss *SystemStats) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON into a SystemStats.

Jump to

Keyboard shortcuts

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