gwhub

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PingEndpoint                = "/ping"
	MetricsQueryEndpoint        = "/metrics/query"
	MetricsAggregationsEndpoint = "/metrics/aggregations"
	QueryEventRecordsEndpoint   = "/events/recordsQuery"
	EntitiesEndpoint            = "/entities"
	EntitiesSummaryEndpoint     = "/entities/summary"
	EntitiesMetricsEndpoint     = "/entities/metrics"
	EntitiesMetricsRowsEndpoint = "/entities/metrics/rows"
	EntitiesAttributesEndpoint  = "/entities/attributes"
)
View Source
const (
	Day  = 24 * time.Hour
	Week = 7 * Day
)
View Source
const (
	PT1M  = 1 * time.Minute
	PT5M  = 5 * time.Minute
	PT15M = 15 * time.Minute
	PT1H  = 1 * time.Hour
	PT3H  = 3 * time.Hour
	PT12H = 12 * time.Hour
	P1D   = 24 * time.Hour
	P1W   = 7 * 24 * time.Hour
)

ISO8601 durations used by GW Hub

View Source
const (
	Monday    = "monday"
	Tuesday   = "tuesday"
	Wednesday = "wednesday"
)

Time Windows

Variables

View Source
var ErrServerError = errors.New("error from server (HTTP Status > 299)")

ErrServerError makes it a little easier for the caller to check the underlying HTTP response

Functions

func FormatDuration added in v1.7.1

func FormatDuration(d time.Duration) (iso string)

FormatDuration converts a time.Duration to an ISO8601 duration up to weeks. Months and years are not supported.

func ParseDuration added in v1.7.1

func ParseDuration(isoDuration string) (time.Duration, error)

ParseDuration parses an ISO 8601 string representing a duration, and returns the resultant golang time.Duration instance.

From https://github.com/spatialtime/iso8601 but "fixed" to allow durations without 'T'

Types

type Bucketing

type Bucketing struct {
	Duration string `json:"duration,omitempty"`
	Count    int    `json:"count,omitempty"`
}

type Data added in v1.7.1

type Data struct {
	Bucket   time.Time                         `json:"bucket"`
	Grouping DataGrouping                      `json:"group"`
	Metrics  map[string]map[string]interface{} `json:"metrics"`
}

type DataGrouping added in v1.7.1

type DataGrouping struct {
	Rowname   string `json:"rowname,omitempty"`
	Entity    int    `json:"entity,omitempty"`
	Attribute string `json:"attribute,omitempty"`
}

type EntitiesAttributeRequest added in v1.6.1

type EntitiesAttributeRequest struct {
	Name           string `url:"-"`
	Filter         string `url:"filter,omitempty"`
	IncludeDeleted bool   `url:"includeDeleted,omitempty"`
}

EntitiesAttributeRequest type

type EntitiesAttributesRequest added in v1.6.1

type EntitiesAttributesRequest struct {
	Filter         string `url:"filter,omitempty"`
	IncludeDeleted bool   `url:"includeDeleted,omitempty"`
}

EntitiesAttributesRequest type

type EntitiesAttributesResponse added in v1.6.1

type EntitiesAttributesResponse []EntityAttributes

EntitiesAttributesResponse type

type EntitiesMetricsRequest added in v1.6.1

type EntitiesMetricsRequest struct {
	Filter            string `url:"filter,omitempty"`
	Plugin            string `url:"plugin,omitempty"`
	IncludeMappings   bool   `url:"includeMappings,omitempty"`
	IncludeDeleted    bool   `url:"includeDeleted,omitempty"`
	IncludeNonNumeric bool   `url:"includeNonNumeric,omitempty"`
}

EntitiesMetricsRequest type

type EntitiesMetricsResponse added in v1.6.1

type EntitiesMetricsResponse []EntityMetric

EntitiesMetricsResponse type

type EntitiesMetricsRowsRequest added in v1.6.1

type EntitiesMetricsRowsRequest struct {
	Filter       string    `url:"filter,omitempty"`
	Path         string    `url:"path"`
	UpdatedSince time.Time `url:"updatedSince,omitempty"`
}

EntitiesMetricsRowsRequest type

type EntitiesMetricsRowsResponse added in v1.6.1

type EntitiesMetricsRowsResponse []string

EntitiesMetricsRowsResponse type

type EntitiesRequest added in v1.6.1

type EntitiesRequest struct {
	Filter         string `url:"filter,omitempty"`
	IncludeDeleted bool   `url:"includeDeleted"`
}

EntitiesRequest type

type EntitiesResponse added in v1.6.1

type EntitiesResponse []Entity

EntitiesResponse type

type EntitiesSummariesCount added in v1.6.1

type EntitiesSummariesCount struct {
	States         map[string]string `json:"states"`
	Count          int               `json:"count"`
	SampleEntities []int             `json:"sampleEntities"`
}

