omada

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

README

go-omada

golang library for the TP-Link Omada SDN. This is work in progress so is not complete.

This is currently being tested on controller version 5.7.6 on a hardware OC200 controller , and may not work correctly on other versions as TP-Link do not publish up to date API documentation with new releases.

Features:

  • login
  • get networks
  • get devices
  • get clients

Example usage

See example/main.go

Authentication

Authentication is handled via a username and password, which you can create in the controller admin section. Permissions are not very granular with only admin or reader roles available. Currently this package only needs reader.

The provided example shows how to provide credentials via environment variables if that is your thing.

Once logged in the sessions appear to be valid for 14 days and you will need your application to periodically re-login if the session expires by calling omada.Login().

HTTPS Vertification

HTTPS verification is enabled by default and recommended for good security. This can be disabled by setting the environment variable OMADA_DISABLE_HTTPS_VERIFICATION to true

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Name     string `json:"name"`
	HostName string `json:"hostName,omitempty"`
	Ip       string `json:"ip"`
	MAC      string `json:"mac"`
	DnsName  string
}

type Controller

type Controller struct {
	Sites map[string]string
	// contains filtered or unexported fields
}

func New

func New(baseURL string) Controller

func (*Controller) GetClients

func (c *Controller) GetClients() ([]Client, error)

func (*Controller) GetControllerInfo

func (c *Controller) GetControllerInfo() error

func (*Controller) GetDevices

func (c *Controller) GetDevices() ([]Device, error)

func (*Controller) GetDhcpReservations added in v0.4.1

func (c *Controller) GetDhcpReservations() ([]DhcpReservation, error)

func (*Controller) GetNetworks

func (c *Controller) GetNetworks() ([]OmadaNetwork, error)

func (*Controller) Login

func (c *Controller) Login(user string, pass string) error

func (*Controller) SetSite added in v0.4.0

func (c *Controller) SetSite(site string) error

type ControllerInfo

type ControllerInfo struct {
	ErrorCode int    `json:"errorCode"`
	Msg       string `json:"msg"`
	Result    struct {
		ControllerVer string `json:"controllerVer"`
		APIVer        string `json:"apiVer"`
		Configured    bool   `json:"configured"`
		Type          int    `json:"type"`
		SupportApp    bool   `json:"supportApp"`
		OmadacID      string `json:"omadacId"`
	} `json:"result"`
}

type Device

