opnsense

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HealthCheckStatusOK = "OK"
	// OPNsense>25.1 has a different value
	// See https://github.com/AthennaMind/opnsense-exporter/issues/48#issuecomment-2692494735
	HealthCheckStatusOK_v25_1 = 2
)
View Source
const MaxRetries = 3

MaxRetries is the maximum number of retries when a request to the OPNsense API fails

Variables

This section is empty.

Functions

This section is empty.

Types

type APICallError

type APICallError struct {
	Endpoint   string
	Message    string
	StatusCode int
}

APICallError is an error returned by the OPNsense API

func (APICallError) Error

func (e APICallError) Error() string

type Arp

type Arp struct {
	Mac             string
	IP              string
	Type            string
	Hostname        string
	IntfDescription string
	Expired         bool
	Permanent       bool
	Expires         int
}

type ArpTable

type ArpTable struct {
	Arp          []Arp
	TotalEntries int
}

type Client

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

Client is an OPNsense API client

func NewClient

func NewClient(cfg options.OPNSenseConfig, userAgentVersion string, log *slog.Logger) (Client, error)

NewClient creates a new OPNsense API Client

func (*Client) Endpoints

func (c *Client) Endpoints() map[EndpointName]EndpointPath

Endpoints returns a map of all the endpoints that are called by the client.

func (*Client) FetchArpTable

func (c *Client) FetchArpTable() (ArpTable, *APICallError)

func (*Client) FetchCronTable

func (c *Client) FetchCronTable() (CronTable, *APICallError)

func (*Client) FetchFirmwareStatus added in v0.0.7

func (c *Client) FetchFirmwareStatus() (FirmwareStatus, *APICallError)

func (*Client) FetchGateways

func (c *Client) FetchGateways() (Gateways, *APICallError)

FetchGateways fetches the gateways status details from the OPNsense API and returns a safe wrapper Gateways struct.

func (*Client) FetchIPsecPhase1 added in v0.0.11

func (c *Client) FetchIPsecPhase1() (IPsecPhase1, *APICallError)

func (*Client) FetchIPsecPhase2 added in v0.0.12

func (c *Client) FetchIPsecPhase2(ikeId string) (ipsecPhase2SearchResponse, *APICallError)

func (*Client) FetchInterfaces

func (c *Client) FetchInterfaces() (Interfaces, *APICallError)

func (*Client) FetchOpenVPNInstances

func (c *Client) FetchOpenVPNInstances() (OpenVPNInstances, *APICallError)

func (*Client) FetchOpenVPNSessions added in v0.0.11

func (c *Client) FetchOpenVPNSessions() (OpenVPNSessions, *APICallError)

func (*Client) FetchPFStatsByInterface added in v0.0.6

func (c *Client) FetchPFStatsByInterface() (FirewallPFStats, *APICallError)

func (*Client) FetchProtocolStatistics

func (c *Client) FetchProtocolStatistics() (ProtocolStatistics, *APICallError)

func (*Client) FetchServices

func (c *Client) FetchServices() (Services, *APICallError)

func (*Client) FetchSystemInfo

func (c *Client) FetchSystemInfo() (SystemInfo, *APICallError)

func (*Client) FetchUnboundOverview

func (c *Client) FetchUnboundOverview() (UnboundDNSOverview, *APICallError)

func (*Client) FetchWireguardConfig added in v0.0.2

func (c *Client) FetchWireguardConfig() (WireguardClients, *APICallError)

func (*Client) HealthCheck added in v0.0.4

func (c *Client) HealthCheck() (HealthCheckResponse, error)

HealthCheck checks if the OPNsense is up and running.

type Cron

type Cron struct {
	UUID        string
	Schedule    string
	Description string
	Command     string
	Origin      string
	Status      CronStatus
}

type CronStatus

type CronStatus int
const (
	CronStatusDisabled CronStatus = iota
	CronStatusEnabled
)

type CronTable

type CronTable struct {
	Cron         []Cron
	TotalEntries int
}

type EndpointName

type EndpointName string

EndpointName is the custom type for name of an endpoint definition

type EndpointPath

type EndpointPath string

EndpointPath is the custom type for url path of an endpoint definition

type FirewallPFStat added in v0.0.6

type FirewallPFStat struct {
	InterfaceName string `json:"interface,omitempty"` // We will populate this field with the key of the map
	References    int    `json:"references"`

	In4PassPackets   int `json:"in4_pass_packets"`
	In4BlockPackets  int `json:"in4_block_packets"`
	Out4PassPackets  int `json:"out4_pass_packets"`
	Out4BlockPackets int `json:"out4_block_packets"`

	In6PassPackets   int `json:"in6_pass_packets"`
	In6BlockPackets  int `json:"in6_block_packets"`
	Out6PassPackets  int `json:"out6_pass_packets"`
	Out6BlockPackets int `json:"out6_block_packets"`
}

