librato

package
v0.0.0-...-848ba84 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: MIT Imports: 12 Imported by: 82

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors; and returns them if present. A Response is considered an error if it has a status code outside the 2XX range.

func Float

func Float(v float64) *float64

Float is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.

func RenderErrorFromArray

func RenderErrorFromArray(errors []interface{}) string

RenderErrorFromArray returns a string with the parameter errors

func RenderErrorFromMap

func RenderErrorFromMap(errors map[string]interface{}) string

RenderErrorFromMap returns a string with the parameter errors (e.g. from Conditions)

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func Stringify

func Stringify(message interface{}) string

Stringify attempts to create a reasonable string representation of types in the Librato library. It does things like resolve pointers to their values and omits struct fields with nil values.

func Uint

func Uint(v uint) *uint

Uint is a helper routine that allocates a new uint value to store v and returns a pointer to it.

Types

type Alert

type Alert struct {
	Name       *string          `json:"name"`
	ID         *uint            `json:"id,omitempty"`
	Conditions []AlertCondition `json:"conditions,omitempty"`
	// These are interface{} because the Librato API asks for integers
	// on Create and returns hashes on Get
	Services     interface{}      `json:"services,omitempty"`
	Attributes   *AlertAttributes `json:"attributes,omitempty"`
	Description  *string          `json:"description,omitempty"`
	Active       *bool            `json:"active,omitempty"`
	RearmSeconds *uint            `json:"rearm_seconds,omitempty"`
	// Required for older "mixed mode" source & tags Librato accounts
	Md *bool `json:"md,omitempty"`
}

Alert represents a Librato Alert.

func (Alert) String

func (a Alert) String() string

type AlertAttributes

type AlertAttributes struct {
	RunbookURL *string `json:"runbook_url,omitempty"`
}

AlertAttributes represents the attributes of an alert.

type AlertCondition

type AlertCondition struct {
	ID              *uint                  `json:"id,omitempty"`
	Type            *string                `json:"type"`
	MetricName      *string                `json:"metric_name"`
	Source          *string                `json:"source,omitempty"`
	Tags            []AlertConditionTagSet `json:"tags,omitempty"`
	DetectReset     *bool                  `json:"detect_reset,omitempty"`
	Threshold       *float64               `json:"threshold,omitempty"`
	SummaryFunction *string                `json:"summary_function,omitempty"`
	Duration        *uint                  `json:"duration,omitempty"`
}

AlertCondition represents an alert trigger condition.

type AlertConditionTagSet

type AlertConditionTagSet struct {
	Name    *string   `json:"name"`
	Grouped *bool     `json:"grouped,omitempty"`
	Values  []*string `json:"values"`
}

type AlertsService

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

AlertsService handles communication with the Librato API methods related to alerts.

func (*AlertsService) Create

func (a *AlertsService) Create(alert *Alert) (*Alert, *http.Response, error)

Create an alert

Librato API docs: https://www.librato.com/docs/api/?shell#create-an-alert

func (*AlertsService) Delete

func (a *AlertsService) Delete(id uint) (*http.Response, error)

Delete an alert

Librato API docs: https://www.librato.com/docs/api/?shell#delete-alert

func (*AlertsService) Get

func (a *AlertsService) Get(id uint) (*Alert, *http.Response, error)

Get an alert by ID

Librato API docs: https://www.librato.com/docs/api/#retrieve-alert-by-id

func (*AlertsService) Update

func (a *AlertsService) Update(alertID uint, alert *Alert) (*http.Response, error)

Update an alert.

Librato API docs: https://www.librato.com/docs/api/?shell#update-alert

type Annotation

type Annotation struct {
	Name        *string          `json:"name"`
	Title       *string          `json:"title"`
	Source      *string          `json:"source,omitempty"`
	Description *string          `json:"description,omitempty"`
	Links       []AnnotationLink `json:"links,omitempty"`
	StartTime   *uint            `json:"start_time,omitempty"`
	EndTime     *uint            `json:"end_time,omitempty"`
}

Annotation represents a Librato Annotation.

type AnnotationLink struct {
	Label *string `json:"label,omitempty"`
	Rel   *string `json:"rel"`
	Href  *string `json:"href,omitempty"`
}

