-
Notifications
You must be signed in to change notification settings - Fork 1
/
series.go
71 lines (60 loc) · 1.92 KB
/
series.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ilert
import (
"errors"
"fmt"
)
// SingleSeries definition https://api.ilert.com/api-docs/#tag/Series
type SingleSeries struct {
Timestamp int64 `json:"timestamp,omitempty"`
Value float64 `json:"value"`
}
// MultipleSeries definition https://api.ilert.com/api-docs/#tag/Series
type MultipleSeries struct {
Series []SingleSeries `json:"series"`
}
// CreateSingleSeriesInput represents the input of a CreateSingleSeries operation.
type CreateSingleSeriesInput struct {
_ struct{}
Series *SingleSeries
MetricKey *string
}
// CreateSingleSeries ingests a series for a metric. https://api.ilert.com/api-docs/#tag/Series/paths/~1series~1{key}/post
func (c *Client) CreateSingleSeries(input *CreateSingleSeriesInput) error {
if input == nil {
return errors.New("input is required")
}
if input.MetricKey == nil {
return errors.New("metric integration key is required")
}
resp, err := c.httpClient.R().SetBody(input.Series).Post(fmt.Sprintf("%s/%s", apiRoutes.series, *input.MetricKey))
if err != nil {
return err
}
if apiErr := getGenericAPIError(resp, 202); apiErr != nil {
return apiErr
}
return nil
}
// CreateMultipleSeriesInput represents the input of a CreateMultipleSeries operation.
type CreateMultipleSeriesInput struct {
_ struct{}
Series *MultipleSeries
MetricKey *string
}
// CreateMultipleSeries ingests multiple series for a metric. https://api.ilert.com/api-docs/#tag/Series/paths/~1series~1{key}/post
func (c *Client) CreateMultipleSeries(input *CreateMultipleSeriesInput) error {
if input == nil {
return errors.New("input is required")
}
if input.MetricKey == nil {
return errors.New("metric integration key is required")
}
resp, err := c.httpClient.R().SetBody(input.Series).Post(fmt.Sprintf("%s/%s", apiRoutes.series, *input.MetricKey))
if err != nil {
return err
}
if apiErr := getGenericAPIError(resp, 202); apiErr != nil {
return apiErr
}
return nil
}