network

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContextWithDeviceConnection

func NewContextWithDeviceConnection(ctx context.Context, con *RequestDeviceConnection) context.Context

NewContextWithDeviceConnection returns a new context with the device connection

func URLEscapePath

func URLEscapePath(unescaped string) string

URLEscapePath url-escapes a file path.

Types

type CommonOIDs

type CommonOIDs struct {
	SysObjectID    *string
	SysDescription *string
}

CommonOIDs represents the common oids

type ConnectionData

type ConnectionData struct {
	// Data of the snmp connection to the device
	SNMP *SNMPConnectionData `json:"snmp" xml:"snmp" yaml:"snmp"`
	// Data of the http connection to the device
	HTTP *HTTPConnectionData `json:"http" xml:"http" yaml:"http"`
}

ConnectionData

ConnectionData includes all connection data for a device

swagger:model

type HTTPClient

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

HTTPClient is used for communication over HTTP(s).

func NewHTTPClient

func NewHTTPClient(URI string) (*HTTPClient, error)

NewHTTPClient returns a new HTTP client.

func (*HTTPClient) GetHostname

func (h *HTTPClient) GetHostname() string

GetHostname returns the hostname.

func (*HTTPClient) GetProtocolString

func (h *HTTPClient) GetProtocolString() string

GetProtocolString returns the protocol as a string.

func (*HTTPClient) GetSuccessfulCachedRequests

func (h *HTTPClient) GetSuccessfulCachedRequests() map[string]cachedRequestResult

GetSuccessfulCachedRequests returns all successful cached requests.

func (*HTTPClient) InsecureSSLCert

func (h *HTTPClient) InsecureSSLCert(b bool)

InsecureSSLCert defines weather insecure ssl certificates are allowed.

func (*HTTPClient) Request

func (h *HTTPClient) Request(ctx context.Context, method, path, body string, header, queryParams map[string]string) (*resty.Response, error)

Request sends an http request.

func (*HTTPClient) SetFormat

func (h *HTTPClient) SetFormat(format string) error

SetFormat sets the format header which is used in requests.

func (*HTTPClient) SetPort

func (h *HTTPClient) SetPort(port int)

SetPort sets HTTP(S) port

func (*HTTPClient) SetTimeout

func (h *HTTPClient) SetTimeout(timeout time.Duration)

SetTimeout sets a timeout for the http client.

func (*HTTPClient) SetUsernameAndPassword

func (h *HTTPClient) SetUsernameAndPassword(username, password string) error

SetUsernameAndPassword sets username and password for an http client.

func (*HTTPClient) UseCache

func (h *HTTPClient) UseCache(b bool)

UseCache configures whether the http cache should be used or not.

func (*HTTPClient) UseDefaultPort

func (h *HTTPClient) UseDefaultPort()

UseDefaultPort sets HTTP(S) port to its default port.

func (*HTTPClient) UseHTTPS

func (h *HTTPClient) UseHTTPS(useHTTPS bool)

UseHTTPS turns on HTTPS.

type HTTPConnectionData

type HTTPConnectionData struct {
	// The http port(s) of the device
	//
	// example: 80
	HTTPPorts []int `json:"http_ports" xml:"http_ports" yaml:"http_ports"`
	// The https port(s) of the device
	//
	// example: 443
	HTTPSPorts []int `json:"https_ports" xml:"https_ports" yaml:"https_ports"`
	// The username for authorization on the device
	//
	// example: username
	AuthUsername *string `json:"auth_username" xml:"auth_username" yaml:"auth_username"`
	// The password for authorization on the device
	//
	// example: password
	AuthPassword *string `json:"auth_password" xml:"auth_password" yaml:"auth_password"`
}

HTTPConnectionData

HTTPConnectionData includes all http connection data for a device

swagger:model

type OID

type OID string

OID represents an SNMP oid.

func (*OID) Validate

func (o *OID) Validate() error

Validate checks if the oid is syntactically correct

type RequestDeviceConnection

type RequestDeviceConnection struct {
	RawConnectionData ConnectionData
	HTTP              *RequestDeviceConnectionHTTP
	SNMP              *RequestDeviceConnectionSNMP
}

RequestDeviceConnection represents the request device connection

func DeviceConnectionFromContext

func DeviceConnectionFromContext(ctx context.Context) (*RequestDeviceConnection, bool)

DeviceConnectionFromContext gets the device connection from the context

func (*RequestDeviceConnection) CloseConnections

func (r *RequestDeviceConnection) CloseConnections()

CloseConnections closes the connection to the device

func (*RequestDeviceConnection) GetIdealConnectionData

func (r *RequestDeviceConnection) GetIdealConnectionData() ConnectionData

GetIdealConnectionData returns the ideal connection data.

type RequestDeviceConnectionHTTP

type RequestDeviceConnectionHTTP struct {
	HTTPClient     *HTTPClient
	ConnectionData *HTTPConnectionData
}

RequestDeviceConnectionHTTP represents the http request device connection

type RequestDeviceConnectionSNMP

type RequestDeviceConnectionSNMP struct {
	SnmpClient *SNMPClient
	CommonOIDs CommonOIDs
}

RequestDeviceConnectionSNMP represents the snmp request device connection

func (*RequestDeviceConnectionSNMP) GetSysDescription

func (r *RequestDeviceConnectionSNMP) GetSysDescription(ctx context.Context) (string, error)

GetSysDescription returns the sysDescription.

func (*RequestDeviceConnectionSNMP) GetSysObjectID

func (r *RequestDeviceConnectionSNMP) GetSysObjectID(ctx context.Context) (string, error)

