dtclient

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OsLinux        = "LINUX"
	StatusOutdated = "OUTDATED"
)
View Source
const (
	Slash                 = "/"
	DtCommunicationSuffix = "communication"
)
View Source
const (
	InstallerTypeDefault = "default"
)

Known installer types.

View Source
const (
	OsUnix = "unix"
)

Known OS values.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveGate

type ActiveGate struct {
	NetworkAddresses []string
	AutoUpdateStatus string
	OfflineSince     int64
	Version          string
	Hostname         string
	NetworkZone      string
}

type ActiveGateQuery

type ActiveGateQuery struct {
	Hostname       string
	NetworkAddress string
	NetworkZone    string
	UpdateStatus   string
}

type Client

type Client interface {
	// GetLatestAgentVersion gets the latest agent version for the given OS and installer type.
	// Returns the version as received from the server on success.
	//
	// Returns an error for the following conditions:
	//  - os or installerType is empty
	//  - IO error or unexpected response
	//  - error response from the server (e.g. authentication failure)
	//  - the agent version is not set or empty
	GetLatestAgentVersion(os, installerType string) (string, error)

	// GetAgentVersionForIP returns the agent version running on the host with the given IP address.
	// Returns the version string formatted as "Major.Minor.Revision.Timestamp" on success.
	//
	// Returns an error for the following conditions:
	//  - the IP is empty
	//  - IO error or unexpected response
	//  - error response from the server (e.g. authentication failure)
	//  - a host with the given IP cannot be found
	//  - the agent version for the host is not set
	//
	// The list of all hosts with their IP addresses is cached the first time this method is called. Use a new
	// client instance to fetch a new list from the server.
	GetAgentVersionForIP(ip string) (string, error)

	// GetCommunicationHosts returns, on success, the list of communication hosts used for available
	// communication endpoints that the Dynatrace OneAgent can use to connect to.
	//
	// Returns an error if there was also an error response from the server.
	GetConnectionInfo() (ConnectionInfo, error)

	// GetCommunicationHostForClient returns a CommunicationHost for the client's API URL. Or error, if failed to be parsed.
	GetCommunicationHostForClient() (CommunicationHost, error)

	// SendEvent posts events to dynatrace API
	SendEvent(eventData *EventData) error

	// GetEntityIDForIP returns the entity id for a given IP address.
	//
	// Returns an error in case the lookup failed.
	GetEntityIDForIP(ip string) (string, error)

	// GetClusterInfo returns the following information about the cluster:
	// * Version
	GetClusterInfo() (*ClusterInfo, error)

	// GetTokenScopes returns the list of scopes assigned to a token if successful.
	GetTokenScopes(token string) (TokenScopes, error)

	// GetTenantInfo returns TenantInfo that holds UUID, Tenant Token and Endpoints
	GetTenantInfo() (*TenantInfo, error)

	QueryOutdatedActiveGates(query *ActiveGateQuery) ([]ActiveGate, error)

	QueryActiveGates(query *ActiveGateQuery) ([]ActiveGate, error)

	AddToDashboard(label string, kubernetesApiEndpoint string, bearerToken string) (string, error)
}

Client is the interface for the Dynatrace REST API client.

func NewClient

func NewClient(url, apiToken, paasToken string, opts ...Option) (Client, error)

NewClient creates a REST client for the given API base URL and authentication tokens. Returns an error if a token or the URL is empty.

The API base URL is different for managed and SaaS environments:

  • SaaS: https://{environment-id}.live.dynatrace.com/api
  • Managed: https://{domain}/e/{environment-id}/api

opts can be used to customize the created client, entries must not be nil.

type ClusterInfo

type ClusterInfo struct {
	Version string `json:"version"`
}

type CommunicationHost

type CommunicationHost struct {
	Protocol string
	Host     string
	Port     uint32
}

CommunicationHost => struct of connection endpoint

type ConnectionInfo

type ConnectionInfo struct {
	CommunicationHosts []CommunicationHost
	TenantUUID         string
}

ConnectionInfo => struct of TenantUUID and CommunicationHosts

type EventData

type EventData struct {
	EventType     string               `json:"eventType"`
	StartInMillis uint64               `json:"start"`
	EndInMillis   uint64               `json:"end"`
	Description   string               `json:"description"`
	AttachRules   EventDataAttachRules `json:"attachRules"`
	Source        string               `json:"source"`
}

EventData struct which defines what event payload should contain

type EventDataAttachRules

type EventDataAttachRules struct {
	EntityIDs []string `json:"entityIds"`
}

type MockDynatraceClient

type MockDynatraceClient struct {
	mock.Mock
}

MockDynatraceClient implements a Dynatrace REST API Client mock

func (*MockDynatraceClient) AddToDashboard

func (o *MockDynatraceClient) AddToDashboard(label string, kubernetesApiEndpoint string, bearerToken string) (string, error)

func (*MockDynatraceClient) GetAgentVersionForIP

func (o *MockDynatraceClient) GetAgentVersionForIP(ip string) (string, error)

func (*MockDynatraceClient) GetClusterInfo

func (o *MockDynatraceClient) GetClusterInfo() (*ClusterInfo, error)

func (*MockDynatraceClient) GetCommunicationHostForClient

func (o *MockDynatraceClient) GetCommunicationHostForClient() (CommunicationHost, error)

func (*MockDynatraceClient) GetConnectionInfo

func (o *MockDynatraceClient) GetConnectionInfo() (ConnectionInfo, error)

func (*MockDynatraceClient) GetEntityIDForIP

func (o *MockDynatraceClient) GetEntityIDForIP(ip string) (string, error)

func (*MockDynatraceClient) GetLatestAgentVersion

func (o *MockDynatraceClient) GetLatestAgentVersion(os, installerType string) (string, error)

func (*MockDynatraceClient) GetTenantInfo

func (o *MockDynatraceClient) GetTenantInfo() (*TenantInfo, error)

func (*MockDynatraceClient) GetTokenScopes

func (o *MockDynatraceClient) GetTokenScopes(token string) (TokenScopes, error)

func (*MockDynatraceClient) QueryActiveGates

func (o *MockDynatraceClient) QueryActiveGates(query *ActiveGateQuery) ([]ActiveGate, error)

func (*MockDynatraceClient) QueryOutdatedActiveGates

func (o *MockDynatraceClient) QueryOutdatedActiveGates(query *ActiveGateQuery) ([]ActiveGate, error)

func (*MockDynatraceClient) SendEvent

func (o *MockDynatraceClient) SendEvent(event *EventData) error

type Option

type Option func(*dynatraceClient)

Option can be passed to NewClient and customizes the created client instance.

func Certs

func Certs(certs []byte) Option

func NetworkZone

func NetworkZone(networkZone string) Option

func Proxy

func Proxy(proxyURL string) Option

func SkipCertificateValidation

func SkipCertificateValidation(skip bool) Option

SkipCertificateValidation creates an Option that specifies whether validation of the server's TLS certificate should be skipped. The default is false.

type ServerError

type ServerError struct {
	Code    int
	Message string
}

ServerError represents an error returned from the server (e.g. authentication failure).

func (ServerError) Error

func (e ServerError) Error() string

Error formats the server error code and message.

type TenantInfo

type TenantInfo struct {
	ID                    string
	Token                 string
	Endpoints             []string
	CommunicationEndpoint string
}

type TokenScopes

type TokenScopes []string

TokenScopes is a list of scopes assigned to a token

func (TokenScopes) Contains

func (s TokenScopes) Contains(scope string) bool

Contains returns true if scope is included on the scopes, or false otherwise.

Jump to

Keyboard shortcuts

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