librenms

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 15 Imported by: 0

README

go-librenms

A Go client library for interacting with the LibreNMS API.

Installation

To use this library, you can import it into your Go project:

import "github.com/jokelyo/go-librenms"

Then, run go get to download and install the package:

go get github.com/jokelyo/go-librenms

Example Usage

Here's a basic example of how to use the library to create a new LibreNMS client and get a device:

package main

import (
	"fmt"
	"log"

	"github.com/jokelyo/go-librenms"
)

func main() {
	// Replace with your LibreNMS API URL and token
	baseURL := "https://your-librenms-instance.com/"
	token := "YOUR_API_TOKEN"

	// Create a new LibreNMS client
	client, err := librenms.New(baseURL, token)
	if err != nil {
		log.Fatalf("Error creating LibreNMS client: %v", err)
	}

	// Get a device by its hostname or ID
	// Replace "device-hostname-or-id" with the actual hostname or ID
	deviceIdentifier := "device-hostname-or-id"
	deviceResp, err := client.GetDevice(deviceIdentifier)
	if err != nil {
		log.Fatalf("Error getting device: %v", err)
	}

	// Print device information
	if len(deviceResp.Devices) > 0 {
		fmt.Printf("Device ID: %d\n", deviceResp.Devices[0].DeviceID)
		fmt.Printf("Hostname: %s\n", deviceResp.Devices[0].Hostname)
		fmt.Printf("OS: %s\n", deviceResp.Devices[0].OS)
	} else {
		fmt.Println("No device found.")
	}
}
Creating a Device Example

Here's an example of how to create a new device in LibreNMS:

// Initialize the device creation request
deviceCreateReq := &librenms.DeviceCreateRequest{
    Hostname:      "192.168.1.10",
    Display:       "My New Router",
    SNMPCommunity: "public",
    SNMPVersion:   "v2c",
}

// Create the device
deviceResp, err := client.CreateDevice(deviceCreateReq)
if err != nil {
    log.Fatalf("Error creating device: %v", err)
}

// Handle the response
fmt.Printf("Device created successfully! Device ID: %d\n", deviceResp.Devices[0].DeviceID)
fmt.Printf("Hostname: %s\n", deviceResp.Devices[0].Hostname)

Documentation

Overview

Package librenms provides a client for interacting with the LibreNMS API.

The package supports CRUD operations for the following resources, which are used within the Terraform provider at https://github.com/jokelyo/terraform-provider-librenms:

  • Alert Rules
  • Devices
  • Device Groups
  • Locations
  • Services

LibreNMS API Documentation: https://docs.librenms.org/API/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert added in v0.2.0

type Alert struct {
	ID           int     `json:"id"`
	Alerted      Bool    `json:"alerted"`
	DeviceID     int     `json:"device_id"`
	Hostname     string  `json:"hostname"`
	Info         string  `json:"info"`
	Name         string  `json:"name"`
	Note         *string `json:"note"`
	Notes        *string `json:"notes"`
	Open         Bool    `json:"open"`
	ProcedureURL *string `json:"proc"`
	RuleID       int     `json:"rule_id"`
	Severity     string  `json:"severity"` // "ok", "warning", "critical"
	State        int     `json:"state"`    // 0 = ok, 1 = alert, 2 = ack
	Timestamp    string  `json:"timestamp"`
}

Alert represents a LibreNMS alert.

Pointers are used for fields that may be null. A custom type Bool is used to represent booleans that may be defined as 0/1 by the API.

type AlertAckRequest added in v0.2.0

type AlertAckRequest struct {
	Note       string `json:"note,omitempty"`
	UntilClear bool   `json:"until_clear"` // if set to false, the alert will re-alert if it gets worse/better or changes
}

AlertAckRequest represents the request payload for acknowledging an alert.

type AlertRule