type FirewallPFStats added in v0.0.6

type FirewallPFStats struct {
	Interfaces []FirewallPFStat
}

type FirmwareStatus added in v0.0.7

type FirmwareStatus struct {
	LastCheck          string
	NeedsReboot        string
	NewPackages        int
	OsVersion          string
	ProductABI         string
	ProductId          string
	ProductVersion     string
	UpgradePackages    int
	UpgradeNeedsReboot string
}

func NewFirmwareStatus added in v0.0.12

func NewFirmwareStatus() FirmwareStatus

func (*FirmwareStatus) GetNeedsReboot added in v0.0.12

func (f *FirmwareStatus) GetNeedsReboot() bool

GetNeedsReboot converts NeedsReboot field to bool, handling empty strings and integers

func (*FirmwareStatus) GetUpgradeNeedsReboot added in v0.0.12

func (f *FirmwareStatus) GetUpgradeNeedsReboot() bool

GetUpgradeNeedsReboot converts UpgradeNeedsReboot field to bool, handling empty strings and integers

type Gateway

type Gateway struct {
	Name                 string
	Description          string
	Enabled              bool
	HardwareInterface    string
	IPProtocol           string
	Gateway              string
	DefaultGateway       bool
	FarGateway           string
	MonitorEnabled       bool
	MonitorNoRoute       bool
	Monitor              string
	ForceDown            bool
	Priority             string
	Weight               string
	LatencyLow           string
	LatencyHigh          string
	LossLow              string
	LossHigh             string
	Interval             string
	TimePeriod           string
	LossInterval         string
	DataLength           string
	UUID                 string
	Interface            string
	Attribute            int
	Dynamic              bool
	Virtual              bool
	Upstream             bool
	InterfaceDescription string
	Status               GatewayStatusType
	Delay                float64
	StdDev               float64
	Loss                 float64
	LabelClass           string
}

type GatewayStatusType added in v0.0.8

type GatewayStatusType int

GatewayStatus is the custom type that represents the status of a gateway

const (
	GatewayStatusOffline GatewayStatusType = iota
	GatewayStatusOnline
	GatewayStatusUnknown
	GatewayStatusPeding
)

type Gateways

type Gateways struct {
	Gateways []Gateway
}

type HealthCheckResponse added in v0.0.4

type HealthCheckResponse struct {
	System struct {
		Status string `json:"status"`
	} `json:"System"`
	CrashReporter struct {
		Message    string `json:"message"`
		Status     string `json:"status"`
		StatusCode int    `json:"statusCode"`
	} `json:"CrashReporter"`
	Firewall struct {
		Message    string `json:"message"`
		Status     string `json:"status"`
		StatusCode int    `json:"statusCode"`
	} `json:"Firewall"`
	// OPNsense>25.1 has a different structure
	// See https://github.com/AthennaMind/opnsense-exporter/issues/48#issuecomment-2692494735
	Metadata struct {
		System struct {
			Status interface{} `json:"status"`
		} `json:"System"`
		CrashReporter struct {
			Message    string `json:"message"`
			Status     string `json:"status"`
			StatusCode int    `json:"statusCode"`
		} `json:"CrashReporter"`
		Firewall struct {
			Message    string      `json:"message"`
			Status     interface{} `json:"status"`
			StatusCode int         `json:"statusCode"`
		} `json:"Firewall"`
	} `json:"metadata"`
}

func (*HealthCheckResponse) GetMetadataFirewallStatus added in v0.0.12

func (h *HealthCheckResponse) GetMetadataFirewallStatus() int

GetMetadataFirewallStatus converts the Status field to int, handling both string and int types

func (*HealthCheckResponse) GetMetadataSystemStatus added in v0.0.12

func (h *HealthCheckResponse) GetMetadataSystemStatus() int

GetMetadataSystemStatus converts the Status field to int, handling both string and int types

type IPsec added in v0.0.11

type IPsec struct {
	Phase1desc  string
	Connected   int
	IkeId       string
	Name        string
	InstallTime int
	BytesIn     int
	BytesOut    int
	PacketsIn   int
	PacketsOut  int
	Phase2      []ipsecPhase2
}

type IPsecPhase1 added in v0.0.11

type IPsecPhase1 struct {
	Rows []IPsec
}

type Interface

type Interface struct {
	Name                  string
	Device                string
	Type                  string
	MTU                   int
	PacketsReceived       int
	PacketsTransmitted    int
	BytesReceived         int
	BytesTransmitted      int
	MulticastsReceived    int
	MulticastsTransmitted int
	InputErrors           int
	OutputErrors          int
	Collisions            int
}

type InterfaceDetails