EntitiesSummariesCount type

type EntitiesSummary added in v1.6.1

type EntitiesSummary struct {
	Attributes        map[string]string        `json:"attributes"`
	Count             int                      `json:"count"`
	SampleEntityCount int                      `json:"sampleEntityCount"`
	Counts            []EntitiesSummariesCount `json:"counts"`
}

EntitiesSummary type

type EntitiesSummaryRequest added in v1.7.0

type EntitiesSummaryRequest struct {
	Filter         string   `url:"filter,omitempty"`
	GroupBy        []string `url:"groupBy,omitempty"`
	Samples        int      `url:"nrSamples,omitempty"`
	IncludeDeleted bool     `url:"includeDeleted,omitempty"`
}

EntitiesSummaryRequest

type EntitiesSummaryResponse added in v1.6.1

type EntitiesSummaryResponse []EntitiesSummary

EntitiesSummaryResponse type

type Entity

type Entity struct {
	ID         int               `json:"id"`
	Attributes map[string]string `json:"attributes"`
	IsDeleted  bool              `json:"isDeleted"`
}

Entity type

type EntityAttributeResponse added in v1.6.1

type EntityAttributeResponse []string

EntityAttributeResponse type

type EntityAttributes

type EntityAttributes struct {
	Name       string `json:"name"`
	ValueCount int    `json:"valueCount"`
}

EntityAttributes type

type EntityMetric added in v1.6.1

type EntityMetric struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Unit     string `json:"unit"`
	Mappings []EntityMetricMapping
}

EntityMetric type

type EntityMetricMapping added in v1.6.1

type EntityMetricMapping struct {
	LegacyPath string `json:"legacyPath"`
	DataviewID int    `json:"dataviewId"`
	IsDeleted  bool   `json:"isDeleted"`
}

EntityMetricMapping type

type EntityMetricsDataRequest added in v1.6.1

type EntityMetricsDataRequest struct {
	EntityID int       `url:"-"`
	Path     string    `url:"path"`
	From     time.Time `url:"from"`
	To       time.Time `url:"to"`
	Skip     int       `url:"skip"`
	Limit    int       `url:"limit"`
}

EntityMetricsDataRequest type

type EntityMetricsDataResponse added in v1.6.1

type EntityMetricsDataResponse struct {
	TotalCount int `json:"totalCount"`
	Values     []EntityMetricsDataValue
}

EntityMetricsDataResponse type

type EntityMetricsDataValue added in v1.6.1

type EntityMetricsDataValue struct {
	Timestamp time.Time `json:"timestamp"`
	Value     string    `json:"value"`
}

EntityMetricsDataValue type

type EntityMetricsRequest added in v1.6.1

type EntityMetricsRequest struct {
	EntityID          int  `url:"-"`
	IncludeDeleted    bool `url:"includeDeleted,omitempty"`
	IncludeNonNumeric bool `url:"includeNonNumeric,omitempty"`
}

EntityMetricsRequest type

type EntityMetricsResponse added in v1.6.1

type EntityMetricsResponse []EntityMetric

EntityMetricsResponse type

type EntityMetricsRowsRequest added in v1.6.1

type EntityMetricsRowsRequest struct {
	EntityID     int       `url:"-"`
	Path         string    `url:"path"`
	UpdatedSince time.Time `url:"updatedSince,omitempty"`
}

EntityMetricsRowsRequest type

type EntityMetricsRowsResponse added in v1.6.1

type EntityMetricsRowsResponse []string

EntityMetricsRowsResponse type

type Event

type Event struct {
	EntityID  int       `json:"entityId"`
	Timestamp time.Time `json:"timestamp"`
	Data      EventData `json:"data"`
	Metric    string    `json:"metric"`
	Type      string    `json:"type"`
}

type EventData

type EventData struct {
	Severity string            `json:"severity"`
	Active   bool              `json:"active"`
	Value    map[string]string `json:"value"`
}

type Filter

type Filter struct {
	Entities    string       `json:"entities,omitempty"`
	Range       TimeRange    `json:"range"`
	TimeWindows []TimeWindow `json:"timeWindows,omitempty"`
}

type Hub

type Hub struct {
	*rest.Client
}

Hub holds connection details for a GW Hub

func New

func New(options ...rest.Options) *Hub

func (*Hub) Entities

func (h *Hub) Entities(ctx context.Context, request EntitiesRequest) (response EntitiesResponse, resp *http.Response, err error)

Entities request

func (*Hub) EntitiesAttributes

func (h *Hub) EntitiesAttributes(ctx context.Context, request EntitiesAttributesRequest) (response EntitiesAttributesResponse, resp *http.Response, err error)

EntitiesAttributes request

func (*Hub) EntitiesMetrics added in v1.6.1