type AlertRule struct {
	ID           int     `json:"id"`
	Builder      string  `json:"builder"`
	Devices      []int   `json:"devices"`
	Disabled     Bool    `json:"disabled"`
	Extra        string  `json:"extra"`
	Groups       []int   `json:"groups"`
	InvertMap    Bool    `json:"invert_map"`
	Locations    []int   `json:"locations"`
	Name         string  `json:"name"`
	Notes        *string `json:"notes"`
	ProcedureURL *string `json:"proc"`
	Query        string  `json:"query"`
	Rule         string  `json:"rule"`
	Severity     string  `json:"severity"`
}

AlertRule represents an alert rule in LibreNMS.

See https://docs.librenms.org/API/Alerts/#add_rule for field descriptions.

type AlertRuleCreateRequest

type AlertRuleCreateRequest struct {
	Builder      string `json:"builder"`         // encoded JSON
	Count        int    `json:"count,omitempty"` // Max Alerts in the UI
	Delay        string `json:"delay,omitempty"`
	Devices      []int  `json:"devices"`
	Disabled     Bool   `json:"disabled,omitempty"`
	Groups       []int  `json:"groups"`
	Interval     string `json:"interval,omitempty"`
	Locations    []int  `json:"locations"`
	Mute         bool   `json:"mute,omitempty"`
	Name         string `json:"name"`
	Notes        string `json:"notes,omitempty"`
	ProcedureURL string `json:"proc,omitempty"`
	Query        string `json:"query,omitempty"`
	Rule         string `json:"rule,omitempty"`
	Severity     string `json:"severity"` // ok, warning, critical
}

AlertRuleCreateRequest is the request structure for creating an alert rule.

See https://docs.librenms.org/API/Alerts/#add_rule for field descriptions.

type AlertRuleResponse

type AlertRuleResponse struct {
	BaseResponse
	Rules []AlertRule `json:"rules"`
}

AlertRuleResponse is the response structure for alert rules.

type AlertRuleUpdateRequest

type AlertRuleUpdateRequest struct {
	AlertRuleCreateRequest
	ID int `json:"rule_id"`
}

AlertRuleUpdateRequest is the request structure for updating an alert rule.

type AlertsQuery added in v0.2.0

type AlertsQuery struct {
	Order    *string `url:"order"`
	RuleID   *int    `url:"alert_rule"`
	Severity *string `url:"severity"` // "ok", "warning", "critical"
	State    *int    `url:"state"`    // 0 = ok, 1 = alert, 2 = ack
}

AlertsQuery represents the query parameters for GetAlerts().

Documentation: https://docs.librenms.org/API/Alerts/#list_alerts

func NewAlertsQuery added in v0.2.0

func NewAlertsQuery() *AlertsQuery

NewAlertsQuery creates a new AlertsQuery with default values.

func (*AlertsQuery) SetOrder added in v0.2.0

func (q *AlertsQuery) SetOrder(order string) *AlertsQuery

SetOrder sets the order for the AlertsQuery.

func (*AlertsQuery) SetRuleID added in v0.2.0

func (q *AlertsQuery) SetRuleID(ruleID int) *AlertsQuery

SetRuleID sets the rule ID for the AlertsQuery.

func (*AlertsQuery) SetSeverity added in v0.2.0

func (q *AlertsQuery) SetSeverity(severity string) *AlertsQuery

SetSeverity sets the severity for the AlertsQuery.

func (*AlertsQuery) SetState added in v0.2.0

func (q *AlertsQuery) SetState(state int) *AlertsQuery

SetState sets the state for the AlertsQuery.

type AlertsResponse added in v0.2.0

type AlertsResponse struct {
	BaseResponse
	Alerts []Alert `json:"alerts"`
}

AlertsResponse represents the response from the alerts API endpoint.

type BaseResponse

type BaseResponse struct {
	// Status indicates the success or failure of the API call.
	Status string `json:"status"`
	// Message contains additional information about the API call.
	Message string `json:"message"`
	Count   int    `json:"count"`
}

BaseResponse is the base structure for API responses.

type Bool

type Bool bool

Bool represents a boolean value, used for JSON marshaling. The API returns some fields as 0/1 instead of true/false, so we use this custom type.

func (*Bool) MarshalJSON

func (b *Bool) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaling for the Bool type.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshalling for the Bool type.

