diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d2713f..f95e670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - [#404](https://github.com/influxdata/influxdb-client-go/pull/404) Expose HTTP response headers in the Error type to aid analysis and debugging of error results. Add selected response headers to the error log. +### Fixes +- [#403](https://github.com/influxdata/influxdb-client-go/pull/403) Custom checks de/serialization to allow calling server Check API + ## 2.13.0 [2023-12-05] ### Features diff --git a/api/checks_test.go b/api/checks_test.go new file mode 100644 index 0000000..6c2240d --- /dev/null +++ b/api/checks_test.go @@ -0,0 +1,357 @@ +//go:build e2e + +// Copyright 2024 InfluxData, Inc. All rights reserved. +// Use of this source code is governed by MIT +// license that can be found in the LICENSE fil +package api_test + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + + influxdb2 "github.com/influxdata/influxdb-client-go/v2" + "github.com/influxdata/influxdb-client-go/v2/domain" +) + +var msg = "Check: ${ r._check_name } is: ${ r._level }" +var flux = `from(bucket: "foo") |> range(start: -1d, stop: now()) |> aggregateWindow(every: 1m, fn: mean) |> filter(fn: (r) => r._field == "usage_user") |> yield()` +var every = "1h" +var offset = "0s" +var timeSince = "90m" +var staleTime = "30m" +var level = domain.CheckStatusLevelCRIT + +func TestCreateGetDeleteThresholdCheck(t *testing.T) { + ctx := context.Background() + client := influxdb2.NewClient(serverURL, authToken) + + greater := domain.GreaterThreshold{} + greater.Value = 10.0 + lc := domain.CheckStatusLevelCRIT + greater.Level = &lc + greater.AllValues = &[]bool{true}[0] + + lesser := domain.LesserThreshold{} + lesser.Value = 1.0 + lo := domain.CheckStatusLevelOK + lesser.Level = &lo + + rang := domain.RangeThreshold{} + rang.Min = 3.0 + rang.Max = 8.0 + lw := domain.CheckStatusLevelWARN + rang.Level = &lw + + org, err := client.OrganizationsAPI().FindOrganizationByName(ctx, "my-org") + require.Nil(t, err) + + thresholds := []domain.Threshold{&greater, &lesser, &rang} + + check := domain.ThresholdCheck{ + CheckBaseExtend: domain.CheckBaseExtend{ + CheckBase: domain.CheckBase{ + Name: "ThresholdCheck test", + OrgID: *org.Id, + Query: domain.DashboardQuery{Text: &flux}, + Status: domain.TaskStatusTypeActive, + }, + Every: &every, + Offset: &offset, + StatusMessageTemplate: &msg, + }, + Thresholds: &thresholds, + } + params := domain.CreateCheckAllParams{ + Body: domain.CreateCheckJSONRequestBody(&check), + } + nc, err := client.APIClient().CreateCheck(context.Background(), ¶ms) + require.Nil(t, err) + tc := validateTC(t, nc, *org.Id) + + gp := domain.GetChecksIDAllParams{CheckID: *tc.Id} + + c, err := client.APIClient().GetChecksID(context.Background(), &gp) + require.Nil(t, err) + tc = validateTC(t, c, *org.Id) + + dp := domain.DeleteChecksIDAllParams{ + CheckID: *tc.Id, + } + + err = client.APIClient().DeleteChecksID(context.Background(), &dp) + require.Nil(t, err) + + _, err = client.APIClient().GetChecksID(context.Background(), &gp) + require.NotNil(t, err) +} + +func TestCreateGetDeleteDeadmanCheck(t *testing.T) { + client := influxdb2.NewClient(serverURL, authToken) + + ctx := context.Background() + + org, err := client.OrganizationsAPI().FindOrganizationByName(ctx, "my-org") + require.Nil(t, err) + + check := domain.DeadmanCheck{ + CheckBaseExtend: domain.CheckBaseExtend{ + CheckBase: domain.CheckBase{ + Name: "DeadmanCheck test", + OrgID: *org.Id, + Query: domain.DashboardQuery{Text: &flux}, + Status: domain.TaskStatusTypeActive, + }, + Every: &every, + Offset: &offset, + StatusMessageTemplate: &msg, + }, + TimeSince: &timeSince, + StaleTime: &staleTime, + Level: &level, + } + params := domain.CreateCheckAllParams{ + Body: domain.CreateCheckJSONRequestBody(&check), + } + nc, err := client.APIClient().CreateCheck(context.Background(), ¶ms) + require.Nil(t, err) + dc := validateDC(t, nc, *org.Id) + + gp := domain.GetChecksIDAllParams{CheckID: *dc.Id} + + c, err := client.APIClient().GetChecksID(context.Background(), &gp) + require.Nil(t, err) + dc = validateDC(t, c, *org.Id) + + dp := domain.DeleteChecksIDAllParams{ + CheckID: *dc.Id, + } + + err = client.APIClient().DeleteChecksID(context.Background(), &dp) + require.Nil(t, err) + +} + +func TestUpdateThresholdCheck(t *testing.T) { + ctx := context.Background() + client := influxdb2.NewClient(serverURL, authToken) + + greater := domain.GreaterThreshold{} + greater.Value = 10.0 + lc := domain.CheckStatusLevelCRIT + greater.Level = &lc + greater.AllValues = &[]bool{true}[0] + + org, err := client.OrganizationsAPI().FindOrganizationByName(ctx, "my-org") + require.Nil(t, err) + + thresholds := []domain.Threshold{&greater} + + ev := "1m" + + check := domain.ThresholdCheck{ + CheckBaseExtend: domain.CheckBaseExtend{ + CheckBase: domain.CheckBase{ + Name: "ThresholdCheck update test", + OrgID: *org.Id, + Query: domain.DashboardQuery{Text: &flux}, + Status: domain.TaskStatusTypeActive, + }, + Every: &ev, + Offset: &offset, + StatusMessageTemplate: &msg, + }, + Thresholds: &thresholds, + } + params := domain.CreateCheckAllParams{ + Body: domain.CreateCheckJSONRequestBody(&check), + } + nc, err := client.APIClient().CreateCheck(context.Background(), ¶ms) + require.Nil(t, err) + require.NotNil(t, nc) + tc := nc.(*domain.ThresholdCheck) + + lesser := domain.LesserThreshold{} + lesser.Value = 1.0 + lo := domain.CheckStatusLevelOK + lesser.Level = &lo + + rang := domain.RangeThreshold{} + rang.Min = 3.0 + rang.Max = 8.0 + lw := domain.CheckStatusLevelWARN + rang.Level = &lw + + thresholds = []domain.Threshold{&greater, &lesser, &rang} + tc.Thresholds = &thresholds + tc.Every = &every + tc.Name = "ThresholdCheck test" + + updateParams := domain.PutChecksIDAllParams{ + CheckID: *tc.Id, + Body: tc, + } + nc, err = client.APIClient().PutChecksID(context.Background(), &updateParams) + require.Nil(t, err) + require.NotNil(t, nc) + tc = validateTC(t, nc, *org.Id) + + dp := domain.DeleteChecksIDAllParams{ + CheckID: *tc.Id, + } + + err = client.APIClient().DeleteChecksID(context.Background(), &dp) + require.Nil(t, err) +} + +func TestGetChecks(t *testing.T) { + client := influxdb2.NewClient(serverURL, authToken) + + ctx := context.Background() + + org, err := client.OrganizationsAPI().FindOrganizationByName(ctx, "my-org") + require.Nil(t, err) + + check := domain.DeadmanCheck{ + CheckBaseExtend: domain.CheckBaseExtend{ + CheckBase: domain.CheckBase{ + Name: "DeadmanCheck test", + OrgID: *org.Id, + Query: domain.DashboardQuery{Text: &flux}, + Status: domain.TaskStatusTypeActive, + }, + Every: &every, + Offset: &offset, + StatusMessageTemplate: &msg, + }, + TimeSince: &timeSince, + StaleTime: &staleTime, + Level: &level, + } + params := domain.CreateCheckAllParams{ + Body: domain.CreateCheckJSONRequestBody(&check), + } + nc, err := client.APIClient().CreateCheck(context.Background(), ¶ms) + require.Nil(t, err) + validateDC(t, nc, *org.Id) + + greater := domain.GreaterThreshold{} + greater.Value = 10.0 + lc := domain.CheckStatusLevelCRIT + greater.Level = &lc + greater.AllValues = &[]bool{true}[0] + + lesser := domain.LesserThreshold{} + lesser.Value = 1.0 + lo := domain.CheckStatusLevelOK + lesser.Level = &lo + + rang := domain.RangeThreshold{} + rang.Min = 3.0 + rang.Max = 8.0 + lw := domain.CheckStatusLevelWARN + rang.Level = &lw + + thresholds := []domain.Threshold{&greater, &lesser, &rang} + + check2 := domain.ThresholdCheck{ + CheckBaseExtend: domain.CheckBaseExtend{ + CheckBase: domain.CheckBase{ + Name: "ThresholdCheck test", + OrgID: *org.Id, + Query: domain.DashboardQuery{Text: &flux}, + Status: domain.TaskStatusTypeActive, + }, + Every: &every, + Offset: &offset, + StatusMessageTemplate: &msg, + }, + Thresholds: &thresholds, + } + params2 := domain.CreateCheckAllParams{ + Body: domain.CreateCheckJSONRequestBody(&check2), + } + nc, err = client.APIClient().CreateCheck(context.Background(), ¶ms2) + require.Nil(t, err) + validateTC(t, nc, *org.Id) + + gp := domain.GetChecksParams{ + OrgID: *org.Id, + } + checks, err := client.APIClient().GetChecks(context.Background(), &gp) + require.Nil(t, err) + require.NotNil(t, checks) + require.NotNil(t, checks.Checks) + assert.Len(t, *checks.Checks, 2) + dc := validateDC(t, (*checks.Checks)[0], *org.Id) + tc := validateTC(t, (*checks.Checks)[1], *org.Id) + + dp := domain.DeleteChecksIDAllParams{ + CheckID: *dc.Id, + } + err = client.APIClient().DeleteChecksID(context.Background(), &dp) + require.Nil(t, err) + + dp2 := domain.DeleteChecksIDAllParams{ + CheckID: *tc.Id, + } + err = client.APIClient().DeleteChecksID(context.Background(), &dp2) + require.Nil(t, err) + + checks, err = client.APIClient().GetChecks(context.Background(), &gp) + require.Nil(t, err) + require.NotNil(t, checks) + assert.Nil(t, checks.Checks) +} + +func validateDC(t *testing.T, nc domain.Check, orgID string) *domain.DeadmanCheck { + require.NotNil(t, nc) + require.Equal(t, "deadman", nc.Type()) + dc := nc.(*domain.DeadmanCheck) + require.NotNil(t, dc) + assert.Equal(t, "DeadmanCheck test", dc.Name) + assert.Equal(t, orgID, dc.OrgID) + assert.Equal(t, msg, *dc.StatusMessageTemplate) + assert.Equal(t, flux, *dc.Query.Text) + assert.Equal(t, every, *dc.Every) + assert.Equal(t, offset, *dc.Offset) + assert.Equal(t, domain.TaskStatusTypeActive, dc.Status) + assert.Equal(t, timeSince, *dc.TimeSince) + assert.Equal(t, staleTime, *dc.StaleTime) + assert.Equal(t, domain.CheckStatusLevelCRIT, *dc.Level) + return dc +} + +func validateTC(t *testing.T, check domain.Check, orgID string) *domain.ThresholdCheck { + require.NotNil(t, check) + require.Equal(t, "threshold", check.Type()) + tc := check.(*domain.ThresholdCheck) + require.NotNil(t, tc) + assert.Equal(t, "ThresholdCheck test", tc.Name) + assert.Equal(t, orgID, tc.OrgID) + assert.Equal(t, msg, *tc.StatusMessageTemplate) + assert.Equal(t, flux, *tc.Query.Text) + assert.Equal(t, every, *tc.Every) + assert.Equal(t, offset, *tc.Offset) + assert.Equal(t, domain.TaskStatusTypeActive, tc.Status) + assert.Len(t, *tc.Thresholds, 3) + require.Equal(t, "greater", (*tc.Thresholds)[0].Type()) + gt := (*tc.Thresholds)[0].(*domain.GreaterThreshold) + require.NotNil(t, gt) + assert.Equal(t, float32(10.0), gt.Value) + assert.Equal(t, domain.CheckStatusLevelCRIT, *gt.Level) + assert.Equal(t, true, *gt.AllValues) + require.Equal(t, "lesser", (*tc.Thresholds)[1].Type()) + lt := (*tc.Thresholds)[1].(*domain.LesserThreshold) + require.NotNil(t, lt) + assert.Equal(t, float32(1.0), lt.Value) + assert.Equal(t, domain.CheckStatusLevelOK, *lt.Level) + require.Equal(t, "range", (*tc.Thresholds)[2].Type()) + rt := (*tc.Thresholds)[2].(*domain.RangeThreshold) + require.NotNil(t, rt) + assert.Equal(t, float32(3.0), rt.Min) + assert.Equal(t, float32(8.0), rt.Max) + assert.Equal(t, domain.CheckStatusLevelWARN, *rt.Level) + return tc +} diff --git a/domain/Readme.md b/domain/Readme.md index 8cc8a77..5a2f007 100644 --- a/domain/Readme.md +++ b/domain/Readme.md @@ -16,8 +16,8 @@ to maintain full compatibility with the latest InfluxDB release ## Generate ### Generate types -`oapi-codegen -generate types -o types.gen.go -package domain -templates .\templates oss.yml` +`oapi-codegen -generate types -exclude-tags Checks -o types.gen.go -package domain -templates .\templates oss.yml` ### Generate client -`oapi-codegen -generate client -o client.gen.go -package domain -templates .\templates oss.yml` +`oapi-codegen -generate client -exclude-tags Checks -o client.gen.go -package domain -templates .\templates oss.yml` diff --git a/domain/checks.client.go b/domain/checks.client.go new file mode 100644 index 0000000..e914645 --- /dev/null +++ b/domain/checks.client.go @@ -0,0 +1,762 @@ +// Package domain provides primitives to interact with the openapi HTTP API. +// +// Code generated by version DO NOT EDIT. +package domain + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "github.com/oapi-codegen/runtime" + "io" + "net/http" + "net/url" +) + +var typeToCheck = map[string]func() Check{ + "deadman": func() Check { return &DeadmanCheck{} }, + "threshold": func() Check { return &ThresholdCheck{} }, + "custom": func() Check { return &CustomCheck{} }, +} + +// UnmarshalJSON will convert +func unmarshalCheckJSON(b []byte) (Check, error) { + var raw struct { + Type string `json:"type"` + } + if err := json.Unmarshal(b, &raw); err != nil { + m := "unable to detect the check type from json" + e := &Error{ + Code: ErrorCodeInvalid, + Message: &m, + } + return nil, e.Error() + } + factoryFunc, ok := typeToCheck[raw.Type] + if !ok { + return nil, fmt.Errorf("invalid check type %s", raw.Type) + } + check := factoryFunc() + err := json.Unmarshal(b, check) + return check, err +} + +// GetChecks calls the GET on /checks +// List all checks +func (c *Client) GetChecks(ctx context.Context, params *GetChecksParams) (*Checks, error) { + var err error + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks") + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + queryValues := queryURL.Query() + + if params.Offset != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "offset", runtime.ParamLocationQuery, *params.Offset); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.Limit != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "limit", runtime.ParamLocationQuery, *params.Limit); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "orgID", runtime.ParamLocationQuery, params.OrgID); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + queryURL.RawQuery = queryValues.Encode() + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return nil, err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + type raw struct { + Checks *[]json.RawMessage `json:"checks,omitempty"` + + // URI pointers for additional paged results. + Links *Links `json:"links,omitempty"` + } + response := &Checks{} + + switch rsp.StatusCode { + case 200: + var a raw + if err := unmarshalJSONResponse(bodyBytes, &a); err != nil { + return nil, err + } + if a.Checks != nil && len(*a.Checks) > 0 { + c := make([]Check, len(*a.Checks)) + response.Checks = &c + for i, m := range *a.Checks { + check, err := unmarshalCheckJSON(m) + if err != nil { + return nil, err + } + (*response.Checks)[i] = check + } + } + response.Links = a.Links + default: + return nil, decodeError(bodyBytes, rsp) + } + return response, nil + +} + +// CreateCheck calls the POST on /checks +// Add new check +func (c *Client) CreateCheck(ctx context.Context, params *CreateCheckAllParams) (Check, error) { + var err error + var bodyReader io.Reader + buf, err := json.Marshal(params.Body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks") + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), bodyReader) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", "application/json") + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + switch rsp.StatusCode { + case 201: + check, err := unmarshalCheckJSON(bodyBytes) + if err != nil { + return nil, err + } + return check, nil + default: + return nil, decodeError(bodyBytes, rsp) + } +} + +// DeleteChecksID calls the DELETE on /checks/{checkID} +// Delete a check +func (c *Client) DeleteChecksID(ctx context.Context, params *DeleteChecksIDAllParams) error { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return err + } + + operationPath := fmt.Sprintf("./checks/%s", pathParam0) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return err + } + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return err + } + + defer func() { _ = rsp.Body.Close() }() + + if rsp.StatusCode > 299 { + bodyBytes, err := io.ReadAll(rsp.Body) + if err != nil { + return err + } + return decodeError(bodyBytes, rsp) + } + return nil + +} + +// GetChecksID calls the GET on /checks/{checkID} +// Retrieve a check +func (c *Client) GetChecksID(ctx context.Context, params *GetChecksIDAllParams) (Check, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks/%s", pathParam0) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return nil, err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + switch rsp.StatusCode { + case 200: + check, err := unmarshalCheckJSON(bodyBytes) + if err != nil { + return nil, err + } + return check, nil + default: + return nil, decodeError(bodyBytes, rsp) + } +} + +// PatchChecksID calls the PATCH on /checks/{checkID} +// Update a check +func (c *Client) PatchChecksID(ctx context.Context, params *PatchChecksIDAllParams) (Check, error) { + var err error + var bodyReader io.Reader + buf, err := json.Marshal(params.Body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks/%s", pathParam0) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PATCH", queryURL.String(), bodyReader) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", "application/json") + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return nil, err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + switch rsp.StatusCode { + case 200: + check, err := unmarshalCheckJSON(bodyBytes) + if err != nil { + return nil, err + } + return check, nil + default: + return nil, decodeError(bodyBytes, rsp) + } +} + +// PutChecksID calls the PUT on /checks/{checkID} +// Update a check +func (c *Client) PutChecksID(ctx context.Context, params *PutChecksIDAllParams) (Check, error) { + var err error + var bodyReader io.Reader + buf, err := json.Marshal(params.Body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks/%s", pathParam0) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PUT", queryURL.String(), bodyReader) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", "application/json") + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return nil, err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + switch rsp.StatusCode { + case 200: + check, err := unmarshalCheckJSON(bodyBytes) + if err != nil { + return nil, err + } + return check, nil + default: + return nil, decodeError(bodyBytes, rsp) + } +} + +// GetChecksIDLabels calls the GET on /checks/{checkID}/labels +// List all labels for a check +func (c *Client) GetChecksIDLabels(ctx context.Context, params *GetChecksIDLabelsAllParams) (*LabelsResponse, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks/%s/labels", pathParam0) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return nil, err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &LabelsResponse{} + + switch rsp.StatusCode { + case 200: + if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { + return nil, err + } + default: + return nil, decodeError(bodyBytes, rsp) + } + return response, nil + +} + +// PostChecksIDLabels calls the POST on /checks/{checkID}/labels +// Add a label to a check +func (c *Client) PostChecksIDLabels(ctx context.Context, params *PostChecksIDLabelsAllParams) (*LabelResponse, error) { + var err error + var bodyReader io.Reader + buf, err := json.Marshal(params.Body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks/%s/labels", pathParam0) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), bodyReader) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", "application/json") + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return nil, err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &LabelResponse{} + + switch rsp.StatusCode { + case 201: + if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { + return nil, err + } + default: + return nil, decodeError(bodyBytes, rsp) + } + return response, nil + +} + +// DeleteChecksIDLabelsID calls the DELETE on /checks/{checkID}/labels/{labelID} +// Delete label from a check +func (c *Client) DeleteChecksIDLabelsID(ctx context.Context, params *DeleteChecksIDLabelsIDAllParams) error { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "labelID", runtime.ParamLocationPath, params.LabelID) + if err != nil { + return err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return err + } + + operationPath := fmt.Sprintf("./checks/%s/labels/%s", pathParam0, pathParam1) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return err + } + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return err + } + + defer func() { _ = rsp.Body.Close() }() + + if rsp.StatusCode > 299 { + bodyBytes, err := io.ReadAll(rsp.Body) + if err != nil { + return err + } + return decodeError(bodyBytes, rsp) + } + return nil + +} + +// GetChecksIDQuery calls the GET on /checks/{checkID}/query +// Retrieve a check query +func (c *Client) GetChecksIDQuery(ctx context.Context, params *GetChecksIDQueryAllParams) (*FluxResponse, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(c.APIEndpoint) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("./checks/%s/query", pathParam0) + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + if params.ZapTraceSpan != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) + if err != nil { + return nil, err + } + + req.Header.Set("Zap-Trace-Span", headerParam0) + } + + req = req.WithContext(ctx) + rsp, err := c.Client.Do(req) + if err != nil { + return nil, err + } + bodyBytes, err := io.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &FluxResponse{} + + switch rsp.StatusCode { + case 200: + if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { + return nil, err + } + default: + return nil, decodeError(bodyBytes, rsp) + } + return response, nil + +} diff --git a/domain/checks.types.go b/domain/checks.types.go new file mode 100644 index 0000000..2bbcd89 --- /dev/null +++ b/domain/checks.types.go @@ -0,0 +1,537 @@ +// Package domain provides primitives to interact with the openapi HTTP API. +// +// Code generated by version DO NOT EDIT. +package domain + +import ( + "encoding/json" + "fmt" + "time" +) + +// Defines values for CheckBaseLastRunStatus. +const ( + CheckBaseLastRunStatusCanceled CheckBaseLastRunStatus = "canceled" + + CheckBaseLastRunStatusFailed CheckBaseLastRunStatus = "failed" + + CheckBaseLastRunStatusSuccess CheckBaseLastRunStatus = "success" +) + +// Defines values for CheckPatchStatus. +const ( + CheckPatchStatusActive CheckPatchStatus = "active" + + CheckPatchStatusInactive CheckPatchStatus = "inactive" +) + +// Defines values for CheckStatusLevel. +const ( + CheckStatusLevelCRIT CheckStatusLevel = "CRIT" + + CheckStatusLevelINFO CheckStatusLevel = "INFO" + + CheckStatusLevelOK CheckStatusLevel = "OK" + + CheckStatusLevelUNKNOWN CheckStatusLevel = "UNKNOWN" + + CheckStatusLevelWARN CheckStatusLevel = "WARN" +) + +// Defines values for DeadmanCheckType. +const ( + DeadmanCheckTypeDeadman DeadmanCheckType = "deadman" +) + +// Defines values for ThresholdCheckType. +const ( + ThresholdCheckTypeThreshold ThresholdCheckType = "threshold" +) + +// Defines values for CustomCheckType. +const ( + CustomCheckTypeCustom CustomCheckType = "custom" +) + +// CheckPatch defines model for CheckPatch. +type CheckPatch struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Status *CheckPatchStatus `json:"status,omitempty"` +} + +// CheckPatchStatus defines model for CheckPatch.Status. +type CheckPatchStatus string + +// The state to record if check matches a criteria. +type CheckStatusLevel string + +// CustomCheckType defines model for CustomCheck.Type. +type CustomCheckType string + +// DeadmanCheckType defines model for DeadmanCheck.Type. +type DeadmanCheckType string + +// ThresholdCheckType defines model for ThresholdCheck.Type. +type ThresholdCheckType string + +// CreateCheckJSONRequestBody defines body for CreateCheck for application/json ContentType. +type CreateCheckJSONRequestBody CreateCheckJSONBody + +// PatchChecksIDJSONRequestBody defines body for PatchChecksID for application/json ContentType. +type PatchChecksIDJSONRequestBody PatchChecksIDJSONBody + +// PutChecksIDJSONRequestBody defines body for PutChecksID for application/json ContentType. +type PutChecksIDJSONRequestBody PutChecksIDJSONBody + +// PostChecksIDLabelsJSONRequestBody defines body for PostChecksIDLabels for application/json ContentType. +type PostChecksIDLabelsJSONRequestBody PostChecksIDLabelsJSONBody + +// Check defines model for Check. +type Check interface { + Type() string +} + +// Checks defines model for Checks. +type Checks struct { + Checks *[]Check `json:"checks,omitempty"` + + // URI pointers for additional paged results. + Links *Links `json:"links,omitempty"` +} + +// CheckBase defines model for CheckBase. +type CheckBase struct { + CreatedAt *time.Time `json:"createdAt,omitempty"` + + // An optional description of the check. + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Labels *Labels `json:"labels,omitempty"` + LastRunError *string `json:"lastRunError,omitempty"` + LastRunStatus *CheckBaseLastRunStatus `json:"lastRunStatus,omitempty"` + + // A timestamp ([RFC3339 date/time format](https://docs.influxdata.com/influxdb/v2.3/reference/glossary/#rfc3339-timestamp)) of the latest scheduled and completed run. + LatestCompleted *time.Time `json:"latestCompleted,omitempty"` + Links *struct { + // URI of resource. + Labels *Link `json:"labels,omitempty"` + + // URI of resource. + Members *Link `json:"members,omitempty"` + + // URI of resource. + Owners *Link `json:"owners,omitempty"` + + // URI of resource. + Query *Link `json:"query,omitempty"` + + // URI of resource. + Self *Link `json:"self,omitempty"` + } `json:"links,omitempty"` + Name string `json:"name"` + + // The ID of the organization that owns this check. + OrgID string `json:"orgID"` + + // The ID of creator used to create this check. + OwnerID *string `json:"ownerID,omitempty"` + Query DashboardQuery `json:"query"` + + // `inactive` cancels scheduled runs and prevents manual runs of the task. + Status TaskStatusType `json:"status"` + + // The ID of the task associated with this check. + TaskID *string `json:"taskID,omitempty"` + UpdatedAt *time.Time `json:"updatedAt,omitempty"` +} + +type CheckBaseExtend struct { + CheckBase + // Embedded fields due to inline allOf schema + // Check repetition interval. + Every *string `json:"every,omitempty"` + + // Duration to delay after the schedule, before executing check. + Offset *string `json:"offset,omitempty"` + + // The template used to generate and write a status message. + StatusMessageTemplate *string `json:"statusMessageTemplate,omitempty"` + + // List of tags to write to each status. + Tags *[]struct { + Key *string `json:"key,omitempty"` + Value *string `json:"value,omitempty"` + } `json:"tags,omitempty"` +} + +// DeadmanCheck defines model for DeadmanCheck. +type DeadmanCheck struct { + CheckBaseExtend + // The state to record if check matches a criteria. + Level *CheckStatusLevel `json:"level,omitempty"` + + // If only zero values reported since time, trigger an alert + ReportZero *bool `json:"reportZero,omitempty"` + + // String duration for time that a series is considered stale and should not trigger deadman. + StaleTime *string `json:"staleTime,omitempty"` + + // String duration before deadman triggers. + TimeSince *string `json:"timeSince,omitempty"` +} + +func (d DeadmanCheck) Type() string { + return string(DeadmanCheckTypeDeadman) +} + +// MarshalJSON implement json.Marshaler interface. +func (d DeadmanCheck) MarshalJSON() ([]byte, error) { + type deadmanCheckAlias DeadmanCheck + return json.Marshal( + struct { + deadmanCheckAlias + Type string `json:"type"` + }{ + deadmanCheckAlias: deadmanCheckAlias(d), + Type: d.Type(), + }) +} + +// ThresholdCheck defines model for ThresholdCheck. +type ThresholdCheck struct { + // Embedded struct due to allOf(#/components/schemas/CheckBase) + CheckBaseExtend + Thresholds *[]Threshold `json:"thresholds,omitempty"` +} + +// MarshalJSON implement json.Marshaler interface. +func (t *ThresholdCheck) MarshalJSON() ([]byte, error) { + type thresholdCheckAlias ThresholdCheck + return json.Marshal( + struct { + thresholdCheckAlias + Type string `json:"type"` + }{ + thresholdCheckAlias: thresholdCheckAlias(*t), + Type: t.Type(), + }) +} + +type thresholdCheckDecode struct { + CheckBaseExtend + Thresholds []thresholdDecode `json:"thresholds"` +} + +type thresholdDecode struct { + ThresholdBase + Type string `json:"type"` + Value float32 `json:"value"` + Min float32 `json:"min"` + Max float32 `json:"max"` + Within bool `json:"within"` +} + +// UnmarshalJSON implement json.Unmarshaler interface. +func (t *ThresholdCheck) UnmarshalJSON(b []byte) error { + var tdRaws thresholdCheckDecode + if err := json.Unmarshal(b, &tdRaws); err != nil { + return err + } + t.CheckBaseExtend = tdRaws.CheckBaseExtend + a := make([]Threshold, 0, len(tdRaws.Thresholds)) + t.Thresholds = &a + for _, tdRaw := range tdRaws.Thresholds { + switch tdRaw.Type { + case "lesser": + td := &LesserThreshold{ + ThresholdBase: tdRaw.ThresholdBase, + Value: tdRaw.Value, + } + *t.Thresholds = append(*t.Thresholds, td) + case "greater": + td := &GreaterThreshold{ + ThresholdBase: tdRaw.ThresholdBase, + Value: tdRaw.Value, + } + *t.Thresholds = append(*t.Thresholds, td) + case "range": + td := &RangeThreshold{ + ThresholdBase: tdRaw.ThresholdBase, + Min: tdRaw.Min, + Max: tdRaw.Max, + Within: tdRaw.Within, + } + *t.Thresholds = append(*t.Thresholds, td) + default: + return fmt.Errorf("invalid threshold type %s", tdRaw.Type) + } + } + return nil +} + +func (t ThresholdCheck) Type() string { + return string(ThresholdCheckTypeThreshold) +} + +// Threshold defines model for Threshold. +type Threshold interface { + Type() string +} + +// ThresholdBase defines model for ThresholdBase. +type ThresholdBase struct { + // If true, only alert if all values meet threshold. + AllValues *bool `json:"allValues,omitempty"` + + // The state to record if check matches a criteria. + Level *CheckStatusLevel `json:"level,omitempty"` +} + +// LesserThreshold defines model for LesserThreshold. +type LesserThreshold struct { + // Embedded struct due to allOf(#/components/schemas/ThresholdBase) + ThresholdBase + // Embedded fields due to inline allOf schema + Typ LesserThresholdType `json:"type"` + Value float32 `json:"value"` +} + +func (t LesserThreshold) Type() string { + return string(LesserThresholdTypeLesser) +} + +// MarshalJSON implement json.Marshaler interface. +func (t LesserThreshold) MarshalJSON() ([]byte, error) { + type lesserThresholdAlias LesserThreshold + return json.Marshal( + struct { + lesserThresholdAlias + Type string `json:"type"` + }{ + lesserThresholdAlias: lesserThresholdAlias(t), + Type: t.Type(), + }) +} + +// GreaterThreshold defines model for GreaterThreshold. +type GreaterThreshold struct { + // Embedded struct due to allOf(#/components/schemas/ThresholdBase) + ThresholdBase + // Embedded fields due to inline allOf schema + Typ GreaterThresholdType `json:"type"` + Value float32 `json:"value"` +} + +func (t GreaterThreshold) Type() string { + return string(GreaterThresholdTypeGreater) +} + +// MarshalJSON implement json.Marshaler interface. +func (t GreaterThreshold) MarshalJSON() ([]byte, error) { + type greaterThresholdAlias GreaterThreshold + return json.Marshal( + struct { + greaterThresholdAlias + Type string `json:"type"` + }{ + greaterThresholdAlias: greaterThresholdAlias(t), + Type: t.Type(), + }) +} + +// RangeThreshold defines model for RangeThreshold. +type RangeThreshold struct { + // Embedded struct due to allOf(#/components/schemas/ThresholdBase) + ThresholdBase + // Embedded fields due to inline allOf schema + Max float32 `json:"max"` + Min float32 `json:"min"` + Typ RangeThresholdType `json:"type"` + Within bool `json:"within"` +} + +func (r RangeThreshold) Type() string { + return string(RangeThresholdTypeRange) +} + +// MarshalJSON implement json.Marshaler interface. +func (r RangeThreshold) MarshalJSON() ([]byte, error) { + type rangeThresholdAlias RangeThreshold + return json.Marshal( + struct { + rangeThresholdAlias + Type string `json:"type"` + }{ + rangeThresholdAlias: rangeThresholdAlias(r), + Type: r.Type(), + }) +} + +// CustomCheck defines model for CustomCheck. +type CustomCheck struct { + // Embedded struct due to allOf(#/components/schemas/CheckBase) + CheckBase +} + +func (c CustomCheck) Type() string { + return string(CustomCheckTypeCustom) +} + +// MarshalJSON implement json.Marshaler interface. +func (c CustomCheck) MarshalJSON() ([]byte, error) { + type customCheckAlias CustomCheck + return json.Marshal( + struct { + customCheckAlias + Type string `json:"type"` + }{ + customCheckAlias: customCheckAlias(c), + Type: c.Type(), + }) +} + +// GetChecksParams defines parameters for GetChecks. +type GetChecksParams struct { + // The offset for pagination. + // The number of records to skip. + Offset *Offset `json:"offset,omitempty"` + + // Limits the number of records returned. Default is `20`. + Limit *Limit `json:"limit,omitempty"` + + // Only show checks that belong to a specific organization ID. + OrgID string `json:"orgID"` + + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// CreateCheckJSONBody defines parameters for CreateCheck. +type CreateCheckJSONBody Check + +// CreateCheckAllParams defines type for all parameters for CreateCheck. +type CreateCheckAllParams struct { + Body CreateCheckJSONRequestBody +} + +// DeleteChecksIDParams defines parameters for DeleteChecksID. +type DeleteChecksIDParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// DeleteChecksIDAllParams defines type for all parameters for DeleteChecksID. +type DeleteChecksIDAllParams struct { + DeleteChecksIDParams + + CheckID string +} + +// GetChecksIDParams defines parameters for GetChecksID. +type GetChecksIDParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// GetChecksIDAllParams defines type for all parameters for GetChecksID. +type GetChecksIDAllParams struct { + GetChecksIDParams + + CheckID string +} + +// PatchChecksIDJSONBody defines parameters for PatchChecksID. +type PatchChecksIDJSONBody CheckPatch + +// PatchChecksIDParams defines parameters for PatchChecksID. +type PatchChecksIDParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// PatchChecksIDAllParams defines type for all parameters for PatchChecksID. +type PatchChecksIDAllParams struct { + PatchChecksIDParams + + CheckID string + + Body PatchChecksIDJSONRequestBody +} + +// PutChecksIDJSONBody defines parameters for PutChecksID. +type PutChecksIDJSONBody Check + +// PutChecksIDParams defines parameters for PutChecksID. +type PutChecksIDParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// PutChecksIDAllParams defines type for all parameters for PutChecksID. +type PutChecksIDAllParams struct { + PutChecksIDParams + + CheckID string + + Body PutChecksIDJSONRequestBody +} + +// GetChecksIDLabelsParams defines parameters for GetChecksIDLabels. +type GetChecksIDLabelsParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// GetChecksIDLabelsAllParams defines type for all parameters for GetChecksIDLabels. +type GetChecksIDLabelsAllParams struct { + GetChecksIDLabelsParams + + CheckID string +} + +// PostChecksIDLabelsJSONBody defines parameters for PostChecksIDLabels. +type PostChecksIDLabelsJSONBody LabelMapping + +// PostChecksIDLabelsParams defines parameters for PostChecksIDLabels. +type PostChecksIDLabelsParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// PostChecksIDLabelsAllParams defines type for all parameters for PostChecksIDLabels. +type PostChecksIDLabelsAllParams struct { + PostChecksIDLabelsParams + + CheckID string + + Body PostChecksIDLabelsJSONRequestBody +} + +// DeleteChecksIDLabelsIDParams defines parameters for DeleteChecksIDLabelsID. +type DeleteChecksIDLabelsIDParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// DeleteChecksIDLabelsIDAllParams defines type for all parameters for DeleteChecksIDLabelsID. +type DeleteChecksIDLabelsIDAllParams struct { + DeleteChecksIDLabelsIDParams + + CheckID string + + LabelID string +} + +// GetChecksIDQueryParams defines parameters for GetChecksIDQuery. +type GetChecksIDQueryParams struct { + // OpenTracing span context + ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` +} + +// GetChecksIDQueryAllParams defines type for all parameters for GetChecksIDQuery. +type GetChecksIDQueryAllParams struct { + GetChecksIDQueryParams + + CheckID string +} diff --git a/domain/client.gen.go b/domain/client.gen.go index 12e0d79..9b08c79 100644 --- a/domain/client.gen.go +++ b/domain/client.gen.go @@ -1558,714 +1558,6 @@ func (c *Client) DeleteBucketsIDOwnersID(ctx context.Context, params *DeleteBuck } -// GetChecks calls the GET on /checks -// List all checks -func (c *Client) GetChecks(ctx context.Context, params *GetChecksParams) (*Checks, error) { - var err error - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks") - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - queryValues := queryURL.Query() - - if params.Offset != nil { - - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "offset", runtime.ParamLocationQuery, *params.Offset); err != nil { - return nil, err - } else if parsed, err := url.ParseQuery(queryFrag); err != nil { - return nil, err - } else { - for k, v := range parsed { - for _, v2 := range v { - queryValues.Add(k, v2) - } - } - } - - } - - if params.Limit != nil { - - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "limit", runtime.ParamLocationQuery, *params.Limit); err != nil { - return nil, err - } else if parsed, err := url.ParseQuery(queryFrag); err != nil { - return nil, err - } else { - for k, v := range parsed { - for _, v2 := range v { - queryValues.Add(k, v2) - } - } - } - - } - - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "orgID", runtime.ParamLocationQuery, params.OrgID); err != nil { - return nil, err - } else if parsed, err := url.ParseQuery(queryFrag); err != nil { - return nil, err - } else { - for k, v := range parsed { - for _, v2 := range v { - queryValues.Add(k, v2) - } - } - } - - queryURL.RawQuery = queryValues.Encode() - - req, err := http.NewRequest("GET", queryURL.String(), nil) - if err != nil { - return nil, err - } - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return nil, err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &Checks{} - - switch rsp.StatusCode { - case 200: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - -// CreateCheck calls the POST on /checks -// Add new check -func (c *Client) CreateCheck(ctx context.Context, params *CreateCheckAllParams) (*Check, error) { - var err error - var bodyReader io.Reader - buf, err := json.Marshal(params.Body) - if err != nil { - return nil, err - } - bodyReader = bytes.NewReader(buf) - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks") - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", queryURL.String(), bodyReader) - if err != nil { - return nil, err - } - - req.Header.Add("Content-Type", "application/json") - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &Check{} - - switch rsp.StatusCode { - case 201: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - -// DeleteChecksID calls the DELETE on /checks/{checkID} -// Delete a check -func (c *Client) DeleteChecksID(ctx context.Context, params *DeleteChecksIDAllParams) error { - var err error - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return err - } - - operationPath := fmt.Sprintf("./checks/%s", pathParam0) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return err - } - - req, err := http.NewRequest("DELETE", queryURL.String(), nil) - if err != nil { - return err - } - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return err - } - - defer func() { _ = rsp.Body.Close() }() - - if rsp.StatusCode > 299 { - bodyBytes, err := io.ReadAll(rsp.Body) - if err != nil { - return err - } - return decodeError(bodyBytes, rsp) - } - return nil - -} - -// GetChecksID calls the GET on /checks/{checkID} -// Retrieve a check -func (c *Client) GetChecksID(ctx context.Context, params *GetChecksIDAllParams) (*Check, error) { - var err error - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks/%s", pathParam0) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("GET", queryURL.String(), nil) - if err != nil { - return nil, err - } - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return nil, err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &Check{} - - switch rsp.StatusCode { - case 200: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - -// PatchChecksID calls the PATCH on /checks/{checkID} -// Update a check -func (c *Client) PatchChecksID(ctx context.Context, params *PatchChecksIDAllParams) (*Check, error) { - var err error - var bodyReader io.Reader - buf, err := json.Marshal(params.Body) - if err != nil { - return nil, err - } - bodyReader = bytes.NewReader(buf) - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks/%s", pathParam0) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("PATCH", queryURL.String(), bodyReader) - if err != nil { - return nil, err - } - - req.Header.Add("Content-Type", "application/json") - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return nil, err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &Check{} - - switch rsp.StatusCode { - case 200: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - -// PutChecksID calls the PUT on /checks/{checkID} -// Update a check -func (c *Client) PutChecksID(ctx context.Context, params *PutChecksIDAllParams) (*Check, error) { - var err error - var bodyReader io.Reader - buf, err := json.Marshal(params.Body) - if err != nil { - return nil, err - } - bodyReader = bytes.NewReader(buf) - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks/%s", pathParam0) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("PUT", queryURL.String(), bodyReader) - if err != nil { - return nil, err - } - - req.Header.Add("Content-Type", "application/json") - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return nil, err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &Check{} - - switch rsp.StatusCode { - case 200: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - -// GetChecksIDLabels calls the GET on /checks/{checkID}/labels -// List all labels for a check -func (c *Client) GetChecksIDLabels(ctx context.Context, params *GetChecksIDLabelsAllParams) (*LabelsResponse, error) { - var err error - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks/%s/labels", pathParam0) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("GET", queryURL.String(), nil) - if err != nil { - return nil, err - } - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return nil, err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &LabelsResponse{} - - switch rsp.StatusCode { - case 200: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - -// PostChecksIDLabels calls the POST on /checks/{checkID}/labels -// Add a label to a check -func (c *Client) PostChecksIDLabels(ctx context.Context, params *PostChecksIDLabelsAllParams) (*LabelResponse, error) { - var err error - var bodyReader io.Reader - buf, err := json.Marshal(params.Body) - if err != nil { - return nil, err - } - bodyReader = bytes.NewReader(buf) - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks/%s/labels", pathParam0) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", queryURL.String(), bodyReader) - if err != nil { - return nil, err - } - - req.Header.Add("Content-Type", "application/json") - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return nil, err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &LabelResponse{} - - switch rsp.StatusCode { - case 201: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - -// DeleteChecksIDLabelsID calls the DELETE on /checks/{checkID}/labels/{labelID} -// Delete label from a check -func (c *Client) DeleteChecksIDLabelsID(ctx context.Context, params *DeleteChecksIDLabelsIDAllParams) error { - var err error - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return err - } - - var pathParam1 string - - pathParam1, err = runtime.StyleParamWithLocation("simple", false, "labelID", runtime.ParamLocationPath, params.LabelID) - if err != nil { - return err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return err - } - - operationPath := fmt.Sprintf("./checks/%s/labels/%s", pathParam0, pathParam1) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return err - } - - req, err := http.NewRequest("DELETE", queryURL.String(), nil) - if err != nil { - return err - } - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return err - } - - defer func() { _ = rsp.Body.Close() }() - - if rsp.StatusCode > 299 { - bodyBytes, err := io.ReadAll(rsp.Body) - if err != nil { - return err - } - return decodeError(bodyBytes, rsp) - } - return nil - -} - -// GetChecksIDQuery calls the GET on /checks/{checkID}/query -// Retrieve a check query -func (c *Client) GetChecksIDQuery(ctx context.Context, params *GetChecksIDQueryAllParams) (*FluxResponse, error) { - var err error - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "checkID", runtime.ParamLocationPath, params.CheckID) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(c.APIEndpoint) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("./checks/%s/query", pathParam0) - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("GET", queryURL.String(), nil) - if err != nil { - return nil, err - } - - if params.ZapTraceSpan != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Zap-Trace-Span", runtime.ParamLocationHeader, *params.ZapTraceSpan) - if err != nil { - return nil, err - } - - req.Header.Set("Zap-Trace-Span", headerParam0) - } - - req = req.WithContext(ctx) - rsp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - bodyBytes, err := io.ReadAll(rsp.Body) - - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &FluxResponse{} - - switch rsp.StatusCode { - case 200: - if err := unmarshalJSONResponse(bodyBytes, &response); err != nil { - return nil, err - } - default: - return nil, decodeError(bodyBytes, rsp) - } - return response, nil - -} - // GetConfig calls the GET on /config // Retrieve runtime configuration func (c *Client) GetConfig(ctx context.Context, params *GetConfigParams) (*Config, error) { diff --git a/domain/types.gen.go b/domain/types.gen.go index d8b1ca3..0a8928c 100644 --- a/domain/types.gen.go +++ b/domain/types.gen.go @@ -72,35 +72,6 @@ const ( BuilderAggregateFunctionTypeGroup BuilderAggregateFunctionType = "group" ) -// Defines values for CheckBaseLastRunStatus. -const ( - CheckBaseLastRunStatusCanceled CheckBaseLastRunStatus = "canceled" - - CheckBaseLastRunStatusFailed CheckBaseLastRunStatus = "failed" - - CheckBaseLastRunStatusSuccess CheckBaseLastRunStatus = "success" -) - -// Defines values for CheckPatchStatus. -const ( - CheckPatchStatusActive CheckPatchStatus = "active" - - CheckPatchStatusInactive CheckPatchStatus = "inactive" -) - -// Defines values for CheckStatusLevel. -const ( - CheckStatusLevelCRIT CheckStatusLevel = "CRIT" - - CheckStatusLevelINFO CheckStatusLevel = "INFO" - - CheckStatusLevelOK CheckStatusLevel = "OK" - - CheckStatusLevelUNKNOWN CheckStatusLevel = "UNKNOWN" - - CheckStatusLevelWARN CheckStatusLevel = "WARN" -) - // Defines values for CheckViewPropertiesShape. const ( CheckViewPropertiesShapeChronografV2 CheckViewPropertiesShape = "chronograf-v2" @@ -116,11 +87,6 @@ const ( ConstantVariablePropertiesTypeConstant ConstantVariablePropertiesType = "constant" ) -// Defines values for CustomCheckType. -const ( - CustomCheckTypeCustom CustomCheckType = "custom" -) - // Defines values for DashboardColorType. const ( DashboardColorTypeBackground DashboardColorType = "background" @@ -136,11 +102,6 @@ const ( DashboardColorTypeThreshold DashboardColorType = "threshold" ) -// Defines values for DeadmanCheckType. -const ( - DeadmanCheckTypeDeadman DeadmanCheckType = "deadman" -) - // Defines values for DialectAnnotations. const ( DialectAnnotationsDatatype DialectAnnotations = "datatype" @@ -726,11 +687,6 @@ const ( TemplateKindVariable TemplateKind = "Variable" ) -// Defines values for ThresholdCheckType. -const ( - ThresholdCheckTypeThreshold ThresholdCheckType = "threshold" -) - // Defines values for UserStatus. const ( UserStatusActive UserStatus = "active" @@ -1194,77 +1150,9 @@ type Cells []Cell // CellsWithViewProperties defines model for CellsWithViewProperties. type CellsWithViewProperties []CellWithViewProperties -// Check defines model for Check. -type Check struct { - // Embedded struct due to allOf(#/components/schemas/CheckDiscriminator) - CheckDiscriminator `yaml:",inline"` -} - -// CheckBase defines model for CheckBase. -type CheckBase struct { - CreatedAt *time.Time `json:"createdAt,omitempty"` - - // An optional description of the check. - Description *string `json:"description,omitempty"` - Id *string `json:"id,omitempty"` - Labels *Labels `json:"labels,omitempty"` - LastRunError *string `json:"lastRunError,omitempty"` - LastRunStatus *CheckBaseLastRunStatus `json:"lastRunStatus,omitempty"` - - // A timestamp ([RFC3339 date/time format](https://docs.influxdata.com/influxdb/v2.3/reference/glossary/#rfc3339-timestamp)) of the latest scheduled and completed run. - LatestCompleted *time.Time `json:"latestCompleted,omitempty"` - Links *struct { - // URI of resource. - Labels *Link `json:"labels,omitempty"` - - // URI of resource. - Members *Link `json:"members,omitempty"` - - // URI of resource. - Owners *Link `json:"owners,omitempty"` - - // URI of resource. - Query *Link `json:"query,omitempty"` - - // URI of resource. - Self *Link `json:"self,omitempty"` - } `json:"links,omitempty"` - Name string `json:"name"` - - // The ID of the organization that owns this check. - OrgID string `json:"orgID"` - - // The ID of creator used to create this check. - OwnerID *string `json:"ownerID,omitempty"` - Query DashboardQuery `json:"query"` - - // `inactive` cancels scheduled runs and prevents manual runs of the task. - Status *TaskStatusType `json:"status,omitempty"` - - // The ID of the task associated with this check. - TaskID *string `json:"taskID,omitempty"` - UpdatedAt *time.Time `json:"updatedAt,omitempty"` -} - // CheckBaseLastRunStatus defines model for CheckBase.LastRunStatus. type CheckBaseLastRunStatus string -// CheckDiscriminator defines model for CheckDiscriminator. -type CheckDiscriminator interface{} - -// CheckPatch defines model for CheckPatch. -type CheckPatch struct { - Description *string `json:"description,omitempty"` - Name *string `json:"name,omitempty"` - Status *CheckPatchStatus `json:"status,omitempty"` -} - -// CheckPatchStatus defines model for CheckPatch.Status. -type CheckPatchStatus string - -// The state to record if check matches a criteria. -type CheckStatusLevel string - // CheckViewProperties defines model for CheckViewProperties. type CheckViewProperties struct { AdaptiveZoomHide *bool `json:"adaptiveZoomHide,omitempty"` @@ -1288,14 +1176,6 @@ type CheckViewPropertiesShape string // CheckViewPropertiesType defines model for CheckViewProperties.Type. type CheckViewPropertiesType string -// Checks defines model for Checks. -type Checks struct { - Checks *[]Check `json:"checks,omitempty"` - - // URI pointers for additional paged results. - Links *Links `json:"links,omitempty"` -} - // A color mapping is an object that maps time series data to a UI color scheme to allow the UI to render graphs consistent colors across reloads. type ColorMapping struct { AdditionalProperties map[string]string `json:"-"` @@ -1349,17 +1229,6 @@ type CreateDashboardRequest struct { OrgID string `json:"orgID"` } -// CustomCheck defines model for CustomCheck. -type CustomCheck struct { - // Embedded struct due to allOf(#/components/schemas/CheckBase) - CheckBase `yaml:",inline"` - // Embedded fields due to inline allOf schema - Type CustomCheckType `json:"type"` -} - -// CustomCheckType defines model for CustomCheck.Type. -type CustomCheckType string - // DBRP defines model for DBRP. type DBRP struct { // The ID of the bucket used as the target for the translation. @@ -1538,43 +1407,6 @@ type DateTimeLiteral struct { Value *time.Time `json:"value,omitempty"` } -// DeadmanCheck defines model for DeadmanCheck. -type DeadmanCheck struct { - // Embedded struct due to allOf(#/components/schemas/CheckBase) - CheckBase `yaml:",inline"` - // Embedded fields due to inline allOf schema - // Check repetition interval. - Every *string `json:"every,omitempty"` - - // The state to record if check matches a criteria. - Level *CheckStatusLevel `json:"level,omitempty"` - - // Duration to delay after the schedule, before executing check. - Offset *string `json:"offset,omitempty"` - - // If only zero values reported since time, trigger an alert - ReportZero *bool `json:"reportZero,omitempty"` - - // String duration for time that a series is considered stale and should not trigger deadman. - StaleTime *string `json:"staleTime,omitempty"` - - // The template used to generate and write a status message. - StatusMessageTemplate *string `json:"statusMessageTemplate,omitempty"` - - // List of tags to write to each status. - Tags *[]struct { - Key *string `json:"key,omitempty"` - Value *string `json:"value,omitempty"` - } `json:"tags,omitempty"` - - // String duration before deadman triggers. - TimeSince *string `json:"timeSince,omitempty"` - Type DeadmanCheckType `json:"type"` -} - -// DeadmanCheckType defines model for DeadmanCheck.Type. -type DeadmanCheckType string - // Indicates whether decimal places should be enforced, and how many digits it should show. type DecimalPlaces struct { // The number of digits after decimal to display @@ -1962,15 +1794,6 @@ type GeoViewPropertiesShape string // GeoViewPropertiesType defines model for GeoViewProperties.Type. type GeoViewPropertiesType string -// GreaterThreshold defines model for GreaterThreshold. -type GreaterThreshold struct { - // Embedded struct due to allOf(#/components/schemas/ThresholdBase) - ThresholdBase `yaml:",inline"` - // Embedded fields due to inline allOf schema - Type GreaterThresholdType `json:"type"` - Value float32 `json:"value"` -} - // GreaterThresholdType defines model for GreaterThreshold.Type. type GreaterThresholdType string @@ -2249,15 +2072,6 @@ type LatLonColumns struct { Lon LatLonColumn `json:"lon"` } -// LesserThreshold defines model for LesserThreshold. -type LesserThreshold struct { - // Embedded struct due to allOf(#/components/schemas/ThresholdBase) - ThresholdBase `yaml:",inline"` - // Embedded fields due to inline allOf schema - Type LesserThresholdType `json:"type"` - Value float32 `json:"value"` -} - // LesserThresholdType defines model for LesserThreshold.Type. type LesserThresholdType string @@ -2916,12 +2730,6 @@ type PostBucketRequest struct { SchemaType *SchemaType `json:"schemaType,omitempty"` } -// PostCheck defines model for PostCheck. -type PostCheck struct { - // Embedded struct due to allOf(#/components/schemas/CheckDiscriminator) - CheckDiscriminator `yaml:",inline"` -} - // PostNotificationEndpoint defines model for PostNotificationEndpoint. type PostNotificationEndpoint struct { // Embedded struct due to allOf(#/components/schemas/NotificationEndpointDiscriminator) @@ -3007,16 +2815,20 @@ type QueryType string // To use parameters in your query, pass a _`query`_ with `params` references (in dot notation)--for example: // // ```json -// query: "from(bucket: params.mybucket) |> range(start: params.rangeStart) |> limit(n:1)" +// +// query: "from(bucket: params.mybucket) |> range(start: params.rangeStart) |> limit(n:1)" +// // ``` // // and pass _`params`_ with the key-value pairs--for example: // // ```json -// params: { -// "mybucket": "environment", -// "rangeStart": "-30d" -// } +// +// params: { +// "mybucket": "environment", +// "rangeStart": "-30d" +// } +// // ``` // // During query execution, InfluxDB passes _`params`_ to your script and substitutes the values. @@ -3043,17 +2855,6 @@ type QueryVariableProperties struct { // QueryVariablePropertiesType defines model for QueryVariableProperties.Type. type QueryVariablePropertiesType string -// RangeThreshold defines model for RangeThreshold. -type RangeThreshold struct { - // Embedded struct due to allOf(#/components/schemas/ThresholdBase) - ThresholdBase `yaml:",inline"` - // Embedded fields due to inline allOf schema - Max float32 `json:"max"` - Min float32 `json:"min"` - Type RangeThresholdType `json:"type"` - Within bool `json:"within"` -} - // RangeThresholdType defines model for RangeThreshold.Type. type RangeThresholdType string @@ -4242,33 +4043,33 @@ type TemplateApply_EnvRefs struct { // the following Flux script retrieves `POSTGRES_USERNAME` and `POSTGRES_PASSWORD` // secrets and then uses them to connect to a PostgreSQL database: // -// ```js -// import "sql" -// import "influxdata/influxdb/secrets" +// ```js +// import "sql" +// import "influxdata/influxdb/secrets" // -// username = secrets.get(key: "POSTGRES_USERNAME") -// password = secrets.get(key: "POSTGRES_PASSWORD") +// username = secrets.get(key: "POSTGRES_USERNAME") +// password = secrets.get(key: "POSTGRES_PASSWORD") // -// sql.from( -// driverName: "postgres", -// dataSourceName: "postgresql://${username}:${password}@localhost:5432", -// query: "SELECT * FROM example_table", -// ) -// ``` +// sql.from( +// driverName: "postgres", +// dataSourceName: "postgresql://${username}:${password}@localhost:5432", +// query: "SELECT * FROM example_table", +// ) +// ``` // // To define secret values in your `/api/v2/templates/apply` request, // pass the `secrets` parameter with key-value pairs--for example: // -// ```json -// { -// ... -// "secrets": { -// "POSTGRES_USERNAME": "pguser", -// "POSTGRES_PASSWORD": "foo" -// } -// ... -// } -// ``` +// ```json +// { +// ... +// "secrets": { +// "POSTGRES_USERNAME": "pguser", +// "POSTGRES_PASSWORD": "foo" +// } +// ... +// } +// ``` // // InfluxDB stores the key-value pairs as secrets that you can access with `secrets.get()`. // Once stored, you can't view secret values in InfluxDB. @@ -4380,12 +4181,12 @@ type TemplateSummary struct { TemplateMetaName *string `json:"templateMetaName,omitempty"` } `json:"buckets,omitempty"` Checks *[]struct { - Id *string `json:"id,omitempty"` - Kind *TemplateKind `json:"kind,omitempty"` - New *CheckDiscriminator `json:"new,omitempty"` - Old *CheckDiscriminator `json:"old,omitempty"` - StateStatus *string `json:"stateStatus,omitempty"` - TemplateMetaName *string `json:"templateMetaName,omitempty"` + Id *string `json:"id,omitempty"` + Kind *TemplateKind `json:"kind,omitempty"` + New *Check `json:"new,omitempty"` + Old *Check `json:"old,omitempty"` + StateStatus *string `json:"stateStatus,omitempty"` + TemplateMetaName *string `json:"templateMetaName,omitempty"` } `json:"checks,omitempty"` Dashboards *[]struct { Id *string `json:"id,omitempty"` @@ -4554,7 +4355,7 @@ type TemplateSummary struct { } `json:"buckets,omitempty"` Checks *[]struct { // Embedded struct due to allOf(#/components/schemas/CheckDiscriminator) - CheckDiscriminator `yaml:",inline"` + Check // Embedded fields due to inline allOf schema EnvReferences *TemplateEnvReferences `json:"envReferences,omitempty"` Kind *TemplateKind `json:"kind,omitempty"` @@ -4677,44 +4478,6 @@ type TestStatement struct { Type *NodeType `json:"type,omitempty"` } -// Threshold defines model for Threshold. -type Threshold interface{} - -// ThresholdBase defines model for ThresholdBase. -type ThresholdBase struct { - // If true, only alert if all values meet threshold. - AllValues *bool `json:"allValues,omitempty"` - - // The state to record if check matches a criteria. - Level *CheckStatusLevel `json:"level,omitempty"` -} - -// ThresholdCheck defines model for ThresholdCheck. -type ThresholdCheck struct { - // Embedded struct due to allOf(#/components/schemas/CheckBase) - CheckBase `yaml:",inline"` - // Embedded fields due to inline allOf schema - // Check repetition interval. - Every *string `json:"every,omitempty"` - - // Duration to delay after the schedule, before executing check. - Offset *string `json:"offset,omitempty"` - - // The template used to generate and write a status message. - StatusMessageTemplate *string `json:"statusMessageTemplate,omitempty"` - - // List of tags to write to each status. - Tags *[]struct { - Key *string `json:"key,omitempty"` - Value *string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Thresholds *[]Threshold `json:"thresholds,omitempty"` - Type ThresholdCheckType `json:"type"` -} - -// ThresholdCheckType defines model for ThresholdCheck.Type. -type ThresholdCheckType string - // Uses operators to act on a single operand in an expression type UnaryExpression struct { Argument *Expression `json:"argument,omitempty"` @@ -5250,151 +5013,6 @@ type DeleteBucketsIDOwnersIDAllParams struct { UserID string } -// GetChecksParams defines parameters for GetChecks. -type GetChecksParams struct { - // The offset for pagination. - // The number of records to skip. - Offset *Offset `json:"offset,omitempty"` - - // Limits the number of records returned. Default is `20`. - Limit *Limit `json:"limit,omitempty"` - - // Only show checks that belong to a specific organization ID. - OrgID string `json:"orgID"` - - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// CreateCheckJSONBody defines parameters for CreateCheck. -type CreateCheckJSONBody PostCheck - -// CreateCheckAllParams defines type for all parameters for CreateCheck. -type CreateCheckAllParams struct { - Body CreateCheckJSONRequestBody -} - -// DeleteChecksIDParams defines parameters for DeleteChecksID. -type DeleteChecksIDParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// DeleteChecksIDAllParams defines type for all parameters for DeleteChecksID. -type DeleteChecksIDAllParams struct { - DeleteChecksIDParams - - CheckID string -} - -// GetChecksIDParams defines parameters for GetChecksID. -type GetChecksIDParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// GetChecksIDAllParams defines type for all parameters for GetChecksID. -type GetChecksIDAllParams struct { - GetChecksIDParams - - CheckID string -} - -// PatchChecksIDJSONBody defines parameters for PatchChecksID. -type PatchChecksIDJSONBody CheckPatch - -// PatchChecksIDParams defines parameters for PatchChecksID. -type PatchChecksIDParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// PatchChecksIDAllParams defines type for all parameters for PatchChecksID. -type PatchChecksIDAllParams struct { - PatchChecksIDParams - - CheckID string - - Body PatchChecksIDJSONRequestBody -} - -// PutChecksIDJSONBody defines parameters for PutChecksID. -type PutChecksIDJSONBody Check - -// PutChecksIDParams defines parameters for PutChecksID. -type PutChecksIDParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// PutChecksIDAllParams defines type for all parameters for PutChecksID. -type PutChecksIDAllParams struct { - PutChecksIDParams - - CheckID string - - Body PutChecksIDJSONRequestBody -} - -// GetChecksIDLabelsParams defines parameters for GetChecksIDLabels. -type GetChecksIDLabelsParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// GetChecksIDLabelsAllParams defines type for all parameters for GetChecksIDLabels. -type GetChecksIDLabelsAllParams struct { - GetChecksIDLabelsParams - - CheckID string -} - -// PostChecksIDLabelsJSONBody defines parameters for PostChecksIDLabels. -type PostChecksIDLabelsJSONBody LabelMapping - -// PostChecksIDLabelsParams defines parameters for PostChecksIDLabels. -type PostChecksIDLabelsParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// PostChecksIDLabelsAllParams defines type for all parameters for PostChecksIDLabels. -type PostChecksIDLabelsAllParams struct { - PostChecksIDLabelsParams - - CheckID string - - Body PostChecksIDLabelsJSONRequestBody -} - -// DeleteChecksIDLabelsIDParams defines parameters for DeleteChecksIDLabelsID. -type DeleteChecksIDLabelsIDParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// DeleteChecksIDLabelsIDAllParams defines type for all parameters for DeleteChecksIDLabelsID. -type DeleteChecksIDLabelsIDAllParams struct { - DeleteChecksIDLabelsIDParams - - CheckID string - - LabelID string -} - -// GetChecksIDQueryParams defines parameters for GetChecksIDQuery. -type GetChecksIDQueryParams struct { - // OpenTracing span context - ZapTraceSpan *TraceSpan `json:"Zap-Trace-Span,omitempty"` -} - -// GetChecksIDQueryAllParams defines type for all parameters for GetChecksIDQuery. -type GetChecksIDQueryAllParams struct { - GetChecksIDQueryParams - - CheckID string -} - // GetConfigParams defines parameters for GetConfig. type GetConfigParams struct { // OpenTracing span context @@ -8016,18 +7634,6 @@ type PostBucketsIDMembersJSONRequestBody PostBucketsIDMembersJSONBody // PostBucketsIDOwnersJSONRequestBody defines body for PostBucketsIDOwners for application/json ContentType. type PostBucketsIDOwnersJSONRequestBody PostBucketsIDOwnersJSONBody -// CreateCheckJSONRequestBody defines body for CreateCheck for application/json ContentType. -type CreateCheckJSONRequestBody CreateCheckJSONBody - -// PatchChecksIDJSONRequestBody defines body for PatchChecksID for application/json ContentType. -type PatchChecksIDJSONRequestBody PatchChecksIDJSONBody - -// PutChecksIDJSONRequestBody defines body for PutChecksID for application/json ContentType. -type PutChecksIDJSONRequestBody PutChecksIDJSONBody - -// PostChecksIDLabelsJSONRequestBody defines body for PostChecksIDLabels for application/json ContentType. -type PostChecksIDLabelsJSONRequestBody PostChecksIDLabelsJSONBody - // PatchDashboardsIDJSONRequestBody defines body for PatchDashboardsID for application/json ContentType. type PatchDashboardsIDJSONRequestBody PatchDashboardsIDJSONBody diff --git a/examples_test.go b/examples_test.go index 5b67fe2..554fd66 100644 --- a/examples_test.go +++ b/examples_test.go @@ -7,7 +7,6 @@ package influxdb2_test import ( "context" "fmt" - "github.com/influxdata/influxdb-client-go/v2" "github.com/influxdata/influxdb-client-go/v2/domain" ) @@ -77,3 +76,77 @@ func ExampleClient_customServerAPICall() { fmt.Printf("Created DBRP: %#v\n", newDbrp) } + +func ExampleClient_checkAPICall() { + // This example shows how to perform custom server API invocation for checks API + + // Create client. You need an admin token for creating DBRP mapping + client := influxdb2.NewClient("http://localhost:8086", "my-token") + + // Always close client at the end + defer client.Close() + + ctx := context.Background() + + // Create a new threshold check + greater := domain.GreaterThreshold{} + greater.Value = 10.0 + lc := domain.CheckStatusLevelCRIT + greater.Level = &lc + greater.AllValues = &[]bool{true}[0] + + lesser := domain.LesserThreshold{} + lesser.Value = 1.0 + lo := domain.CheckStatusLevelOK + lesser.Level = &lo + + rang := domain.RangeThreshold{} + rang.Min = 3.0 + rang.Max = 8.0 + lw := domain.CheckStatusLevelWARN + rang.Level = &lw + + thresholds := []domain.Threshold{&greater, &lesser, &rang} + + // Get organization where check will be created + org, err := client.OrganizationsAPI().FindOrganizationByName(ctx, "my-org") + if err != nil { + panic(err) + } + + // Prepare necessary parameters + msg := "Check: ${ r._check_name } is: ${ r._level }" + flux := `from(bucket: "foo") |> range(start: -1d, stop: now()) |> aggregateWindow(every: 1m, fn: mean) |> filter(fn: (r) => r._field == "usage_user") |> yield()` + every := "1h" + offset := "0s" + + c := domain.ThresholdCheck{ + CheckBaseExtend: domain.CheckBaseExtend{ + CheckBase: domain.CheckBase{ + Name: "My threshold check", + OrgID: *org.Id, + Query: domain.DashboardQuery{Text: &flux}, + Status: domain.TaskStatusTypeActive, + }, + Every: &every, + Offset: &offset, + StatusMessageTemplate: &msg, + }, + Thresholds: &thresholds, + } + params := domain.CreateCheckAllParams{ + Body: &c, + } + // Call checks API using internal API client + check, err := client.APIClient().CreateCheck(context.Background(), ¶ms) + if err != nil { + panic(err) + } + // Optionally verify type + if check.Type() != string(domain.ThresholdCheckTypeThreshold) { + panic("Check type is not threshold") + } + // Cast check to threshold check + thresholdCheck := check.(*domain.ThresholdCheck) + fmt.Printf("Created threshold check with id %s\n", *thresholdCheck.Id) +}