librenms

package
v0.0.0-...-aeb3b19 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlertFiring  = 1
	AlertCleared = 0
)

Variables

View Source
var ErrNotFound = errors.New("the request object was not found")

Functions

This section is empty.

Types

type AddDeviceResponse

type AddDeviceResponse struct {
	Devices []struct {
		DeviceID int         `json:"device_id"`
		Hostname string      `json:"hostname"`
		Serial   interface{} `json:"serial"`
	} `json:"devices"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

type Client

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

func NewClient

func NewClient(url string, token string, logger models.Logger) *Client

NewClient creates a new LibreNMS API client

func (*Client) AddDevice

func (c *Client) AddDevice(ip string) (deviceID int, err error)

AddDevice adds the given IP to LibreNMS to monitor. Returns the device ID assigned in LibreNMS

func (*Client) FindPortForIP

func (c *Client) FindPortForIP(ip string) (port Port, err error)

func (*Client) GetDevice

func (c *Client) GetDevice(deviceID int) (LibreDevice, error)

GetDevice returns the device with the corresponding ID

func (*Client) GetDeviceByIP

func (c *Client) GetDeviceByIP(ip string) (device LibreDevice, err error)

func (*Client) GetIPs

func (c *Client) GetIPs() (ipList []IP, err error)

func (*Client) GetPort

func (c *Client) GetPort(portID int) (port Port, err error)

GetPort returns the individual port request by ID

func (*Client) GetPortsForDevice

func (c *Client) GetPortsForDevice(id int) (ports []Port, err error)

GetPortsForDevice returns all of the ports for the given device. If the number of ports returned is zero an ErrNotFound is returned

func (*Client) LoadIPs

func (c *Client) LoadIPs() error

type IP

type IP struct {
	ContextName   string `json:"context_name"`
	Ipv4Address   string `json:"ipv4_address"`
	Ipv4AddressID int    `json:"ipv4_address_id"`
	Ipv4NetworkID string `json:"ipv4_network_id"`
	Ipv4Prefixlen int    `json:"ipv4_prefixlen"`
	PortID        int    `json:"port_id"`
}

type IPResponse

type IPResponse struct {
	Count       int    `json:"count"`
	IPAddresses []IP   `json:"ip_addresses"`
	Status      string `json:"status"`
}

type LibreAlert

type LibreAlert struct {
	DeviceID  int    `json:"device_id"`
	Host      string `json:"host"`
	ID        string `json:"id"`
	IP        string `json:"ip"`
	Location  string `json:"location"`
	Runbook   string `json:"runbook"`
	Severity  string `json:"severity"`
	State     int    `json:"state"`
	Subject   string `json:"subject"`
	SysName   string `json:"sysName"`
	Timestamp string `json:"timestamp"`
	UID       string `json:"uid"`
}

LibreAlert represents an API alert from LibreNMS. Transport configuration should look like this:

Transport Headers: Content-type=application/json Transport Body: ``` {"device_id": {{ $device_id }}, "timestamp": "{{ $timestamp }}", "subject": "{{ $title }}", "host": "{{ $hostname }}", "sysName": "{{ $sysName }}", "location": "{{ $location }}", "ip": "{{ $ip }}", "state": {{ $state }}, "severity": "{{ $severity }}", "id": "{{ $id }}", "uid": "{{ $uid }}", "runbook": "{{ $proc }}" } ```

type LibreDevice

type LibreDevice struct {
	Community           *string     `json:"community"`
	DeviceID            int         `json:"device_id"`
	DisableNotify       int         `json:"disable_notify"`
	Disabled            int         `json:"disabled"`
	Display             *string     `json:"display"`
	Features            interface{} `json:"features"`
	Hardware            *string     `json:"hardware"`
	Hostname            string      `json:"hostname"`
	IP                  string      `json:"ip"`
	Ignore              int         `json:"ignore"`
	IgnoreStatus        int         `json:"ignore_status"`
	Lat                 *float32    `json:"lat"`
	Lng                 *float32    `json:"lng"`
	Location            string      `json:"location"`
	LocationID          int         `json:"location_id"`
	MaxDepth            int         `json:"max_depth"`
	Notes               *string     `json:"notes"`
	Os                  string      `json:"os"`
	PollerGroup         int         `json:"poller_group"`
	Port                int         `json:"port"`
	PortAssociationMode int         `json:"port_association_mode"`
	Purpose             *string     `json:"purpose"`
	Serial              *string     `json:"serial"`
	Status              bool        `json:"status"`
	StatusReason        string      `json:"status_reason"`
	SysContact          *string     `json:"sysContact"`
	SysDescr            *string     `json:"sysDescr"`
	SysName             *string     `json:"sysName"`
	SysObjectID         *string     `json:"sysObjectID"`
	Type                *string     `json:"type"`
	Uptime              int         `json:"uptime"`
	Version             *string     `json:"version"`
}

type LibreDeviceResponse

type LibreDeviceResponse struct {
	Count   int           `json:"count"`
	Devices []LibreDevice `json:"devices"`
	Status  string        `json:"status"`
}

type LibreErrorResponse

type LibreErrorResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
}

LibreErrorResponse can be used to decode the body when a non-2xx status is returned

func GetLibreError

func GetLibreError(resp *resty.Response) (LibreErrorResponse, error)

type Port

type Port struct {
	DeviceID           int     `json:"device_id"`
	IfAdminStatus      string  `json:"ifAdminStatus"`
	IfAdminStatusPrev  string  `json:"ifAdminStatus_prev"`
	IfAlias            string  `json:"ifAlias"`
	IfConnectorPresent string  `json:"ifConnectorPresent"`
	IfDescr            string  `json:"ifDescr"`
	IfDuplex           *string `json:"ifDuplex"`
	IfMtu              int     `json:"ifMtu"`
	IfName             string  `json:"ifName"`
	IfOperStatus       string  `json:"ifOperStatus"`
	IfOperStatusPrev   string  `json:"ifOperStatus_prev"`
	IfSpeed            *int    `json:"ifSpeed"`
	IfSpeedPrev        int     `json:"ifSpeed_prev"`
	IfType             string  `json:"ifType"`
	IfPhysAddress      *string `json:"ifPhysAddress"`
	IfVlan             *string `json:"ifVlan"`
	IfTrunk            *string `json:"ifTrunk"`
	PortDescrCircuit   *string `json:"port_descr_circuit"`
	PortDescrDescr     *string `json:"port_descr_descr"`
	PortDescrNotes     *string `json:"port_descr_notes"`
	PortDescrSpeed     *int    `json:"port_descr_speed"`
	PortDescrType      *string `json:"port_descr_type"`
	PortID             int     `json:"port_id"`
	PortName           *string `json:"portName"`
}

func (Port) GetDuplex

func (p Port) GetDuplex() string

func (Port) GetPhysAddress

func (p Port) GetPhysAddress() string

func (Port) GetSpeed

func (p Port) GetSpeed() int

type PortResponse

type PortResponse struct {
	Count  int    `json:"count"`
	Ports  []Port `json:"port"`
	Status string `json:"status"`
}

PortResponse is returned when querying for a given port

type PortSearchResponse

type PortSearchResponse struct {
	Ports  []Port `json:"ports"`
	Status string `json:"status"`
}

Jump to

Keyboard shortcuts

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