type Client

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

Client is the main structure for the LibreNMS client.

func New

func New(baseURL, token string, opts ...Option) (*Client, error)

New creates a new LibreNMS client with the given base URL and options. The base URL should be in the format 'http[s]://<host>[:port]/'.

func (*Client) AckAlert added in v0.2.0

func (c *Client) AckAlert(alertID int, payload *AlertAckRequest) (*BaseResponse, error)

AckAlert acknowledges an alert by its ID in the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#ack_alert

func (*Client) CreateAlertRule

func (c *Client) CreateAlertRule(payload *AlertRuleCreateRequest) (*BaseResponse, error)

CreateAlertRule creates a specific alert rule in the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#add_rule

func (*Client) CreateDevice

func (c *Client) CreateDevice(payload *DeviceCreateRequest) (*DeviceResponse, error)

CreateDevice creates a device by hostname/IP.

Documentation: https://docs.librenms.org/API/Devices/#add_device

func (*Client) CreateDeviceGroup

func (c *Client) CreateDeviceGroup(group *DeviceGroupCreateRequest) (*DeviceGroupCreateResponse, error)

CreateDeviceGroup creates a device group in the LibreNMS API.

Documentation: https://docs.librenms.org/API/DeviceGroups/#add_devicegroup

func (*Client) CreateLocation

func (c *Client) CreateLocation(location *LocationCreateRequest) (*BaseResponse, error)

CreateLocation creates a new location in the LibreNMS API.

Documentation: https://docs.librenms.org/API/Locations/#add_location

func (*Client) CreateService

func (c *Client) CreateService(deviceIdentifier string, service *ServiceCreateRequest) (*ServiceResponse, error)

CreateService creates a service for the specified device id or hostname.

Documentation: https://docs.librenms.org/API/Services/#add_service_for_host

func (*Client) DeleteAlertRule

func (c *Client) DeleteAlertRule(id int) (*BaseResponse, error)

DeleteAlertRule deletes a specific alert rule by its ID from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#delete_rule

func (*Client) DeleteDevice

func (c *Client) DeleteDevice(identifier string) (*DeviceResponse, error)

DeleteDevice deletes a device by its ID or hostname from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Devices/#del_device

func (*Client) DeleteDeviceGroup

func (c *Client) DeleteDeviceGroup(identifier string) (*BaseResponse, error)

DeleteDeviceGroup deletes a group by its ID or hostname from the LibreNMS API.

Documentation: https://docs.librenms.org/API/DeviceGroups/#delete_devicegroup

func (*Client) DeleteLocation

func (c *Client) DeleteLocation(locationID int) (*BaseResponse, error)

DeleteLocation deletes a location by its ID in the LibreNMS API.

Documentation: https://docs.librenms.org/API/Locations/#delete_location

func (*Client) DeleteService

func (c *Client) DeleteService(serviceID int) (*BaseResponse, error)

DeleteService deletes a service by its ID.

Documentation: https://docs.librenms.org/API/Services/#delete_service_from_host

func (*Client) GetAlert added in v0.2.0

func (c *Client) GetAlert(alertID int) (*AlertsResponse, error)

GetAlert retrieves a specific alert by its ID from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#get_alert

func (*Client) GetAlertRule

func (c *Client) GetAlertRule(id int) (*AlertRuleResponse, error)

GetAlertRule retrieves a specific alert rule by its ID from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#get_alert_rule

func (*Client) GetAlertRules

func (c *Client) GetAlertRules() (*AlertRuleResponse, error)

GetAlertRules retrieves all alert rules from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#list_alert_rules

func (*Client) GetAlerts added in v0.2.0

func (c *Client) GetAlerts(query *AlertsQuery) (*AlertsResponse, error)

GetAlerts retrieves a list of alerts from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#list_alerts

func (*Client) GetDevice

func (c *Client) GetDevice(identifier string) (*DeviceResponse, error)

GetDevice retrieves a device by its ID or hostname from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Devices/#get_device

func (*Client) GetDeviceGroup

