netdisco

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 14 Imported by: 4

README

go-netdisco

It's a client lib written in go for netdisco.

For now only searching device is supported as it was the only thing we wanted for now.

Usage

import with go get github.com/orange-cloudfoundry/go-netdisco

You can now use lib in this way:

package main

import (
	"fmt"
	"github.com/orange-cloudfoundry/go-netdisco"
)

func main() {
	client := netdisco.NewClient("https://netdisco2-demo.herokuapp.com", "guest", "guest", false)
	devices, err := client.SearchDevice(&netdisco.SearchDeviceQuery{
		Layers:   "7",
		Matchall: false,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(devices)
}

Important: For now user/password login produce an api key, a user can't have multiple on netdisco which can block usage with the same login on multiple clients which are not aware of the api key.

Until netdisco allow multiple api key you can:

  1. set api_token_lifetime: 1576800000 in netdisco configuration, this will set expiration time to 50 years for a token
  2. Produce an api key on https://my.netdisco.com/swagger-ui
  3. use in this lib netdisco.NewClientWithApiKey("https://netdisco2-demo.herokuapp.com", "api key", false) everywhere you need it

This is a weak solution as at any login or logout made on api, will make api key change.

Documentation

Index

Constants

View Source
const SeparatorByte byte = 255

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthTransport

type AuthTransport struct {
	ApiKey        string
	WrapTransport http.RoundTripper
}

func NewTransport

func NewTransport(apiKey string, insecureSkipVerify bool) *AuthTransport

func (AuthTransport) RoundTrip

func (t AuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Client

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

func NewClient

func NewClient(endpoint, username, password string, insecureSkipVerify bool) *Client

func NewClientWithApiKey added in v0.2.0

func NewClientWithApiKey(endpoint, apiKey string, insecureSkipVerify bool) *Client

func (*Client) Do

func (c *Client) Do(method, path string, query, value interface{}) error

func (*Client) DoWithRetry

func (c *Client) DoWithRetry(req *http.Request, value interface{}) error

func (*Client) Login

func (c *Client) Login() error

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, body io.Reader) (*http.Request, error)

func (*Client) ObjectDeviceByIP added in v0.2.0

func (c *Client) ObjectDeviceByIP(ip string) (DeviceDetails, error)

func (*Client) ReportsDeviceAddrNoDns added in v0.2.0

func (c *Client) ReportsDeviceAddrNoDns() ([]Device, error)

func (*Client) ReportsDeviceByLocation added in v0.2.0

func (c *Client) ReportsDeviceByLocation() ([]Device, error)

func (*Client) ReportsDeviceDnsMismatch added in v0.2.0

func (c *Client) ReportsDeviceDnsMismatch() ([]Device, error)

func (*Client) ReportsDevicePoeStatus added in v0.2.0

func (c *Client) ReportsDevicePoeStatus() ([]DevicePoeStatus, error)

func (*Client) ReportsDevicePortUtilization added in v0.2.0

func (c *Client) ReportsDevicePortUtilization(req *MarkAsFreeIfDownForRequest) ([]PortUtilization, error)

func (*Client) ReportsNodeMultiIps added in v0.2.0

func (c *Client) ReportsNodeMultiIps() ([]NodeIPCount, error)

func (*Client) ReportsPortAdminDown added in v0.2.0

func (c *Client) ReportsPortAdminDown() ([]PortAdminDown, error)

func (*Client) ReportsPortErrorDisabled added in v0.2.0

func (c *Client) ReportsPortErrorDisabled() ([]PortErrorDisabled, error)

func (*Client) ReportsPortHalfDuplex added in v0.2.0

func (c *Client) ReportsPortHalfDuplex() ([]PortHalfDuplex, error)

func (*Client) ReportsPortMultiNodes added in v0.2.0

func (c *Client) ReportsPortMultiNodes(filterByVlan int) ([]PortMultiNodes, error)

func (*Client) ReportsPortVlanMismatch added in v0.2.0

func (c *Client) ReportsPortVlanMismatch() ([]PortVlanMismatch, error)

func (*Client) SearchDevice

func (c *Client) SearchDevice(query *SearchDeviceQuery) ([]Device, error)

func (*Client) UnmarshalResponse

func (c *Client) UnmarshalResponse(resp *http.Response, value interface{}, validResponseCode ...int) error

type Device

type Device struct {
	Log               string        `json:"log"`
	Location          string        `json:"location"`
	LastMacsuckStamp  string        `json:"last_macsuck_stamp"`
	Ps2Type           string        `json:"ps2_type"`
	SnmpVer           int           `json:"snmp_ver"`
	LastArpnip        string        `json:"last_arpnip"`
	Creation          string        `json:"creation"`
	SnmpClass         string        `json:"snmp_class"`
	Ps1Type           string        `json:"ps1_type"`
	Contact           string        `json:"contact"`
	SnmpEngineid      string        `json:"snmp_engineid"`
	Model             string        `json:"model"`
	SinceFirstSeen    Float64String `json:"since_first_seen"`
	SnmpComm          string        `json:"snmp_comm"`
	Name              string        `json:"name"`
	Slots             int           `json:"slots"`
	IP                string        `json:"ip"`
	SinceLastMacsuck  Float64String `json:"since_last_macsuck"`
	Os                string        `json:"os"`
	LastDiscover      string        `json:"last_discover"`
	Layers            string        `json:"layers"`
	DNS               string        `json:"dns"`
	VtpDomain         string        `json:"vtp_domain"`
	UptimeAge         string        `json:"uptime_age"`
	Mac               string        `json:"mac"`
	LastDiscoverStamp string        `json:"last_discover_stamp"`
	Uptime            int64         `json:"uptime"`
	Description       string        `json:"description"`
	ChassisID         string        `json:"chassis_id"`
	FirstSeenStamp    string        `json:"first_seen_stamp"`
	Fan               string        `json:"fan"`
	Ps1Status         string        `json:"ps1_status"`
	LastArpnipStamp   string        `json:"last_arpnip_stamp"`
	Vendor            string        `json:"vendor"`
	LastMacsuck       string        `json:"last_macsuck"`
	Ps2Status         string        `json:"ps2_status"`
	SinceLastArpnip   Float64String `json:"since_last_arpnip"`
	SinceLastDiscover Float64String `json:"since_last_discover"`
	OsVer             string        `json:"os_ver"`
	NumPorts          int           `json:"num_ports"`
	Serial            string        `json:"serial"`
	IsPseudo          int           `json:"is_pseudo"`

	Alias string `json:"alias"`
}

type DeviceDetails added in v0.2.0

type DeviceDetails struct {
	Model        string `json:"model"`
	Fan          string `json:"fan"`
	Vendor       string `json:"vendor"`
	Layers       string `json:"layers"`
	Uptime       int64  `json:"uptime"`
	LastDiscover string `json:"last_discover"`
	Creation     string `json:"creation"`
	OsVer        string `json:"os_ver"`
	Log          string `json:"log"`
	Slots        int    `json:"slots"`
	Description  string `json:"description"`
	IP           string `json:"ip"`
	VtpDomain    string `json:"vtp_domain"`
	ChassisID    string `json:"chassis_id"`
	Ps2Type      string `json:"ps2_type"`
	LastMacsuck  string `json:"last_macsuck"`
	SnmpComm     string `json:"snmp_comm"`
	Ps1Status    string `json:"ps1_status"`
	SnmpEngineid string `json:"snmp_engineid"`
	IsPseudo     int    `json:"is_pseudo"`
	Os           string `json:"os"`
	SnmpVer      int    `json:"snmp_ver"`
	Name         string `json:"name"`
	Ps2Status    string `json:"ps2_status"`
	DNS          string `json:"dns"`
	Location     string `json:"location"`
	Serial       string `json:"serial"`
	Ps1Type      string `json:"ps1_type"`
	SnmpClass    string `json:"snmp_class"`
	Contact      string `json:"contact"`
	LastArpnip   string `json:"last_arpnip"`
	Mac          string `json:"mac"`
}

type DevicePoeStatus added in v0.2.0

type DevicePoeStatus struct {
	PoeDisabledPorts   int    `json:"poe_disabled_ports"`
	PoePowerCommitted  string `json:"poe_power_committed"`
	PoeCapablePorts    int    `json:"poe_capable_ports"`
	Name               string `json:"name"`
	Model              string `json:"model"`
	PoePoweredPorts    int    `json:"poe_powered_ports"`
	PoePowerDelivering string `json:"poe_power_delivering"`
	PoeErroredPorts    int    `json:"poe_errored_ports"`
	Location           string `json:"location"`
	DNS                string `json:"dns"`
	IP                 string `json:"ip"`
	Module             int    `json:"module"`
	Power              int    `json:"power"`
	Status             string `json:"status"`
}

type Float64String added in v0.2.2

type Float64String float64

func (Float64String) MarshalJSON added in v0.2.2

func (f Float64String) MarshalJSON() ([]byte, error)

func (*Float64String) UnmarshalJSON added in v0.2.2

func (f *Float64String) UnmarshalJSON(b []byte) error

type MarkAsFreeIfDownForRequest added in v0.2.0

type MarkAsFreeIfDownForRequest struct {
	AgeNum  int    `json:"age_num"`
	AgeUnit string `json:"age_unit"`
}

type NodeIPCount added in v0.2.0

type NodeIPCount struct {
	Name    string `json:"name"`
	Vendor  string `json:"vendor"`
	Mac     string `json:"mac"`
	IPCount int    `json:"ip_count"`
	DNS     string `json:"dns"`
	Port    string `json:"port"`
	Switch  string `json:"switch"`
}

type PortAdminDown added in v0.2.0

type PortAdminDown struct {
	IP          string `json:"ip"`
	DNS         string `json:"dns"`
	Port        string `json:"port"`
	Description string `json:"description"`
	Name        string `json:"name"`
	UpAdmin     string `json:"up_admin"`
}

type PortErrorDisabled added in v0.2.0

type PortErrorDisabled struct {
	DNS    string `json:"dns"`
	Name   string `json:"name"`
	Port   string `json:"port"`
	Reason string `json:"reason"`
	IP     string `json:"ip"`
}

type PortHalfDuplex added in v0.2.0

type PortHalfDuplex struct {
	IP     string `json:"ip"`
	Device Device `json:"device"`
	Duplex string `json:"duplex"`
	Port   string `json:"port"`
	Name   string `json:"name"`
}

type PortMultiNodes added in v0.2.0

type PortMultiNodes struct {
	MacCount    int    `json:"mac_count"`
	Description string `json:"description"`
	Name        string `json:"name"`
	IP          string `json:"ip"`
	DNS         string `json:"dns"`
	Port        string `json:"port"`
}

type PortUtilization added in v0.2.0

type PortUtilization struct {
	IP            string `json:"ip"`
	PortsInUse    int    `json:"ports_in_use"`
	PortsShutdown int    `json:"ports_shutdown"`
	PortCount     int    `json:"port_count"`
	PortsFree     int    `json:"ports_free"`
	DNS           string `json:"dns"`
}

type PortVlanMismatch added in v0.2.0

type PortVlanMismatch struct {
	RightDevice string `json:"right_device"`
	RightPort   string `json:"right_port"`
	LeftVlans   string `json:"left_vlans"`
	LeftPort    string `json:"left_port"`
	LeftDevice  string `json:"left_device"`
	RightVlans  string `json:"right_vlans"`
}

type SearchDeviceQuery

type SearchDeviceQuery struct {
	Q             string `json:"q" yaml:"q"`
	Name          string `json:"name" yaml:"name"`
	Location      string `json:"location" yaml:"location"`
	DNS           string `json:"dns" yaml:"dns"`
	Ip            string `json:"ip" yaml:"ip"`
	Description   string `json:"description" yaml:"description"`
	Mac           string `json:"mac" yaml:"mac"`
	Model         string `json:"model" yaml:"model"`
	OS            string `json:"os" yaml:"os"`
	OSVer         string `json:"os_ver" yaml:"os_ver"`
	Vendor        string `json:"vendor" yaml:"vendor"`
	Layers        string `json:"layers" yaml:"layers"`
	Matchall      bool   `json:"matchall" yaml:"matchall"`
	SeeAllColumns bool   `json:"seeallcolumns" yaml:"seeallcolumns"`
	// contains filtered or unexported fields
}

func (*SearchDeviceQuery) Id

func (q *SearchDeviceQuery) Id() uint64

func (*SearchDeviceQuery) Serialize

func (q *SearchDeviceQuery) Serialize() url.Values

Jump to

Keyboard shortcuts

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