AnnotationLink represents a Librato Annotation Link.

type AnnotationsService

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

AnnotationsService handles communication with the Librato API methods related to Annotations.

func (*AnnotationsService) Create

func (a *AnnotationsService) Create(annotation *Annotation) (*Annotation, *http.Response, error)

Create an Annotation

Librato API docs: https://www.librato.com/docs/api/?shell#create-an-Annotation

type Client

type Client struct {

	// Headers to attach to every request made with the client. Headers will be
	// used to provide Librato API authentication details and other necessary
	// headers.
	Headers map[string]string

	// Email and Token contains the authentication details needed to authenticate
	// against the Librato API.
	Email, Token string

	// Base URL for API requests. Defaults to the public Librato API, but can be
	// set to an alternate endpoint if necessary. BaseURL should always be
	// terminated by a slash.
	BaseURL *url.URL

	// User agent used when communicating with the Librato API.
	UserAgent string

	// Services used to manipulate API entities.
	Spaces      *SpacesService
	Metrics     *MetricsService
	Alerts      *AlertsService
	Services    *ServicesService
	Annotations *AnnotationsService
	// contains filtered or unexported fields
}

A Client manages communication with the Librato API.

func NewClient

func NewClient(email, token string) *Client

NewClient returns a new Librato API client bound to the public Librato API.

func NewClientWithBaseURL

func NewClientWithBaseURL(baseURL *url.URL, email, token string) *Client

NewClientWithBaseURL returned a new Librato API client with a custom base URL.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body. If specified, the map provided by headers will be used to update request headers.

type ConditionParamError