func (c *Client) GetDeviceGroup(identifier string) (*DeviceGroupResponse, error)

GetDeviceGroup uses the same endpoint as GetDeviceGroups, but it returns a modified payload with the single host (if a match is found). This is primarily a convenience function for the Terraform provider.

func (*Client) GetDeviceGroupMembers

func (c *Client) GetDeviceGroupMembers(identifier string) (*DeviceGroupMembersResponse, error)

GetDeviceGroupMembers retrieves a list of device group members from the LibreNMS API. The identifier can be either the group ID or the group name.

Documentation: https://docs.librenms.org/API/DeviceGroups/#get_devices_by_group

func (*Client) GetDeviceGroups

func (c *Client) GetDeviceGroups() (*DeviceGroupResponse, error)

GetDeviceGroups retrieves a list of device groups from the LibreNMS API.

Documentation: https://docs.librenms.org/API/DeviceGroups/#get_devicegroups

func (*Client) GetDevices

func (c *Client) GetDevices(query *DevicesQuery) (*DeviceResponse, error)

GetDevices retrieves a list of devices from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Devices/#list_devices

func (*Client) GetLocation

func (c *Client) GetLocation(locationID int) (*LocationResponse, error)

GetLocation retrieves a location by its ID from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Locations/#get_location

func (*Client) GetLocations

func (c *Client) GetLocations() (*LocationsResponse, error)

GetLocations retrieves a list of locations from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Locations/#list_locations

func (*Client) GetService

func (c *Client) GetService(serviceID int) (*ServiceResponse, error)

GetService retrieves a service by ID from the LibreNMS API.

Similar to GetDeviceGroup, this uses the same endpoint as GetServices, but it returns a modified payload with the single host (if a match is found). This is primarily a convenience function for the Terraform provider.

func (*Client) GetServices

func (c *Client) GetServices() (*ServiceResponse, error)

GetServices retrieves all services from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Services/#list_services

func (*Client) GetServicesForHost

func (c *Client) GetServicesForHost(deviceIdentifier string) (*ServiceResponse, error)

GetServicesForHost retrieves all services for a specific host by ID or name from the LibreNMS API.

Documentation: https://docs.librenms.org/API/Services/#get_service_for_host

func (*Client) UnmuteAlert added in v0.2.0

func (c *Client) UnmuteAlert(alertID int) (*BaseResponse, error)

UnmuteAlert unmutes an alert by its ID in the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#unmute_alert

func (*Client) UpdateAlertRule

func (c *Client) UpdateAlertRule(payload *AlertRuleUpdateRequest) (*BaseResponse, error)

UpdateAlertRule updates a specific alert rule in the LibreNMS API.

Documentation: https://docs.librenms.org/API/Alerts/#edit_rule

func (*Client) UpdateDevice

func (c *Client) UpdateDevice(identifier string, payload *DeviceUpdateRequest) (*BaseResponse, error)

UpdateDevice updates a device by its ID or hostname.

Documentation: https://docs.librenms.org/API/Devices/#update_device_field

func (*Client) UpdateDeviceGroup

func (c *Client) UpdateDeviceGroup(identifier string, payload *DeviceGroupUpdateRequest) (*BaseResponse, error)

UpdateDeviceGroup updates an existing device group in the LibreNMS API.

The documentation states it uses name rather than ID to reference the group, but both seem to work (as of v25.5). Documentation: https://docs.librenms.org/API/DeviceGroups/#update_devicegroup

func (*Client) UpdateLocation

func (c *Client) UpdateLocation(locationID int, location *LocationUpdateRequest) (*BaseResponse, error)

UpdateLocation updates a location by its ID in the LibreNMS API.

Documentation: https://docs.librenms.org/API/Locations/#edit_location

func (*Client) UpdateService

func (c *Client) UpdateService(serviceID int, service *ServiceUpdateRequest) (*ServiceResponse, error)

UpdateService updates a service for the specified service ID.

Documentation: https://docs.librenms.org/API/Services/#edit_service_from_host

type Device