GetSysObjectID returns the sysObjectID.

type SNMPClient

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

SNMPClient is used to communicate via snmp.

func NewSNMPClient

func NewSNMPClient(ctx context.Context, ipAddress, snmpVersion, community string, port, timeout, retries int) (*SNMPClient, error)

NewSNMPClient creates a new SNMP Client

func NewSNMPClientByConnectionData

func NewSNMPClientByConnectionData(ctx context.Context, ipAddress string, data *SNMPConnectionData) (*SNMPClient, error)

NewSNMPClientByConnectionData tries to create a new snmp client by SNMPConnectionData and returns it.

func (*SNMPClient) Disconnect

func (s *SNMPClient) Disconnect() error

Disconnect closes an snmp connection.

func (*SNMPClient) GetCommunity

func (s *SNMPClient) GetCommunity() string

GetCommunity returns the community string

func (*SNMPClient) GetMaxRepetitions

func (s *SNMPClient) GetMaxRepetitions() uint8

GetMaxRepetitions returns the max repetitions.

func (*SNMPClient) GetPort

func (s *SNMPClient) GetPort() int

GetPort returns the port

func (*SNMPClient) GetSuccessfulCachedRequests

func (s *SNMPClient) GetSuccessfulCachedRequests() map[string]cachedRequestResult

GetSuccessfulCachedRequests returns all successful cached requests.

func (*SNMPClient) GetVersion

func (s *SNMPClient) GetVersion() string

GetVersion returns the snmp version.

func (*SNMPClient) SNMPGet

func (s *SNMPClient) SNMPGet(ctx context.Context, oid ...string) ([]SNMPResponse, error)

SNMPGet sends one or more simple snmpget requests to the target host and returns the result.

func (*SNMPClient) SNMPWalk

func (s *SNMPClient) SNMPWalk(ctx context.Context, oid string) ([]SNMPResponse, error)

SNMPWalk sends a snmpwalk request to the specified oid.

func (*SNMPClient) SetCommunity added in v0.2.1

func (s *SNMPClient) SetCommunity(community string)

SetCommunity updates the community string. This function is not thread safe!

func (*SNMPClient) SetMaxRepetitions

func (s *SNMPClient) SetMaxRepetitions(maxRepetitions uint32)

SetMaxRepetitions sets the maximum repetitions.

func (*SNMPClient) UseCache

func (s *SNMPClient) UseCache(b bool)

UseCache configures whether the snmp cache should be used or not

type SNMPConnectionData

type SNMPConnectionData struct {
	// The snmp community string(s) for the device
	//
	// example: public
	Communities []string `json:"communities" xml:"communities" yaml:"communities"`
	// The snmp version(s) of the device
	//
	// example: 2c
	Versions []string `json:"versions" xml:"versions" yaml:"versions"`
	// The snmp port(s) of the device
	//
	// example: 161
	Ports []int `json:"ports" xml:"ports" yaml:"ports"`
	// The amount of parallel connection requests used while trying to get a valid SNMP connection
	//
	// example: 5
	DiscoverParallelRequests *int `json:"discoverParallelRequests" xml:"discoverParallelRequests" yaml:"discoverParallelRequests"`
	// The timeout in seconds used while trying to get a valid SNMP connection
	//
	// example: 2
	DiscoverTimeout *int `json:"discoverTimeout" xml:"discoverTimeout" yaml:"discoverTimeout"`
	// The retries used while trying to get a valid SNMP connection
	//
	// example: 0
	DiscoverRetries *int `json:"discoverRetries" xml:"discoverRetries" yaml:"discoverRetries"`
}

SNMPConnectionData

SNMPConnectionData includes all snmp connection data for a device

swagger:model

type SNMPCredentials

type SNMPCredentials struct {
	Version   string `yaml:"version" json:"version" xml:"version"`
	Community string `yaml:"community" json:"community" xml:"community"`
	Port      int    `yaml:"port" json:"port" xml:"port"`
}

SNMPCredentials includes all credential information of the snmp connection.

type SNMPGetConfiguration

type SNMPGetConfiguration struct {
	OID          OID  `yaml:"oid" mapstructure:"oid"`
	UseRawResult bool `yaml:"use_raw_result" mapstructure:"use_raw_result"`
}

SNMPGetConfiguration

type SNMPResponse

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

SNMPResponse is the response returned for a single snmp request.

func (*SNMPResponse) GetOID

func (s *SNMPResponse) GetOID() string

GetOID returns the oid of the response

func (*SNMPResponse) GetSNMPType

func (s *SNMPResponse) GetSNMPType() gosnmp.Asn1BER

GetOID returns the snmp type of the response

func (*SNMPResponse) GetValue

func (s *SNMPResponse) GetValue() (interface{}, error)

GetValue returns the value of the snmp response.

func (*SNMPResponse) GetValueBySNMPGetConfiguration

func (s *SNMPResponse) GetValueBySNMPGetConfiguration(snmpgetConfig SNMPGetConfiguration) (string, error)

GetValueBySNMPGetConfiguration returns the value of the snmp response according to the snmpgetConfig

func (*SNMPResponse) GetValueString

func (s *SNMPResponse) GetValueString() (string, error)

GetValueString returns the value string of the snmp response.

func (*SNMPResponse) GetValueStringRaw

func (s *SNMPResponse) GetValueStringRaw() (string, error)

GetValueStringRaw returns the raw value string of the snmp response.

func (*SNMPResponse) WasSuccessful

func (s *SNMPResponse) WasSuccessful() bool

WasSuccessful returns if the snmp request was successful.

Jump to

Keyboard shortcuts

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