type ConditionParamError struct {
	Condition map[string][]string `json:"conditions,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error messages produces by Librato API.
	Errors ErrorResponseMessages `json:"errors"`
}

ErrorResponse reports an error caused by an API request. ErrorResponse implements the Error interface.

func (*ErrorResponse) Error

func (er *ErrorResponse) Error() string

type ErrorResponseMessages

type ErrorResponseMessages struct {
	Params  map[string]interface{} `json:"params,omitempty"`
	Request []string               `json:"request,omitempty"`
	System  []string               `json:"system,omitempty"`
}

ErrorResponseMessages contains error messages returned from the Librato API.

type GaugeMeasurement

type GaugeMeasurement struct {
	*Measurement
	Count      *uint    `json:"count,omitempty"`
	Sum        *float64 `json:"sum,omitempty"`
	Max        *float64 `json:"max,omitempty"`
	Min        *float64 `json:"min,omitempty"`
	SumSquares *float64 `json:"sum_squares,omitempty"`
}

GaugeMeasurement represents a Librato measurement gauge.

type ListMetricsOptions

type ListMetricsOptions struct {
	*PaginationMeta
	Name string `url:"name,omitempty"`
}

ListMetricsOptions are used to coordinate paging of metrics.

func (*ListMetricsOptions) AdvancePage

AdvancePage advances to the specified page in result set, while retaining the filtering options.

type ListMetricsResponse

type ListMetricsResponse struct {
	ThisPage *PaginationResponseMeta
	NextPage *PaginationMeta
}

ListMetricsResponse represents the response of a List call against the metrics service.

type Measurement

type Measurement struct {
	Name        string   `json:"name"`
	Value       *float64 `json:"value,omitempty"`
	MeasureTime *uint    `json:"measure_time,omitempty"`
	Source      *string  `json:"source,omitempty"`
}

Measurement represents a Librato Measurement.

type MeasurementSubmission

type MeasurementSubmission struct {
	MeasureTime *uint               `json:"measure_time,omitempty"`
	Source      *string             `json:"source,omitempty"`
	Gauges      []*GaugeMeasurement `json:"gauges,omitempty"`
	Counters    []*Measurement      `json:"counters,omitempty"`
}

MeasurementSubmission represents the payload to submit/create a metric.

type Metric

type Metric struct {
	Name        *string           `json:"name"`
	Description *string           `json:"description,omitempty"`
	Type        *string           `json:"type"`
	Period      *uint             `json:"period,omitempty"`
	DisplayName *string           `json:"display_name,omitempty"`
	Composite   *string           `json:"composite,omitempty"`
	Attributes  *MetricAttributes `json:"attributes,omitempty"`
}

Metric represents a Librato Metric.

type MetricAttributes

type MetricAttributes struct {
	Color *string `json:"color"`
	// These are interface{} because sometimes the Librato API
	// returns strings, and sometimes it returns integers
	DisplayMax        interface{} `json:"display_max"`
	DisplayMin        interface{} `json:"display_min"`
	DisplayUnitsLong  string      `json:"display_units_long"`
	DisplayUnitsShort string      `json:"display_units_short"`
	DisplayStacked    bool        `json:"display_stacked"`
	CreatedByUA       string      `json:"created_by_ua,omitempty"`
	GapDetection      bool        `json:"gap_detection,omitempty"`
	Aggregate         bool        `json:"aggregate,omitempty"`
}

MetricAttributes are named attributes as key:value pairs.

type MetricsService

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

MetricsService handles communication with the Librato API methods related to metrics.

func (*MetricsService) Create

func (m *MetricsService) Create(measurements *MeasurementSubmission) (*http.Response, error)

Create metrics

Librato API docs: https://www.librato.com/docs/api/#create-a-measurement

func (*MetricsService) Delete

func (m *MetricsService) Delete(name string) (*http.Response, error)

Delete a metric.

Librato API docs: https://www.librato.com/docs/api/#delete-a-metric-by-name

func (*MetricsService) Get

func (m *MetricsService) Get(name string) (*Metric, *http.Response, error)

Get a metric by name

Librato API docs: https://www.librato.com/docs/api/#retrieve-a-metric-by-name

func (*MetricsService) List

List metrics using the provided options.

Librato API docs: https://www.librato.com/docs/api/#list-a-subset-of-metrics

func (*MetricsService) Update

func (m *MetricsService) Update(metric *Metric) (*http.Response, error)

Update a metric.

Librato API docs: https://www.librato.com/docs/api/#update-a-metric-by-name

type PaginationMeta

type PaginationMeta struct {
	Offset  uint   `url:"offset,omitempty"`
	Length  uint   `url:"length,omitempty"`
	OrderBy string `url:"orderby,omitempty"`
	Sort    string `url:"sort,omitempty"`
}

PaginationMeta contains metadata that the Librato API requires for pagination http://dev.librato.com/v1/pagination

func (*PaginationMeta) EncodeValues

func (m *PaginationMeta) EncodeValues(name string, values *url.Values) error

EncodeValues is implemented to allow other strucs to embed PaginationMeta and still use github.com/google/go-querystring/query to encode the struct. It makes PaginationMeta implement query.Encoder.

type PaginationResponseMeta

type PaginationResponseMeta struct {
	Offset uint `json:"offset"`
	Length uint `json:"length"`
	Total  uint `json:"total"`
	Found  uint `json:"found"`
}

PaginationResponseMeta contains pagination metadata from Librato API responses.

type Service

type Service struct {
	ID    *uint   `json:"id,omitempty"`
	Type  *string `json:"type,omitempty"`
	Title *string `json:"title,omitempty"`
	// This is an interface{} because it's a hash of settings
	// specific to each service.
	Settings map[string]string `json:"settings,omitempty"`
}

Service represents a Librato Service.

func (Service) String

func (a Service) String() string

type ServicesService

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

ServicesService handles communication with the Librato API methods related to notification services.

func (*ServicesService) Create

func (s *ServicesService) Create(service *Service) (*Service, *http.Response, error)

Create a service

Librato API docs: https://www.librato.com/docs/api/#create-a-service

func (*ServicesService) Delete

func (s *ServicesService) Delete(id uint) (*http.Response, error)

Delete a service

Librato API docs: https://www.librato.com/docs/api/#delete-a-service

func (*ServicesService) Get

func (s *ServicesService) Get(id uint) (*Service, *http.Response, error)

Get a service by ID

Librato API docs: https://www.librato.com/docs/api/#retrieve-specific-service

func (*ServicesService) Update

func (s *ServicesService) Update(serviceID uint, service *Service) (*http.Response, error)

Update a service.

Librato API docs: https://www.librato.com/docs/api/#update-a-service

type Space

type Space struct {
	Name *string `json:"name"`
	ID   *uint   `json:"id,omitempty"`
}

Space represents a Librato Space.

func (Space) String

func (s Space) String() string

type SpaceChart

type SpaceChart struct {
	ID           *uint              `json:"id,omitempty"`
	Name         *string            `json:"name,omitempty"`
	Type         *string            `json:"type,omitempty"`
	Min          *float64           `json:"min,omitempty"`
	Max          *float64           `json:"max,omitempty"`
	Label        *string            `json:"label,omitempty"`
	RelatedSpace *uint              `json:"related_space,omitempty"`
	Streams      []SpaceChartStream `json:"streams,omitempty"`
}

SpaceChart represents a chart in a Librato Space.

type SpaceChartStream

type SpaceChartStream struct {
	Metric            *string  `json:"metric,omitempty"`
	Source            *string  `json:"source,omitempty"`
	Composite         *string  `json:"composite,omitempty"`
	GroupFunction     *string  `json:"group_function,omitempty"`
	SummaryFunction   *string  `json:"summary_function,omitempty"`
	Color             *string  `json:"color,omitempty"`
	Name              *string  `json:"name,omitempty"`
	UnitsShort        *string  `json:"units_short,omitempty"`
	UnitsLong         *string  `json:"units_long,omitempty"`
	Min               *float64 `json:"min,omitempty"`
	Max               *float64 `json:"max,omitempty"`
	TransformFunction *string  `json:"transform_function,omitempty"`
	Period            *int64   `json:"period,omitempty"`
}

SpaceChartStream represents a single stream in a chart in a Librato Space.

type SpaceListOptions

type SpaceListOptions struct {
	// filter by name
	Name string `url:"name,omitempty"`
}

SpaceListOptions specifies the optional parameters to the SpaceService.Find method.

type SpacesService

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

SpacesService handles communication with the Librato API methods related to spaces.

func (*SpacesService) Create

func (s *SpacesService) Create(space *Space) (*Space, *http.Response, error)

Create a space with a given name.

Librato API docs: http://dev.librato.com/v1/post/spaces

func (*SpacesService) CreateChart

func (s *SpacesService) CreateChart(spaceID uint, chart *SpaceChart) (*SpaceChart, *http.Response, error)

CreateChart creates a chart in a given Librato Space.

Librato API docs: http://dev.librato.com/v1/post/spaces/:id/charts

func (*SpacesService) Delete

func (s *SpacesService) Delete(id uint) (*http.Response, error)

Delete a space.

Librato API docs: http://dev.librato.com/v1/delete/spaces/:id

func (*SpacesService) DeleteChart

func (s *SpacesService) DeleteChart(spaceID, chartID uint) (*http.Response, error)

DeleteChart deletes a chart.

Librato API docs: http://dev.librato.com/v1/delete/spaces/:id/charts/:id

func (*SpacesService) Get

func (s *SpacesService) Get(id uint) (*Space, *http.Response, error)

Get fetches a space based on the provided ID.

Librato API docs: http://dev.librato.com/v1/get/spaces/:id

func (*SpacesService) GetChart

func (s *SpacesService) GetChart(spaceID, chartID uint) (*SpaceChart, *http.Response, error)

GetChart gets a chart with a given ID in a space with a given ID.

Librato API docs: http://dev.librato.com/v1/get/spaces/:id/charts

func (*SpacesService) List

func (s *SpacesService) List(opt *SpaceListOptions) ([]Space, *http.Response, error)

List spaces using the provided options.

Librato API docs: http://dev.librato.com/v1/get/spaces

func (*SpacesService) ListCharts

func (s *SpacesService) ListCharts(spaceID uint) ([]SpaceChart, *http.Response, error)

ListCharts lists all charts in a given Librato Space.

Librato API docs: http://dev.librato.com/v1/get/spaces/:id/charts

func (*SpacesService) Update

func (s *SpacesService) Update(spaceID uint, space *Space) (*http.Response, error)

Update a space.

Librato API docs: http://dev.librato.com/v1/put/spaces/:id

func (*SpacesService) UpdateChart

func (s *SpacesService) UpdateChart(spaceID, chartID uint, chart *SpaceChart) (*http.Response, error)

UpdateChart updates a chart.

Librato API docs: http://dev.librato.com/v1/put/spaces/:id/charts/:id

Jump to

Keyboard shortcuts

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