type Device struct {
	DeviceID int `json:"device_id"`

	AgentUptime             int      `json:"agent_uptime"`
	AuthAlgorithm           *string  `json:"authalgo"`
	AuthLevel               *string  `json:"authlevel"`
	AuthName                *string  `json:"authname"`
	AuthPass                *string  `json:"authpass"`
	BGPLocalAS              *int     `json:"bgpLocalAs"`
	Community               *string  `json:"community"`
	CryptoAlgorithm         *string  `json:"cryptoalgo"`
	CryptoPass              *string  `json:"cryptopass"`
	DisableNotify           Bool     `json:"disable_notify"`
	Disabled                Bool     `json:"disabled"`
	Display                 *string  `json:"display"`
	Features                *string  `json:"features"`
	Hardware                string   `json:"hardware"`
	Hostname                string   `json:"hostname"`
	Icon                    string   `json:"icon"`
	Ignore                  Bool     `json:"ignore"`
	IgnoreStatus            Bool     `json:"ignore_status"`
	Inserted                string   `json:"inserted"`
	IP                      string   `json:"ip"`
	LastDiscovered          *string  `json:"last_discovered"`
	LastDiscoveredTimeTaken float64  `json:"last_discovered_timetaken"`
	LastPing                *string  `json:"last_ping"`
	LastPingTimeTaken       float64  `json:"last_ping_timetaken"`
	LastPollAttempted       *string  `json:"last_poll_attempted"`
	LastPolled              *string  `json:"last_pulled"`
	LastPolledTimeTaken     float64  `json:"last_polled_timetaken"`
	Latitude                *Float64 `json:"lat"`
	Longitude               *Float64 `json:"lng"`
	Location                *string  `json:"location"`
	LocationID              *int     `json:"location_id"`
	MaxDepth                *int     `json:"max_depth"`
	Notes                   *string  `json:"notes"`
	OS                      string   `json:"os"`
	OverrideSysLocation     Bool     `json:"override_sysLocation"`
	OverwriteIP             string   `json:"overwrite_ip"`
	PollerGroup             int      `json:"poller_group"`
	Port                    int      `json:"port"`
	PortAssociationMode     int      `json:"port_association_mode"`
	Purpose                 *string  `json:"purpose"`
	Retries                 *int     `json:"retries"`
	Serial                  *string  `json:"serial"`
	SNMPDisable             Bool     `json:"snmp_disable"`
	SNMPVersion             string   `json:"snmpver"`
	Status                  Bool     `json:"status"` // /devices returns 0/1, and /devices/:id returns true/false
	StatusReason            string   `json:"status_reason"`
	SysContact              *string  `json:"sysContact"`
	SysDescr                *string  `json:"sysDescr"`
	SysName                 string   `json:"sysName"`
	SysObjectID             *string  `json:"sysObjectID"`
	Timeout                 *int     `json:"timeout"`
	Transport               string   `json:"transport"`
	Type                    string   `json:"type"`
	Uptime                  *int64   `json:"uptime"`
	Version                 *string  `json:"version"`
}

Device represents a device in LibreNMS.

Pointers are used for fields that may be null. A custom type Bool is used to represent booleans that may be defined as 0/1 by the API.

type DeviceCreateRequest

type DeviceCreateRequest struct {
	Hostname            string `json:"hostname"`
	Display             string `json:"display,omitempty"`
	ForceAdd            bool   `json:"force_add,omitempty"`
	Hardware            string `json:"hardware,omitempty"`
	Location            string `json:"location,omitempty"`
	LocationID          int    `json:"location_id,omitempty"`
	OS                  string `json:"os,omitempty"`
	OverrideSysLocation bool   `json:"override_sysLocation,omitempty"`
	PingFallback        bool   `json:"ping_fallback,omitempty"`
	PollerGroup         int    `json:"poller_group,omitempty"`
	Port                int    `json:"port,omitempty"`
	PortAssocMode       int    `json:"port_association_mode,omitempty"` // ifIndex(1), ifName(2), ifDescr(3), ifAlias(4)
	SNMPAuthAlgo        string `json:"authalgo,omitempty"`              // MD5, SHA, SHA-224, SHA-256, SHA384, SHA-512
	SNMPAuthLevel       string `json:"authlevel,omitempty"`             // noAuthNoPriv, authNoPriv, authPriv
	SNMPAuthName        string `json:"authname,omitempty"`
	SNMPAuthPass        string `json:"authpass,omitempty"`
	SNMPCrytoAlgo       string `json:"cryptoalgo,omitempty"` // DES, AES, AES-192, AES-256, AES-256-C
	SNMPCryptoPass      string `json:"cryptopass,omitempty"`
	SNMPCommunity       string `json:"community,omitempty"`
	SNMPDisable         bool   `json:"snmp_disable,omitempty"`
	SNMPVersion         string `json:"snmpver,omitempty"` // v1, v2c, v3
	SysName             string `json:"sysName,omitempty"`
	Transport           string `json:"transport,omitempty"`
}