type InterfaceDetails struct {
	Device                    string `json:"device"`
	Driver                    string `json:"driver"`
	Index                     string `json:"index"`
	Flags                     string `json:"flags"`
	PromiscuousListeners      string `json:"promiscuous listeners"`
	SendQueueLength           string `json:"send queue length"`
	SendQueueMaxLength        string `json:"send queue max length"`
	SendQueueDrops            string `json:"send queue drops"`
	Type                      string `json:"type"`
	AddressLength             string `json:"address length"`
	HeaderLength              string `json:"header length"`
	LinkState                 string `json:"link state"`
	Vhid                      string `json:"vhid"`
	Datalen                   string `json:"datalen"`
	MTU                       string `json:"mtu"`
	Metric                    string `json:"metric"`
	LineRate                  string `json:"line rate"`
	PacketsReceived           string `json:"packets received"`
	PacketsTransmitted        string `json:"packets transmitted"`
	BytesReceived             string `json:"bytes received"`
	BytesTransmitted          string `json:"bytes transmitted"`
	OutputErrors              string `json:"output errors"`
	InputErrors               string `json:"input errors"`
	Collisions                string `json:"collisions"`
	MulticastsReceived        string `json:"multicasts received"`
	MulticastsTransmitted     string `json:"multicasts transmitted"`
	InputQueueDrops           string `json:"input queue drops"`
	PacketsForUnknownProtocol string `json:"packets for unknown protocol"`
	HWOffloadCapabilities     string `json:"HW offload capabilities"`
	UptimeAtAttachOrStatReset string `json:"uptime at attach or stat reset"`
	Name                      string `json:"name"`
}

type Interfaces

type Interfaces struct {
	Interfaces []Interface
}

type OpenVPN

type OpenVPN struct {
	UUID        string
	Description string
	Role        string
	DevType     string
	Enabled     int
}

type OpenVPNInstances

type OpenVPNInstances struct {
	Rows []OpenVPN
}

type OpenVPNSessions added in v0.0.11

type OpenVPNSessions struct {
	Rows []Sessions
}

type ProtocolStatistics

type ProtocolStatistics struct {
	TCPSentPackets            int
	TCPReceivedPackets        int
	ARPSentRequests           int
	ARPReceivedRequests       int
	TCPConnectionCountByState map[string]int
	ICMPCalls                 int
	ICMPSentPackets           int
	ICMPDroppedByReason       map[string]int
	UDPDeliveredPackets       int
	UDPOutputPackets          int
	UDPReceivedDatagrams      int
	UDPDroppedByReason        map[string]int
}

type Service

type Service struct {
	Description string
	Name        string
	Status      ServiceStatus
}

type ServiceStatus

type ServiceStatus int
const (
	ServiceStatusStopped ServiceStatus = iota
	ServiceStatusRunning
	ServiceStatusUnknown
)

type Services

type Services struct {
	Services     []Service
	TotalRunning int
	TotalStopped int
}

type Sessions added in v0.0.11

type Sessions struct {
	Description    string
	Username       string
	VirtualAddress string
	Status         int
}

type SystemInfo

type SystemInfo struct {
	Temperature []Temperature
}

type Temperature

type Temperature struct {
	Device                string
	DeviceSeq             string
	Type                  string
	TemperatureCelsuis    int
	TemperatureFahrenheit float32
}

type UnboundDNSOverview

type UnboundDNSOverview struct {
	AnswerRcodes      map[string]int
	QueryTypes        map[string]int
	Total             int
	BlocklistSize     int
	Passed            int
	AnswerRcodesTotal int
	AnnswerBogusTotal int
	AnswerSecureTotal int
	UptimeSeconds     float64
}

type WGInterfaceStatus added in v0.0.2

type WGInterfaceStatus int

WGInterfaceStatus is the custom type that represents the status of a Wireguard interface

const (
	WGInterfaceStatusDown WGInterfaceStatus = iota
	WGInterfaceStatusUp
	WGInterfaceStatusUnknown
)

type WGPeerStatus added in v0.0.12

type WGPeerStatus int

WGPeerStatus is the custom type that represents the peer status

const (
	WGPeerStatusDown WGPeerStatus = iota
	WGPeerStatusUp
	WGPeerStatusUnknown
)

type WireguardClients added in v0.0.2

type WireguardClients struct {
	Peers      []WireguardPeers
	Interfaces []WireguardInterfaces
}

type WireguardInterfaces added in v0.0.2

type WireguardInterfaces struct {
	Device     string
	DeviceType string
	Name       string
	DeviceName string
	Status     WGInterfaceStatus
}

type WireguardPeers added in v0.0.2

type WireguardPeers struct {
	Device          string
	DeviceName      string
	DeviceType      string
	Name            string
	LatestHandshake float64
	TransferRx      float64
	TransferTx      float64
	Status          WGPeerStatus
}

Jump to

Keyboard shortcuts

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