func (h *Hub) EntitiesMetrics(ctx context.Context, request EntitiesMetricsRequest) (response EntitiesMetricsResponse, resp *http.Response, err error)

EntitiesMetrics request

func (*Hub) EntitiesMetricsRows added in v1.6.1

func (h *Hub) EntitiesMetricsRows(ctx context.Context, request EntityMetricsRowsRequest) (response EntityMetricsRowsResponse, resp *http.Response, err error)

EntitiesMetricsRows request

func (*Hub) EntitiesSummary added in v1.6.1

func (h *Hub) EntitiesSummary(ctx context.Context, request EntitiesSummaryRequest) (response EntitiesSummaryResponse, resp *http.Response, err error)

EntitiesSummary request

func (*Hub) Entity added in v1.6.1

func (h *Hub) Entity(ctx context.Context, entity int) (response Entity, resp *http.Response, err error)

Entity request

func (*Hub) EntityAttributeValues

func (h *Hub) EntityAttributeValues(ctx context.Context, request EntitiesAttributeRequest) (response EntityAttributeResponse, resp *http.Response, err error)

EntityAttributeValues request

func (*Hub) EntityMetrics added in v1.6.1

func (h *Hub) EntityMetrics(ctx context.Context, request EntityMetricsRequest) (response EntityMetricsResponse, resp *http.Response, err error)

EntityMetrics request

func (*Hub) EntityMetricsData added in v1.6.1

func (h *Hub) EntityMetricsData(ctx context.Context, request EntityMetricsDataRequest) (response EntityMetricsDataResponse, resp *http.Response, err error)

EntityMetricsData request

func (*Hub) EntityMetricsRows added in v1.6.1

func (h *Hub) EntityMetricsRows(ctx context.Context, request EntityMetricsRowsRequest) (response EntityMetricsRowsResponse, resp *http.Response, err error)

EntityMetricsRows request

func (*Hub) MetricsAggregations

func (h *Hub) MetricsAggregations(ctx context.Context) (response MetricsAggregationsResponse, resp *http.Response, err error)

MetricsAggregations request

func (*Hub) MetricsQuery

func (h *Hub) MetricsQuery(ctx context.Context, request MetricsQueryRequest) (response MetricsQueryResponse, resp *http.Response, err error)

MetricsQuery request

func (*Hub) Ping

func (hub *Hub) Ping(ctx context.Context) (resp *http.Response, err error)

func (*Hub) QueryEventRecords

func (h *Hub) QueryEventRecords(ctx context.Context, request QueryEventRecordsRequest) (response QueryEventRecordsResponse, resp *http.Response, err error)

QueryEventRecords request

type Metric

type Metric struct {
	Identifier string   `json:"identifier"`
	Include    []string `json:"include"`
}

type MetricsAggregation

type MetricsAggregation struct {
	Parameters  []map[string]string `json:"parameters"`
	Description string              `json:"description"`
}

MetricsAggregation type

type MetricsAggregationsResponse

type MetricsAggregationsResponse map[string]MetricsAggregation

MetricsAggregationsResponse type

type MetricsQueryRequest

type MetricsQueryRequest struct {
	Grouping     []string  `json:"grouping,omitempty"`
	Filter       Filter    `json:"filter"`
	Aggregations []string  `json:"aggregations"`
	Metrics      []Metric  `json:"metrics"`
	ZoneID       string    `json:"zoneId,omitempty"`
	Bucketing    Bucketing `json:"bucketing,omitempty"`
}

type MetricsQueryResponse

type MetricsQueryResponse struct {
	Schema Schema `json:"schema"`
	Data   []Data `json:"data"`
}

type QueryEventRecordsRequest

type QueryEventRecordsRequest struct {
	Skip    int      `json:"skip,omitempty"`
	Filter  Filter   `json:"filter"`
	Metrics []string `json:"metrics,omitempty"`
	ZoneID  string   `json:"zoneId,omitempty"`
	Limit   int      `json:"limit"`
	Events  []string `json:"events"`
}

type QueryEventRecordsResponse

type QueryEventRecordsResponse map[string][]Event

type Schema added in v1.7.1

type Schema struct {
	Bucketing Bucketing                         `json:"bucketing"`
	Grouping  []string                          `json:"grouping"`
	Metrics   map[string]map[string]interface{} `json:"metrics"`
}

type TimeRange

type TimeRange struct {
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

func (TimeRange) MarshalJSON added in v1.7.0

func (t TimeRange) MarshalJSON() ([]byte, error)

MarshalJSON is needed as Hub only accepts short form ISO times

type TimeWindow

type TimeWindow struct {
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
	On   []string  `json:"on,omitempty"`
}

TimeWindow is only time-of-day

func (TimeWindow) MarshalJSON added in v1.7.0

func (t TimeWindow) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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