DeviceCreateRequest represents the request body for creating a new device in LibreNMS.

type DeviceGroup

type DeviceGroup struct {
	ID          int                      `json:"id"`
	Name        string                   `json:"name"`
	Description *string                  `json:"desc"`
	Pattern     *string                  `json:"pattern"`
	Rules       DeviceGroupRuleContainer `json:"rules"`
	Type        string                   `json:"type"`
}

DeviceGroup represents a device group in LibreNMS.

type DeviceGroupCreateRequest

type DeviceGroupCreateRequest struct {
	Name        string  `json:"name"`
	Description *string `json:"desc,omitempty"`
	Devices     []int   `json:"devices,omitempty"`
	Rules       *string `json:"rules,omitempty"`
	Type        string  `json:"type"`
}

DeviceGroupCreateRequest represents the request payload for creating a device group.

The rules should be a serialized JSON string that matches the DeviceGroupRuleContainer structure. Define your rules using the DeviceGroupRuleContainer struct and then serialize it using its JSON() method.

type DeviceGroupCreateResponse

type DeviceGroupCreateResponse struct {
	BaseResponse
	ID int `json:"id"`
}

DeviceGroupCreateResponse represents a creation response.

type DeviceGroupMember

type DeviceGroupMember struct {
	ID int `json:"device_id"`
}

DeviceGroupMember represents a member of a device group.

type DeviceGroupMembersResponse

type DeviceGroupMembersResponse struct {
	BaseResponse
	Devices []DeviceGroupMember `json:"devices"`
}

DeviceGroupMembersResponse represents a response containing the members of a device group.

type DeviceGroupResponse

type DeviceGroupResponse struct {
	BaseResponse
	Groups []DeviceGroup `json:"groups"`
}

DeviceGroupResponse represents a response containing a list of device groups from the LibreNMS API.

type DeviceGroupRule

type DeviceGroupRule struct {
	ID        string            `json:"id,omitempty"`
	Condition string            `json:"condition,omitempty"`
	Field     string            `json:"field,omitempty"`
	Input     string            `json:"input,omitempty"`
	Operator  string            `json:"operator,omitempty"`
	Rules     []DeviceGroupRule `json:"rules,omitempty"`
	Type      string            `json:"type,omitempty"`
	Value     string            `json:"value,omitempty"`
}

DeviceGroupRule represents a rule within a device group. This is a recursive structure. It can contain nested rules, allowing for complex conditions.

A terminal section defines id, field, type, input, operator, and value. A non-terminal section defines condition and a list of rules.

type DeviceGroupRuleContainer

type DeviceGroupRuleContainer struct {
	Condition string            `json:"condition"`
	Joins     [][]string        `json:"joins"`
	Rules     []DeviceGroupRule `json:"rules"`
	Valid     bool              `json:"valid""`
}

DeviceGroupRuleContainer represents the top-level container for device group rules.

func (*DeviceGroupRuleContainer) JSON

func (g *DeviceGroupRuleContainer) JSON() (string, error)

JSON is a helper function that serializes the DeviceGroupRuleContainer to JSON format.

func (*DeviceGroupRuleContainer) MustJSON

func (g *DeviceGroupRuleContainer) MustJSON() string