type Device struct {
	Type            string `json:"type"`
	Mac             string `json:"mac"`
	Name            string `json:"name"`
	Model           string `json:"model"`
	CompoundModel   string `json:"compoundModel"`
	ShowModel       string `json:"showModel"`
	ModelVersion    string `json:"modelVersion"`
	FirmwareVersion string `json:"firmwareVersion"`
	Version         string `json:"version"`
	HwVersion       string `json:"hwVersion"`
	IP              string `json:"ip"`
	Uptime          string `json:"uptime"`
	UptimeLong      int    `json:"uptimeLong"`
	StatusCategory  int    `json:"statusCategory"`
	Status          int    `json:"status"`
	AdoptFailType   int    `json:"adoptFailType"`
	LastSeen        int64  `json:"lastSeen"`
	NeedUpgrade     bool   `json:"needUpgrade"`
	FwDownload      bool   `json:"fwDownload"`
	CPUUtil         int    `json:"cpuUtil"`
	MemUtil         int    `json:"memUtil"`
	Download        int64  `json:"download"`
	Upload          int64  `json:"upload"`
	Site            string `json:"site"`
	Location        struct {
		MapID       string  `json:"mapId"`
		PosX        float64 `json:"posX"`
		PosY        float64 `json:"posY"`
		InstallType int     `json:"installType"`
		Height      float64 `json:"height"`
		Located     bool    `json:"located"`
	} `json:"location,omitempty"`
	ClientNum       int    `json:"clientNum"`
	Compatible      int    `json:"compatible"`
	LocateEnable    bool   `json:"locateEnable"`
	Sn              string `json:"sn"`
	CombinedGateway bool   `json:"combinedGateway"`
	WirelessLinked  bool   `json:"wirelessLinked,omitempty"`
	DeviceMisc      struct {
		Support5G           bool `json:"support5g"`
		Support5G2          bool `json:"support5g2"`
		Support6G           bool `json:"support6g"`
		Support11Ac         bool `json:"support11ac"`
		SupportLag          bool `json:"supportLag"`
		SupportMesh         int  `json:"supportMesh"`
		CustomizeRegion     int  `json:"customizeRegion"`
		MinPower2G          int  `json:"minPower2G"`
		MaxPower2G          int  `json:"maxPower2G"`
		MinPower5G          int  `json:"minPower5G"`
		MaxPower5G          int  `json:"maxPower5G"`
		SupportChannelLimit bool `json:"supportChannelLimit"`
		SupportDfs          int  `json:"supportDfs"`
		SupportRoaming      int  `json:"supportRoaming"`
	} `json:"deviceMisc,omitempty"`
	DevCap struct {
		SupportPa           int  `json:"supportPa"`
		MeshChainNum        int  `json:"meshChainNum"`
		SupportOFDMA2G      bool `json:"supportOFDMA2g"`
		SupportOFDMA5G      bool `json:"supportOFDMA5g"`
		SupportOFDMA5G2     bool `json:"supportOFDMA5g2"`
		SupportOFDMA6G      bool `json:"supportOFDMA6g"`
		SupportMeshPriority bool `json:"supportMeshPriority"`
		SupportL3Access     bool `json:"supportL3Access"`
	} `json:"devCap,omitempty"`
	WlanGroup      string   `json:"wlanGroup,omitempty"`
	Override       string   `json:"override,omitempty"`
	Bssids         []string `json:"bssids,omitempty"`
	RadioSetting2G struct {
		RadioEnable  bool   `json:"radioEnable"`
		ChannelWidth string `json:"channelWidth"`
		Channel      string `json:"channel"`
		TxPower      int    `json:"txPower"`
		TxPowerLevel int    `json:"txPowerLevel"`
	} `json:"radioSetting2g,omitempty"`
	RadioSetting5G struct {
		RadioEnable  bool   `json:"radioEnable"`
		ChannelWidth string `json:"channelWidth"`
		Channel      string `json:"channel"`
		TxPower      int    `json:"txPower"`
		TxPowerLevel int    `json:"txPowerLevel"`
	} `json:"radioSetting5g,omitempty"`
	Wp2G struct {
		ActualChannel string `json:"actualChannel"`
		MaxTxRate     int    `json:"maxTxRate"`
		TxPower       int    `json:"txPower"`
		Region        int    `json:"region"`
		BandWidth     string `json:"bandWidth"`
		RdMode        string `json:"rdMode"`
		TxUtil        int    `json:"txUtil"`
		RxUtil        int    `json:"rxUtil"`
		InterUtil     int    `json:"interUtil"`
	} `json:"wp2g,omitempty"`
	Wp5G struct {
		ActualChannel string `json:"actualChannel"`
		MaxTxRate     int    `json:"maxTxRate"`
		TxPower       int    `json:"txPower"`
		Region        int    `json:"region"`
		BandWidth     string `json:"bandWidth"`
		RdMode        string `json:"rdMode"`
		TxUtil        int    `json:"txUtil"`
		RxUtil        int    `json:"rxUtil"`
		InterUtil     int    `json:"interUtil"`
	} `json:"wp5g,omitempty"`
	TxRate           int     `json:"txRate,omitempty"`
	RxRate           int     `json:"rxRate,omitempty"`
	ClientNum2G      int     `json:"clientNum2g,omitempty"`
	ClientNum5G      int     `json:"clientNum5g,omitempty"`
	ClientNum5G2     int     `json:"clientNum5g2,omitempty"`
	ClientNum6G      int     `json:"clientNum6g,omitempty"`
	UserNum          int     `json:"userNum,omitempty"`
	GuestNum         int     `json:"guestNum,omitempty"`
	Hop              int     `json:"hop,omitempty"`
	Downlink         int     `json:"downlink,omitempty"`
	AnyPoeEnable     bool    `json:"anyPoeEnable,omitempty"`
	LicenseStatusStr string  `json:"licenseStatusStr"`
	Uplink           string  `json:"uplink,omitempty"`
	LoopbackNum      int     `json:"loopbackNum,omitempty"`
	Loop             string  `json:"loop,omitempty"`
	PoeRemain        float64 `json:"poeRemain,omitempty"`
	FanStatus        int     `json:"fanStatus,omitempty"`
	PoeSupport       bool    `json:"poeSupport,omitempty"`
	DnsName          string
}

type DhcpReservation added in v0.4.1

type DhcpReservation struct {
	ID                   string `json:"id"`
	Description          string `json:"description,omitempty"`
	NetID                string `json:"netId"`
	Mac                  string `json:"mac"`
	IP                   string `json:"ip"`
	Status               bool   `json:"status"`
	NetName              string `json:"netName"`
	ExportToIPMacBinding bool   `json:"exportToIpMacBinding"`
	ClientName           string `json:"clientName"`
}

type GetNetworksResponse

type GetNetworksResponse struct {
	ErrorCode int    `json:"errorCode"`
	Msg       string `json:"msg"`
	Result    struct {
		TotalRows   int            `json:"totalRows"`
		CurrentPage int            `json:"currentPage"`
		CurrentSize int            `json:"currentSize"`
		Data        []OmadaNetwork `json:"data"`
	} `json:"result"`
}

type LoginBody

type LoginBody struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type LoginResponse

type LoginResponse struct {
	ErrorCode int    `json:"errorCode"`
	Msg       string `json:"msg"`
	Result    struct {
		RoleType int    `json:"roleType"`
		Token    string `json:"token"`
	} `json:"result"`
}

type OmadaNetwork

type OmadaNetwork struct {
	Id      string `json:"id"`
	Name    string `json:"name,omitempty"`
	Domain  string `json:"domain,omitempty"`
	Purpose string `json:"purpose"`
	Subnet  string `json:"gatewaySubnet"`
}

type Sites added in v0.2.0

type Sites struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

Jump to

Keyboard shortcuts

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