Documentation
¶
Index ¶
- func NewContextWithDeviceConnection(ctx context.Context, con *RequestDeviceConnection) context.Context
- func NewContextWithSNMPGetsInsteadOfWalk(ctx context.Context, b bool) context.Context
- func SNMPGetsInsteadOfWalkFromContext(ctx context.Context) (bool, bool)
- func URLEscapePath(unescaped string) string
- func ValidateSNMPv3AuthProtocol(protocol string) error
- func ValidateSNMPv3PrivProtocol(protocol string) error
- type CommonOIDs
- type ConnectionData
- type HTTPClient
- func (h *HTTPClient) GetHostname() string
- func (h *HTTPClient) GetProtocolString() string
- func (h *HTTPClient) HasSuccessfulCachedRequest() bool
- func (h *HTTPClient) InsecureSSLCert(b bool)
- func (h *HTTPClient) Request(ctx context.Context, method, path, body string, ...) (*resty.Response, error)
- func (h *HTTPClient) SetFormat(format string) error
- func (h *HTTPClient) SetPort(port int)
- func (h *HTTPClient) SetTimeout(timeout time.Duration)
- func (h *HTTPClient) SetUsernameAndPassword(username, password string) error
- func (h *HTTPClient) UseCache(b bool)
- func (h *HTTPClient) UseDefaultPort()
- func (h *HTTPClient) UseHTTPS(useHTTPS bool)
- type HTTPConnectionData
- type OID
- type RequestDeviceConnection
- type RequestDeviceConnectionHTTP
- type RequestDeviceConnectionSNMP
- type SNMPClient
- func NewSNMPClient(ctx context.Context, ipAddress, snmpVersion, community string, ...) (SNMPClient, error)
- func NewSNMPClientByConnectionData(ctx context.Context, ipAddress string, data *SNMPConnectionData) (SNMPClient, error)
- func NewSNMPv3Client(ctx context.Context, ipAddress string, port, timeout, retries int, ...) (SNMPClient, error)
- type SNMPConnectionData
- type SNMPCredentials
- type SNMPGetConfiguration
- type SNMPResponse
- func (s *SNMPResponse) GetOID() OID
- func (s *SNMPResponse) GetSNMPType() gosnmp.Asn1BER
- func (s *SNMPResponse) GetValue() (value.Value, error)
- func (s *SNMPResponse) GetValueBySNMPGetConfiguration(snmpGetConfig SNMPGetConfiguration) (value.Value, error)
- func (s *SNMPResponse) GetValueRaw() (value.Value, error)
- func (s *SNMPResponse) WasSuccessful() bool
- type SNMPv3ConnectionData
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 NewContextWithSNMPGetsInsteadOfWalk ¶
NewContextWithSNMPGetsInsteadOfWalk returns a new context with the request
func SNMPGetsInsteadOfWalkFromContext ¶
SNMPGetsInsteadOfWalkFromContext gets the request from the context
func URLEscapePath ¶
URLEscapePath url-escapes a file path.
Types ¶
type CommonOIDs ¶
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) HasSuccessfulCachedRequest ¶
func (h *HTTPClient) HasSuccessfulCachedRequest() bool
HasSuccessfulCachedRequest returns if there was at least one successful cached request.
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) 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.
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) GetIndexAfterOID ¶
GetIndexAfterOID returns the index of the OID based on the baseOID.
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 interface {
Disconnect() error
SNMPGet(ctx context.Context, oid ...OID) ([]SNMPResponse, error)
SNMPWalk(ctx context.Context, oid OID) ([]SNMPResponse, error)
UseCache(b bool)
HasSuccessfulCachedRequest() bool
GetCommunity() string
SetCommunity(community string)
GetPort() int
GetVersion() string
GetMaxRepetitions() uint32
SetMaxRepetitions(maxRepetitions uint32)
SetMaxOIDs(maxOIDs int) error
GetV3Level() *string
GetV3ContextName() *string
GetV3User() *string
GetV3AuthKey() *string
GetV3AuthProto() *string
GetV3PrivKey() *string
GetV3PrivProto() *string
}
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 NewSNMPv3Client ¶
func NewSNMPv3Client(ctx context.Context, ipAddress string, port, timeout, retries int, v3Data SNMPv3ConnectionData) (SNMPClient, error)
NewSNMPv3Client creates a new SNMP v3 Client.
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 Max Repetitions of the SNMP connection. Overrides the device class settings if set.
//
// example: 20
MaxRepetitions *uint32 `json:"maxRepetitions" xml:"maxRepetitions" yaml:"maxRepetitions"`
// 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"`
// The data required for an SNMP v3 connection.
V3Data SNMPv3ConnectionData `json:"v3_data" xml:"v3_data" yaml:"v3_data"`
}
SNMPConnectionData
SNMPConnectionData includes all SNMP connection information 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"`
V3Level string `yaml:"v3Level" json:"v3Level" xml:"v3Level"`
V3ContextName string `yaml:"v3ContextName" json:"v3ContextName" xml:"v3ContextName"`
}
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 represents the configuration needed to get a value.
type SNMPResponse ¶
type SNMPResponse struct {
// contains filtered or unexported fields
}
SNMPResponse is the response returned for a single snmp request.
func NewSNMPResponse ¶
func NewSNMPResponse(oid OID, snmpType gosnmp.Asn1BER, value interface{}) SNMPResponse
NewSNMPResponse creates a new SNMP Response
func (*SNMPResponse) GetOID ¶
func (s *SNMPResponse) GetOID() OID
GetOID returns the oid of the response.
func (*SNMPResponse) GetSNMPType ¶
func (s *SNMPResponse) GetSNMPType() gosnmp.Asn1BER
GetSNMPType returns the snmp type of the response.
func (*SNMPResponse) GetValue ¶
func (s *SNMPResponse) GetValue() (value.Value, error)
GetValue returns the value of the snmp response.
func (*SNMPResponse) GetValueBySNMPGetConfiguration ¶
func (s *SNMPResponse) GetValueBySNMPGetConfiguration(snmpGetConfig SNMPGetConfiguration) (value.Value, error)
GetValueBySNMPGetConfiguration returns the value of the snmp response according to the snmpgetConfig
func (*SNMPResponse) GetValueRaw ¶
func (s *SNMPResponse) GetValueRaw() (value.Value, error)
GetValueRaw 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.
type SNMPv3ConnectionData ¶
type SNMPv3ConnectionData struct {
// The security level of the SNMP connection.
//
// example: authPriv
Level *string `json:"level" xml:"level" yaml:"level"`
// The context name of the SNMP connection.
//
// example: bridge1
ContextName *string `json:"context_name" xml:"context_name" yaml:"context_name"`
// The user of the SNMP connection.
//
// example: user
User *string `json:"user" xml:"user" yaml:"user"`
// The authentication protocol passphrase of the SNMP connection.
//
// example: passphrase
AuthKey *string `json:"auth_key" xml:"auth_key" yaml:"auth_key"`
// The authentication protocol of the SNMP connection.
//
// example: MD5
AuthProtocol *string `json:"auth_protocol" xml:"auth_protocol" yaml:"auth_protocol"`
// The privacy protocol passphrase of the SNMP connection.
//
// example: passphrase
PrivKey *string `json:"priv_key" xml:"priv_key" yaml:"priv_key"`
// The privacy protocol of the SNMP connection.
//
// example: DES
PrivProtocol *string `json:"priv_protocol" xml:"priv_protocol" yaml:"priv_protocol"`
}
SNMPv3ConnectionData
SNMPv3ConnectionData includes all SNMP v3 specific connection data.
swagger:model