MustJSON is a helper function that serializes the DeviceGroupRuleContainer to JSON format. It returns an empty string if the marshalling fails.

type DeviceGroupUpdateRequest

type DeviceGroupUpdateRequest struct {
	Name        string  `json:"name,omitempty"`
	Description *string `json:"desc,omitempty"`
	Devices     []int   `json:"devices,omitempty"`
	Rules       *string `json:"rules,omitempty"`
	Type        string  `json:"type,omitempty"`
}

DeviceGroupUpdateRequest represents the request payload for updating a device group.

The rules should be a serialized JSON string that matches the DeviceGroupRuleContainer structure. Define your rules using the DeviceGroupRuleContainer struct and then serialize it using its JSON() method.

type DeviceResponse

type DeviceResponse struct {
	BaseResponse
	Devices []Device `json:"devices"`
}

DeviceResponse represents a response containing a list of devices from the LibreNMS API.

type DeviceUpdateRequest

type DeviceUpdateRequest struct {
	Field []string `json:"field"`
	Data  []any    `json:"data"`
}

DeviceUpdateRequest represents the request body for updating a device in LibreNMS.

The `Field` slice contains the names of the field(s) to update, and `Data` contains the corresponding values. Only specify the fields you want to update.

type DevicesQuery

type DevicesQuery struct {
	DeviceID   int    `url:"device_id,omitempty"`
	Display    string `url:"display,omitempty"`
	Hostname   string `url:"hostname,omitempty"`
	IPv4       string `url:"ipv4,omitempty"`
	IPv6       string `url:"ipv6,omitempty"`
	Location   string `url:"location,omitempty"`
	LocationID int    `url:"location_id,omitempty"`
	MACAddress string `url:"mac,omitempty"`
	Order      string `url:"order,omitempty"`
	OS         string `url:"os,omitempty"`
	SysName    string `url:"sysName,omitempty"`
	Type       string `url:"type,omitempty"`
}

DevicesQuery represents the query parameters for filtering GetDevices().

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response `json:"-"`
	Message  string         `json:"message"`
	Status   string         `json:"status"`
}

ErrorResponse represents an error response from the LibreNMS API.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

Error implements the error interface for ErrorResponse.

type Float64 added in v0.1.2

type Float64 float64

Float64 represents a float64 value, used for JSON marshaling. The API returns some fields as strings instead of numbers, so we use this custom type.

func (*Float64) MarshalJSON added in v0.1.2

func (f *Float64) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaling for the Float64 type.

func (*Float64) UnmarshalJSON added in v0.1.2

func (f *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshalling for the Float64 type.

type Location

type Location struct {
	ID               int     `json:"id"`
	FixedCoordinates Bool    `json:"fixed_coordinates"`
	Latitude         Float64 `json:"lat"`
	Longitude        Float64 `json:"lng"`
	Name             string  `json:"location"`
	Timestamp        string  `json:"timestamp"`
}

Location represents a location in LibreNMS.

type LocationCreateRequest

type LocationCreateRequest struct {
	Name             string  `json:"location"`
	FixedCoordinates Bool    `json:"fixed_coordinates"`
	Latitude         float64 `json:"lat"`
	Longitude        float64 `json:"lng"`
}

LocationCreateRequest represents the request payload for creating a location.

type LocationResponse

type LocationResponse struct {
	Status   string   `json:"status"`
	Location Location `json:"get_location"`
}

LocationResponse represents a response containing a single location from the LibreNMS API.

type LocationUpdateRequest

type LocationUpdateRequest struct {
	Name             *string
	FixedCoordinates *bool
	Latitude         *float64
	Longitude        *float64
}

LocationUpdateRequest represents the request payload for updating a location.

Only set the field(s) you want to update. Trying to patch fields that have not changed will result in an HTTP 500 error.

func NewLocationUpdateRequest

func NewLocationUpdateRequest() *LocationUpdateRequest

NewLocationUpdateRequest creates a new, empty LocationUpdateRequest.

func (*LocationUpdateRequest) SetFixedCoordinates

func (r *LocationUpdateRequest) SetFixedCoordinates(fixed bool) *LocationUpdateRequest

SetFixedCoordinates sets whether the location has fixed coordinates in the LocationUpdateRequest.

func (*LocationUpdateRequest) SetLatitude

SetLatitude sets the latitude of the location in the LocationUpdateRequest.

func (*LocationUpdateRequest) SetLongitude

func (r *LocationUpdateRequest) SetLongitude(lng float64) *LocationUpdateRequest

SetLongitude sets the longitude of the location in the LocationUpdateRequest.

func (*LocationUpdateRequest) SetName

SetName sets the name of the location in the LocationUpdateRequest.

type LocationsResponse

type LocationsResponse struct {
	BaseResponse
	Locations []Location `json:"locations"`
}

LocationsResponse represents a response containing a list of locations from the LibreNMS API.

type Option

type Option func(*Client)

Option is a function that configures the Client.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the HTTP client for the LibreNMS client.

func WithLogLevel added in v0.3.0

func WithLogLevel(level slog.Level) Option

WithLogLevel sets the logging level for the default client logger. The default level is slog.LevelInfo.

func WithLogger added in v0.3.0

func WithLogger(logger *slog.Logger) Option

WithLogger sets a custom logger for the LibreNMS client.

type Service

type Service struct {
	ID          int    `json:"service_id"`
	Changed     int64  `json:"service_changed"`
	Description string `json:"service_desc"`
	DeviceID    int    `json:"device_id"`
	DS          string `json:"service_ds"`
	Ignore      Bool   `json:"service_ignore"`
	IP          string `json:"service_ip"`
	Message     string `json:"service_message"`
	Name        string `json:"service_name"`
	Param       string `json:"service_param"`
	Status      int    `json:"service_status"` // assuming this follows Nagios conventions, 0=ok, 1=warning, 2=critical, 3=unknown
	TemplateID  int    `json:"service_template_id"`
	Type        string `json:"service_type"`
}

Service represents a service in LibreNMS.

type ServiceCreateRequest

type ServiceCreateRequest struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"desc,omitempty"`
	IP          string `json:"ip,omitempty"`
	Ignore      Bool   `json:"ignore,omitempty"`
	Param       string `json:"param,omitempty"`
	Type        string `json:"type"`
}

ServiceCreateRequest represents the request payload for creating a service.

type ServiceResponse

type ServiceResponse struct {
	BaseResponse
	Services []Service `json:"services"`
}

ServiceResponse is the response structure for services.

type ServiceUpdateRequest

type ServiceUpdateRequest struct {
	Name        *string
	Description *string
	IP          *string
	Ignore      *bool
	Param       *string
	Type        *string
}

ServiceUpdateRequest represents the request payload for updating a service.

Only set the field(s) you want to update. Trying to patch fields that have not changed will result in an HTTP 500 error.

func NewServiceUpdateRequest

func NewServiceUpdateRequest() *ServiceUpdateRequest

NewServiceUpdateRequest creates a new ServiceUpdateRequest instance.

func (*ServiceUpdateRequest) SetDescription

func (r *ServiceUpdateRequest) SetDescription(description string) *ServiceUpdateRequest

SetDescription sets the description of the service in the update request.

func (*ServiceUpdateRequest) SetIP

SetIP sets the IP address of the service in the update request.

func (*ServiceUpdateRequest) SetIgnore

func (r *ServiceUpdateRequest) SetIgnore(ignore bool) *ServiceUpdateRequest

SetIgnore sets the ignore status of the service in the update request.

func (*ServiceUpdateRequest) SetName

SetName sets the name of the service in the update request.

func (*ServiceUpdateRequest) SetParam

func (r *ServiceUpdateRequest) SetParam(param string) *ServiceUpdateRequest

SetParam sets the parameter of the service in the update request.

func (*ServiceUpdateRequest) SetType

func (r *ServiceUpdateRequest) SetType(serviceType string) *ServiceUpdateRequest

SetType sets the type of the service in the update request.

Jump to

Keyboard shortcuts

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