mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Vendoring dependencies
This commit is contained in:
2
vendor/github.com/zorkian/go-datadog-api/.gitignore
generated
vendored
Normal file
2
vendor/github.com/zorkian/go-datadog-api/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.sublime*
|
||||
cmd
|
||||
26
vendor/github.com/zorkian/go-datadog-api/.travis.yml
generated
vendored
Normal file
26
vendor/github.com/zorkian/go-datadog-api/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- "1.9"
|
||||
- "1.10.x"
|
||||
- "1.11.x"
|
||||
- "tip"
|
||||
|
||||
env:
|
||||
- "PATH=/home/travis/gopath/bin:$PATH"
|
||||
|
||||
install:
|
||||
- go get -v -t .
|
||||
|
||||
script:
|
||||
- scripts/check-fmt.sh
|
||||
- go get -u golang.org/x/lint/golint
|
||||
- golint ./... | grep -v vendor/
|
||||
- make
|
||||
- scripts/check-code-generation-ran.sh
|
||||
# PR's don't have access to Travis EnvVars with DDog API Keys. Skip acceptance tests on PR.
|
||||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then make testacc; fi'
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- go: tip
|
||||
30
vendor/github.com/zorkian/go-datadog-api/LICENSE
generated
vendored
Normal file
30
vendor/github.com/zorkian/go-datadog-api/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
Copyright (c) 2013 by authors and contributors.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the <organization> nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER>
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.
|
||||
36
vendor/github.com/zorkian/go-datadog-api/Makefile
generated
vendored
Normal file
36
vendor/github.com/zorkian/go-datadog-api/Makefile
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
TEST?=$$(go list ./... | grep -v '/go-datadog-api/vendor/')
|
||||
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
|
||||
|
||||
default: test fmt
|
||||
|
||||
generate:
|
||||
go generate
|
||||
|
||||
# test runs the unit tests and vets the code
|
||||
test:
|
||||
go test . $(TESTARGS) -v -timeout=30s -parallel=4
|
||||
@$(MAKE) vet
|
||||
|
||||
# testacc runs acceptance tests
|
||||
testacc:
|
||||
go test integration/* -v $(TESTARGS) -timeout 90m
|
||||
|
||||
# testrace runs the race checker
|
||||
testrace:
|
||||
go test -race $(TEST) $(TESTARGS)
|
||||
|
||||
fmt:
|
||||
gofmt -w $(GOFMT_FILES)
|
||||
|
||||
# vet runs the Go source code static analysis tool `vet` to find
|
||||
# any common errors.
|
||||
vet:
|
||||
@echo "go vet"
|
||||
@go vet; if [ $$? -ne 0 ]; then \
|
||||
echo ""; \
|
||||
echo "Vet found suspicious constructs. Please check the reported constructs"; \
|
||||
echo "and fix them if necessary before submitting the code for review."; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
.PHONY: default test testacc updatedeps vet
|
||||
120
vendor/github.com/zorkian/go-datadog-api/README.md
generated
vendored
Normal file
120
vendor/github.com/zorkian/go-datadog-api/README.md
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
[](https://godoc.org/gopkg.in/zorkian/go-datadog-api.v2)
|
||||
[](https://opensource.org/licenses/BSD-3-Clause)
|
||||
[](https://travis-ci.org/zorkian/go-datadog-api)
|
||||
[](https://goreportcard.com/report/github.com/zorkian/go-datadog-api)
|
||||
|
||||
# Datadog API in Go
|
||||
|
||||
**This is the v2.0 version of the API, and has breaking changes. Use the v1.0 branch if you need
|
||||
legacy code to be supported.**
|
||||
|
||||
A Go wrapper for the Datadog API. Use this library if you need to interact
|
||||
with the Datadog system. You can post metrics with it if you want, but this library is probably
|
||||
mostly used for automating dashboards/alerting and retrieving data (events, etc).
|
||||
|
||||
The source API documentation is here: <http://docs.datadoghq.com/api/>
|
||||
|
||||
## Installation
|
||||
To use the default branch, include it in your code like:
|
||||
```go
|
||||
import "github.com/zorkian/go-datadog-api"
|
||||
```
|
||||
|
||||
Or, if you need to control which version to use, import using [gopkg.in](http://labix.org/gopkg.in). Like so:
|
||||
```go
|
||||
import "gopkg.in/zorkian/go-datadog-api.v2"
|
||||
```
|
||||
|
||||
Using go get:
|
||||
```bash
|
||||
go get gopkg.in/zorkian/go-datadog-api.v2
|
||||
```
|
||||
|
||||
## USAGE
|
||||
This library uses pointers to be able to verify if values are set or not (vs the default value for the type). Like
|
||||
protobuf there are helpers to enhance the API. You can decide to not use them, but you'll have to be careful handling
|
||||
nil pointers.
|
||||
|
||||
Using the client:
|
||||
```go
|
||||
client := datadog.NewClient("api key", "application key")
|
||||
|
||||
dash, err := client.GetDashboard(*datadog.Int(10880))
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: %s\n", err)
|
||||
}
|
||||
|
||||
log.Printf("dashboard %d: %s\n", dash.GetId(), dash.GetTitle())
|
||||
```
|
||||
|
||||
An example using datadog.String(), which allocates a pointer for you:
|
||||
```go
|
||||
m := datadog.Monitor{
|
||||
Name: datadog.String("Monitor other things"),
|
||||
Creator: &datadog.Creator{
|
||||
Name: datadog.String("Joe Creator"),
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
An example using the SetXx, HasXx, GetXx and GetXxOk accessors:
|
||||
```go
|
||||
m := datadog.Monitor{}
|
||||
m.SetName("Monitor all the things")
|
||||
m.SetMessage("Electromagnetic energy loss")
|
||||
|
||||
// Use HasMessage(), to verify we have interest in the message.
|
||||
// Using GetMessage() always safe as it returns the actual or, if never set, default value for that type.
|
||||
if m.HasMessage() {
|
||||
fmt.Printf("Found message %s\n", m.GetMessage())
|
||||
}
|
||||
|
||||
// Alternatively, use GetMessageOk(), it returns a tuple with the (default) value and a boolean expressing
|
||||
// if it was set at all:
|
||||
if v, ok := m.GetMessageOk(); ok {
|
||||
fmt.Printf("Found message %s\n", v)
|
||||
}
|
||||
```
|
||||
|
||||
Check out the Godoc link for the available API methods and, if you can't find the one you need,
|
||||
let us know (or patches welcome)!
|
||||
|
||||
## DOCUMENTATION
|
||||
|
||||
Please see: <https://godoc.org/gopkg.in/zorkian/go-datadog-api.v2>
|
||||
|
||||
## BUGS/PROBLEMS/CONTRIBUTING
|
||||
|
||||
There are certainly some, but presently no known major bugs. If you do
|
||||
find something that doesn't work as expected, please file an issue on
|
||||
Github:
|
||||
|
||||
<https://github.com/zorkian/go-datadog-api/issues>
|
||||
|
||||
Thanks in advance! And, as always, patches welcome!
|
||||
|
||||
## DEVELOPMENT
|
||||
### Running tests
|
||||
* Run tests tests with `make test`.
|
||||
* Integration tests can be run with `make testacc`. Run specific integration tests with `make testacc TESTARGS='-run=TestCreateAndDeleteMonitor'`
|
||||
|
||||
The acceptance tests require _DATADOG_API_KEY_ and _DATADOG_APP_KEY_ to be available
|
||||
in your environment variables.
|
||||
|
||||
*Warning: the integrations tests will create and remove real resources in your Datadog account.*
|
||||
|
||||
### Regenerating code
|
||||
Accessors `HasXx`, `GetXx`, `GetOkXx` and `SetXx` are generated for each struct field type type that contains pointers.
|
||||
When structs are updated a contributor has to regenerate these using `go generate` and commit these changes.
|
||||
Optionally there is a make target for the generation:
|
||||
|
||||
```bash
|
||||
make generate
|
||||
```
|
||||
|
||||
## COPYRIGHT AND LICENSE
|
||||
|
||||
Please see the LICENSE file for the included license information.
|
||||
|
||||
Copyright 2013-2019 by authors and contributors.
|
||||
82
vendor/github.com/zorkian/go-datadog-api/alerts.go
generated
vendored
Normal file
82
vendor/github.com/zorkian/go-datadog-api/alerts.go
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Alert represents the data of an alert: a query that can fire and send a
|
||||
// message to the users.
|
||||
type Alert struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Creator *int `json:"creator,omitempty"`
|
||||
Query *string `json:"query,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
Silenced *bool `json:"silenced,omitempty"`
|
||||
NotifyNoData *bool `json:"notify_no_data,omitempty"`
|
||||
State *string `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
// reqAlerts receives a slice of all alerts.
|
||||
type reqAlerts struct {
|
||||
Alerts []Alert `json:"alerts,omitempty"`
|
||||
}
|
||||
|
||||
// CreateAlert adds a new alert to the system. This returns a pointer to an
|
||||
// Alert so you can pass that to UpdateAlert later if needed.
|
||||
func (client *Client) CreateAlert(alert *Alert) (*Alert, error) {
|
||||
var out Alert
|
||||
if err := client.doJsonRequest("POST", "/v1/alert", alert, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// UpdateAlert takes an alert that was previously retrieved through some method
|
||||
// and sends it back to the server.
|
||||
func (client *Client) UpdateAlert(alert *Alert) error {
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/alert/%d", alert.Id),
|
||||
alert, nil)
|
||||
}
|
||||
|
||||
// GetAlert retrieves an alert by identifier.
|
||||
func (client *Client) GetAlert(id int) (*Alert, error) {
|
||||
var out Alert
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/alert/%d", id), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// DeleteAlert removes an alert from the system.
|
||||
func (client *Client) DeleteAlert(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/alert/%d", id),
|
||||
nil, nil)
|
||||
}
|
||||
|
||||
// GetAlerts returns a slice of all alerts.
|
||||
func (client *Client) GetAlerts() ([]Alert, error) {
|
||||
var out reqAlerts
|
||||
if err := client.doJsonRequest("GET", "/v1/alert", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Alerts, nil
|
||||
}
|
||||
|
||||
// MuteAlerts turns off alerting notifications.
|
||||
func (client *Client) MuteAlerts() error {
|
||||
return client.doJsonRequest("POST", "/v1/mute_alerts", nil, nil)
|
||||
}
|
||||
|
||||
// UnmuteAlerts turns on alerting notifications.
|
||||
func (client *Client) UnmuteAlerts() error {
|
||||
return client.doJsonRequest("POST", "/v1/unmute_alerts", nil, nil)
|
||||
}
|
||||
122
vendor/github.com/zorkian/go-datadog-api/api_keys.go
generated
vendored
Normal file
122
vendor/github.com/zorkian/go-datadog-api/api_keys.go
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2019 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var createdTimeLayout = "2006-01-02 15:04:05"
|
||||
|
||||
// APIKey represents and API key
|
||||
type APIKey struct {
|
||||
CreatedBy *string `json:"created_by,omitempty"`
|
||||
Name *string `json:"name,omitemtpy"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
Created *time.Time `json:"created,omitempty"`
|
||||
}
|
||||
|
||||
// reqAPIKeys retrieves a slice of all APIKeys.
|
||||
type reqAPIKeys struct {
|
||||
APIKeys []APIKey `json:"api_keys,omitempty"`
|
||||
}
|
||||
|
||||
// reqAPIKey is similar to reqAPIKeys, but used for values returned by /v1/api_key/<somekey>
|
||||
// which contain one object (not list) "api_key" (not "api_keys") containing the found key
|
||||
type reqAPIKey struct {
|
||||
APIKey *APIKey `json:"api_key"`
|
||||
}
|
||||
|
||||
// MarshalJSON is a custom method for handling datetime marshalling
|
||||
func (k APIKey) MarshalJSON() ([]byte, error) {
|
||||
// Approach for custom (un)marshalling borrowed from http://choly.ca/post/go-json-marshalling/
|
||||
type Alias APIKey
|
||||
return json.Marshal(&struct {
|
||||
Created *string `json:"created,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
Created: String(k.Created.Format(createdTimeLayout)),
|
||||
Alias: (*Alias)(&k),
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON is a custom method for handling datetime unmarshalling
|
||||
func (k *APIKey) UnmarshalJSON(data []byte) error {
|
||||
type Alias APIKey
|
||||
aux := &struct {
|
||||
Created *string `json:"created,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(k),
|
||||
}
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if created, err := time.Parse(createdTimeLayout, *aux.Created); err != nil {
|
||||
return err
|
||||
} else {
|
||||
k.Created = &created
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAPIKeys returns all API keys or error on failure
|
||||
func (client *Client) GetAPIKeys() ([]APIKey, error) {
|
||||
var out reqAPIKeys
|
||||
if err := client.doJsonRequest("GET", "/v1/api_key", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return out.APIKeys, nil
|
||||
}
|
||||
|
||||
// GetAPIKey returns a single API key or error on failure
|
||||
func (client *Client) GetAPIKey(key string) (*APIKey, error) {
|
||||
var out reqAPIKey
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/api_key/%s", key), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return out.APIKey, nil
|
||||
}
|
||||
|
||||
// CreateAPIKey creates an API key from given struct and fills the rest of its
|
||||
// fields, or returns an error on failure
|
||||
func (client *Client) CreateAPIKey(name string) (*APIKey, error) {
|
||||
toPost := struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
}{
|
||||
&name,
|
||||
}
|
||||
var out reqAPIKey
|
||||
if err := client.doJsonRequest("POST", "/v1/api_key", toPost, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.APIKey, nil
|
||||
}
|
||||
|
||||
// UpdateAPIKey updates given API key (only Name can be updated), returns an error
|
||||
func (client *Client) UpdateAPIKey(apikey *APIKey) error {
|
||||
out := reqAPIKey{APIKey: apikey}
|
||||
toPost := struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
}{
|
||||
apikey.Name,
|
||||
}
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/api_key/%s", *apikey.Key), toPost, &out)
|
||||
}
|
||||
|
||||
// DeleteAPIKey deletes API key given by key, returns an error
|
||||
func (client *Client) DeleteAPIKey(key string) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/api_key/%s", key), nil, nil)
|
||||
}
|
||||
720
vendor/github.com/zorkian/go-datadog-api/board_widgets.go
generated
vendored
Normal file
720
vendor/github.com/zorkian/go-datadog-api/board_widgets.go
generated
vendored
Normal file
@@ -0,0 +1,720 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2019 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
ALERT_GRAPH_WIDGET = "alert_graph"
|
||||
ALERT_VALUE_WIDGET = "alert_value"
|
||||
CHANGE_WIDGET = "change"
|
||||
CHECK_STATUS_WIDGET = "check_status"
|
||||
DISTRIBUTION_WIDGET = "distribution"
|
||||
EVENT_STREAM_WIDGET = "event_stream"
|
||||
EVENT_TIMELINE_WIDGET = "event_timeline"
|
||||
FREE_TEXT_WIDGET = "free_text"
|
||||
GROUP_WIDGET = "group"
|
||||
HEATMAP_WIDGET = "heatmap"
|
||||
HOSTMAP_WIDGET = "hostmap"
|
||||
IFRAME_WIDGET = "iframe"
|
||||
IMAGE_WIDGET = "image"
|
||||
LOG_STREAM_WIDGET = "log_stream"
|
||||
MANAGE_STATUS_WIDGET = "manage_status"
|
||||
NOTE_WIDGET = "note"
|
||||
QUERY_VALUE_WIDGET = "query_value"
|
||||
SCATTERPLOT_WIDGET = "scatterplot"
|
||||
TIMESERIES_WIDGET = "timeseries"
|
||||
TOPLIST_WIDGET = "toplist"
|
||||
TRACE_SERVICE_WIDGET = "trace_service"
|
||||
)
|
||||
|
||||
// BoardWidget represents the structure of any widget. However, the widget Definition structure is
|
||||
// different according to widget type.
|
||||
type BoardWidget struct {
|
||||
Definition interface{} `json:"definition"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Layout *WidgetLayout `json:"layout,omitempty"`
|
||||
}
|
||||
|
||||
// WidgetLayout represents the layout for a widget on a "free" dashboard
|
||||
type WidgetLayout struct {
|
||||
X *float64 `json:"x,omitempty"`
|
||||
Y *float64 `json:"y,omitempty"`
|
||||
Height *float64 `json:"height,omitempty"`
|
||||
Width *float64 `json:"width,omitempty"`
|
||||
}
|
||||
|
||||
func (widget *BoardWidget) GetWidgetType() (string, error) {
|
||||
switch widget.Definition.(type) {
|
||||
case AlertGraphDefinition:
|
||||
return ALERT_GRAPH_WIDGET, nil
|
||||
case AlertValueDefinition:
|
||||
return ALERT_VALUE_WIDGET, nil
|
||||
case ChangeDefinition:
|
||||
return CHANGE_WIDGET, nil
|
||||
case CheckStatusDefinition:
|
||||
return CHECK_STATUS_WIDGET, nil
|
||||
case DistributionDefinition:
|
||||
return DISTRIBUTION_WIDGET, nil
|
||||
case EventStreamDefinition:
|
||||
return EVENT_STREAM_WIDGET, nil
|
||||
case EventTimelineDefinition:
|
||||
return EVENT_TIMELINE_WIDGET, nil
|
||||
case FreeTextDefinition:
|
||||
return FREE_TEXT_WIDGET, nil
|
||||
case GroupDefinition:
|
||||
return GROUP_WIDGET, nil
|
||||
case HeatmapDefinition:
|
||||
return HEATMAP_WIDGET, nil
|
||||
case HostmapDefinition:
|
||||
return HOSTMAP_WIDGET, nil
|
||||
case IframeDefinition:
|
||||
return IFRAME_WIDGET, nil
|
||||
case ImageDefinition:
|
||||
return IMAGE_WIDGET, nil
|
||||
case LogStreamDefinition:
|
||||
return LOG_STREAM_WIDGET, nil
|
||||
case ManageStatusDefinition:
|
||||
return MANAGE_STATUS_WIDGET, nil
|
||||
case NoteDefinition:
|
||||
return NOTE_WIDGET, nil
|
||||
case QueryValueDefinition:
|
||||
return QUERY_VALUE_WIDGET, nil
|
||||
case ScatterplotDefinition:
|
||||
return SCATTERPLOT_WIDGET, nil
|
||||
case TimeseriesDefinition:
|
||||
return TIMESERIES_WIDGET, nil
|
||||
case ToplistDefinition:
|
||||
return TOPLIST_WIDGET, nil
|
||||
case TraceServiceDefinition:
|
||||
return TRACE_SERVICE_WIDGET, nil
|
||||
default:
|
||||
return "", fmt.Errorf("Unsupported widget type")
|
||||
}
|
||||
}
|
||||
|
||||
// AlertGraphDefinition represents the definition for an Alert Graph widget
|
||||
type AlertGraphDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
AlertId *string `json:"alert_id"`
|
||||
VizType *string `json:"viz_type"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
|
||||
// AlertValueDefinition represents the definition for an Alert Value widget
|
||||
type AlertValueDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
AlertId *string `json:"alert_id"`
|
||||
Precision *int `json:"precision,omitempty"`
|
||||
Unit *string `json:"unit,omitempty"`
|
||||
TextAlign *string `json:"text_align,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
}
|
||||
|
||||
// ChangeDefinition represents the definition for a Change widget
|
||||
type ChangeDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests []ChangeRequest `json:"requests"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
type ChangeRequest struct {
|
||||
ChangeType *string `json:"change_type,omitempty"`
|
||||
CompareTo *string `json:"compare_to,omitempty"`
|
||||
IncreaseGood *bool `json:"increase_good,omitempty"`
|
||||
OrderBy *string `json:"order_by,omitempty"`
|
||||
OrderDir *string `json:"order_dir,omitempty"`
|
||||
ShowPresent *bool `json:"show_present,omitempty"`
|
||||
// A ChangeRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
|
||||
// CheckStatusDefinition represents the definition for a Check Status widget
|
||||
type CheckStatusDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Check *string `json:"check"`
|
||||
Grouping *string `json:"grouping"`
|
||||
Group *string `json:"group,omitempty"`
|
||||
GroupBy []string `json:"group_by,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
|
||||
// DistributionDefinition represents the definition for a Distribution widget
|
||||
type DistributionDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests []DistributionRequest `json:"requests"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
type DistributionRequest struct {
|
||||
Style *WidgetRequestStyle `json:"style,omitempty"`
|
||||
// A DistributionRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
|
||||
// EventStreamDefinition represents the definition for an Event Stream widget
|
||||
type EventStreamDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Query *string `json:"query"`
|
||||
EventSize *string `json:"event_size,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
|
||||
// EventTimelineDefinition represents the definition for an Event Timeline widget
|
||||
type EventTimelineDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Query *string `json:"query"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
|
||||
// FreeTextDefinition represents the definition for a Free Text widget
|
||||
type FreeTextDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Text *string `json:"text"`
|
||||
Color *string `json:"color,omitempty"`
|
||||
FontSize *string `json:"font_size,omitempty"`
|
||||
TextAlign *string `json:"text_align,omitempty"`
|
||||
}
|
||||
|
||||
// GroupDefinition represents the definition for an Group widget
|
||||
type GroupDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
LayoutType *string `json:"layout_type"`
|
||||
Widgets []BoardWidget `json:"widgets"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
// HeatmapDefinition represents the definition for a Heatmap widget
|
||||
type HeatmapDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests []HeatmapRequest `json:"requests"`
|
||||
Yaxis *WidgetAxis `json:"yaxis,omitempty"`
|
||||
Events []WidgetEvent `json:"events,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
type HeatmapRequest struct {
|
||||
Style *WidgetRequestStyle `json:"style,omitempty"`
|
||||
// A HeatmapRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
|
||||
// HostmapDefinition represents the definition for a Heatmap widget
|
||||
type HostmapDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests *HostmapRequests `json:"requests"`
|
||||
NodeType *string `json:"node_type,omitempty"`
|
||||
NoMetricHosts *bool `json:"no_metric_hosts,omitempty"`
|
||||
NoGroupHosts *bool `json:"no_group_hosts,omitempty"`
|
||||
Group []string `json:"group,omitempty"`
|
||||
Scope []string `json:"scope,omitempty"`
|
||||
Style *HostmapStyle `json:"style,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
}
|
||||
type HostmapRequests struct {
|
||||
Fill *HostmapRequest `json:"fill,omitempty"`
|
||||
Size *HostmapRequest `json:"size,omitempty"`
|
||||
}
|
||||
type HostmapRequest struct {
|
||||
// A HostmapRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
type HostmapStyle struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
PaletteFlip *bool `json:"palette_flip,omitempty"`
|
||||
FillMin *string `json:"fill_min,omitempty"`
|
||||
FillMax *string `json:"fill_max,omitempty"`
|
||||
}
|
||||
|
||||
// IframeDefinition represents the definition for an Iframe widget
|
||||
type IframeDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Url *string `json:"url"`
|
||||
}
|
||||
|
||||
// ImageDefinition represents the definition for an Image widget
|
||||
type ImageDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Url *string `json:"url"`
|
||||
Sizing *string `json:"sizing,omitempty"`
|
||||
Margin *string `json:"margin,omitempty"`
|
||||
}
|
||||
|
||||
// LogStreamDefinition represents the definition for a Log Stream widget
|
||||
type LogStreamDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Logset *string `json:"logset"`
|
||||
Query *string `json:"query,omitempty"`
|
||||
Columns []string `json:"columns,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
|
||||
// ManageStatusDefinition represents the definition for a Manage Status widget
|
||||
type ManageStatusDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Query *string `json:"query"`
|
||||
Sort *string `json:"sort,omitempty"`
|
||||
Count *int `json:"count,omitempty"`
|
||||
Start *int `json:"start,omitempty"`
|
||||
DisplayFormat *string `json:"display_format,omitempty"`
|
||||
ColorPreference *string `json:"color_preference,omitempty"`
|
||||
HideZeroCounts *bool `json:"hide_zero_counts,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
}
|
||||
|
||||
// NoteDefinition represents the definition for a Note widget
|
||||
type NoteDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Content *string `json:"content"`
|
||||
BackgroundColor *string `json:"background_color,omitempty"`
|
||||
FontSize *string `json:"font_size,omitempty"`
|
||||
TextAlign *string `json:"text_align,omitempty"`
|
||||
ShowTick *bool `json:"show_tick,omitempty"`
|
||||
TickPos *string `json:"tick_pos,omitempty"`
|
||||
TickEdge *string `json:"tick_edge,omitempty"`
|
||||
}
|
||||
|
||||
// QueryValueDefinition represents the definition for a Query Value widget
|
||||
type QueryValueDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests []QueryValueRequest `json:"requests"`
|
||||
Autoscale *bool `json:"autoscale,omitempty"`
|
||||
CustomUnit *string `json:"custom_unit,omitempty"`
|
||||
Precision *int `json:"precision,omitempty"`
|
||||
TextAlign *string `json:"text_align,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
type QueryValueRequest struct {
|
||||
ConditionalFormats []WidgetConditionalFormat `json:"conditional_formats,omitempty"`
|
||||
Aggregator *string `json:"aggregator,omitempty"`
|
||||
// A QueryValueRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
|
||||
// ScatterplotDefinition represents the definition for a Heatmap widget
|
||||
type ScatterplotDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests *ScatterplotRequests `json:"requests"`
|
||||
Xaxis *WidgetAxis `json:"xaxis,omitempty"`
|
||||
Yaxis *WidgetAxis `json:"yaxis,omitempty"`
|
||||
ColorByGroups []string `json:"color_by_groups,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
type ScatterplotRequests struct {
|
||||
X *ScatterplotRequest `json:"x"`
|
||||
Y *ScatterplotRequest `json:"y"`
|
||||
}
|
||||
type ScatterplotRequest struct {
|
||||
Aggregator *string `json:"aggregator,omitempty"`
|
||||
// A ScatterplotRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
|
||||
// TimeseriesDefinition represents the definition for a Timeseries widget
|
||||
type TimeseriesDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests []TimeseriesRequest `json:"requests"`
|
||||
Yaxis *WidgetAxis `json:"yaxis,omitempty"`
|
||||
Events []WidgetEvent `json:"events,omitempty"`
|
||||
Markers []WidgetMarker `json:"markers,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
ShowLegend *bool `json:"show_legend,omitempty"`
|
||||
LegendSize *string `json:"legend_size,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
type TimeseriesRequest struct {
|
||||
Style *TimeseriesRequestStyle `json:"style,omitempty"`
|
||||
Metadata []WidgetMetadata `json:"metadata,omitempty"`
|
||||
DisplayType *string `json:"display_type,omitempty"`
|
||||
// A TimeseriesRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
type TimeseriesRequestStyle struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
LineType *string `json:"line_type,omitempty"`
|
||||
LineWidth *string `json:"line_width,omitempty"`
|
||||
}
|
||||
|
||||
// ToplistDefinition represents the definition for a Distribution widget
|
||||
type ToplistDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Requests []ToplistRequest `json:"requests"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
type ToplistRequest struct {
|
||||
ConditionalFormats []WidgetConditionalFormat `json:"conditional_formats,omitempty"`
|
||||
Style *WidgetRequestStyle `json:"style,omitempty"`
|
||||
// A ToplistRequest should implement exactly one of the following query types
|
||||
MetricQuery *string `json:"q,omitempty"`
|
||||
ApmQuery *WidgetApmOrLogQuery `json:"apm_query,omitempty"`
|
||||
LogQuery *WidgetApmOrLogQuery `json:"log_query,omitempty"`
|
||||
ProcessQuery *WidgetProcessQuery `json:"process_query,omitempty"`
|
||||
}
|
||||
|
||||
// TraceServiceDefinition represents the definition for a Trace Service widget
|
||||
type TraceServiceDefinition struct {
|
||||
Type *string `json:"type"`
|
||||
Env *string `json:"env"`
|
||||
Service *string `json:"service"`
|
||||
SpanName *string `json:"span_name"`
|
||||
ShowHits *bool `json:"show_hits,omitempty"`
|
||||
ShowErrors *bool `json:"show_errors,omitempty"`
|
||||
ShowLatency *bool `json:"show_latency,omitempty"`
|
||||
ShowBreakdown *bool `json:"show_breakdown,omitempty"`
|
||||
ShowDistribution *bool `json:"show_distribution,omitempty"`
|
||||
ShowResourceList *bool `json:"show_resource_list,omitempty"`
|
||||
SizeFormat *string `json:"size_format,omitempty"`
|
||||
DisplayFormat *string `json:"display_format,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
TitleSize *string `json:"title_size,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
Time *WidgetTime `json:"time,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON is a Custom Unmarshal for BoardWidget. If first tries to unmarshal the data in a light
|
||||
// struct that allows to get the widget type. Then based on the widget type, it will try to unmarshal the
|
||||
// data using the corresponding widget struct.
|
||||
func (widget *BoardWidget) UnmarshalJSON(data []byte) error {
|
||||
var widgetHandler struct {
|
||||
Definition *struct {
|
||||
Type *string `json:"type"`
|
||||
} `json:"definition"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Layout *WidgetLayout `json:"layout,omitempty"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &widgetHandler); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the widget id
|
||||
widget.Id = widgetHandler.Id
|
||||
|
||||
// Get the widget layout
|
||||
widget.Layout = widgetHandler.Layout
|
||||
|
||||
// Get the widget definition based on the widget type
|
||||
switch *widgetHandler.Definition.Type {
|
||||
case ALERT_GRAPH_WIDGET:
|
||||
var alertGraphWidget struct {
|
||||
Definition AlertGraphDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &alertGraphWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = alertGraphWidget.Definition
|
||||
case ALERT_VALUE_WIDGET:
|
||||
var alertValueWidget struct {
|
||||
Definition AlertValueDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &alertValueWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = alertValueWidget.Definition
|
||||
case CHANGE_WIDGET:
|
||||
var changeWidget struct {
|
||||
Definition ChangeDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &changeWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = changeWidget.Definition
|
||||
case CHECK_STATUS_WIDGET:
|
||||
var checkStatusWidget struct {
|
||||
Definition CheckStatusDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &checkStatusWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = checkStatusWidget.Definition
|
||||
case DISTRIBUTION_WIDGET:
|
||||
var distributionWidget struct {
|
||||
Definition DistributionDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &distributionWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = distributionWidget.Definition
|
||||
case EVENT_STREAM_WIDGET:
|
||||
var eventStreamWidget struct {
|
||||
Definition EventStreamDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &eventStreamWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = eventStreamWidget.Definition
|
||||
case EVENT_TIMELINE_WIDGET:
|
||||
var eventTimelineWidget struct {
|
||||
Definition EventTimelineDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &eventTimelineWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = eventTimelineWidget.Definition
|
||||
case FREE_TEXT_WIDGET:
|
||||
var freeTextWidget struct {
|
||||
Definition FreeTextDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &freeTextWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = freeTextWidget.Definition
|
||||
case GROUP_WIDGET:
|
||||
var groupWidget struct {
|
||||
Definition GroupDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &groupWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = groupWidget.Definition
|
||||
case HEATMAP_WIDGET:
|
||||
var heatmapWidget struct {
|
||||
Definition HeatmapDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &heatmapWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = heatmapWidget.Definition
|
||||
case HOSTMAP_WIDGET:
|
||||
var hostmapWidget struct {
|
||||
Definition HostmapDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &hostmapWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = hostmapWidget.Definition
|
||||
case IFRAME_WIDGET:
|
||||
var iframeWidget struct {
|
||||
Definition IframeDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &iframeWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = iframeWidget.Definition
|
||||
case IMAGE_WIDGET:
|
||||
var imageWidget struct {
|
||||
Definition ImageDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &imageWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = imageWidget.Definition
|
||||
case LOG_STREAM_WIDGET:
|
||||
var logStreamWidget struct {
|
||||
Definition LogStreamDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &logStreamWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = logStreamWidget.Definition
|
||||
case MANAGE_STATUS_WIDGET:
|
||||
var manageStatusWidget struct {
|
||||
Definition ManageStatusDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &manageStatusWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = manageStatusWidget.Definition
|
||||
case NOTE_WIDGET:
|
||||
var noteWidget struct {
|
||||
Definition NoteDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, ¬eWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = noteWidget.Definition
|
||||
case QUERY_VALUE_WIDGET:
|
||||
var queryValueWidget struct {
|
||||
Definition QueryValueDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &queryValueWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = queryValueWidget.Definition
|
||||
case SCATTERPLOT_WIDGET:
|
||||
var scatterplotWidget struct {
|
||||
Definition ScatterplotDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &scatterplotWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = scatterplotWidget.Definition
|
||||
case TIMESERIES_WIDGET:
|
||||
var timeseriesWidget struct {
|
||||
Definition TimeseriesDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, ×eriesWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = timeseriesWidget.Definition
|
||||
case TOPLIST_WIDGET:
|
||||
var toplistWidget struct {
|
||||
Definition ToplistDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &toplistWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = toplistWidget.Definition
|
||||
case TRACE_SERVICE_WIDGET:
|
||||
var traceServiceWidget struct {
|
||||
Definition TraceServiceDefinition `json:"definition"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &traceServiceWidget); err != nil {
|
||||
return err
|
||||
}
|
||||
widget.Definition = traceServiceWidget.Definition
|
||||
default:
|
||||
return fmt.Errorf("Cannot unmarshal widget of type: %s", *widgetHandler.Definition.Type)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//
|
||||
// List of structs common to multiple widget definitions
|
||||
//
|
||||
|
||||
type WidgetTime struct {
|
||||
LiveSpan *string `json:"live_span,omitempty"`
|
||||
}
|
||||
|
||||
type WidgetAxis struct {
|
||||
Label *string `json:"label,omitempty"`
|
||||
Scale *string `json:"scale,omitempty"`
|
||||
Min *string `json:"min,omitempty"`
|
||||
Max *string `json:"max,omitempty"`
|
||||
IncludeZero *bool `json:"include_zero,omitempty"`
|
||||
}
|
||||
|
||||
type WidgetEvent struct {
|
||||
Query *string `json:"q"`
|
||||
}
|
||||
|
||||
type WidgetMarker struct {
|
||||
Value *string `json:"value"`
|
||||
DisplayType *string `json:"display_type,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
}
|
||||
|
||||
type WidgetMetadata struct {
|
||||
Expression *string `json:"expression"`
|
||||
AliasName *string `json:"alias_name,omitempty"`
|
||||
}
|
||||
|
||||
type WidgetConditionalFormat struct {
|
||||
Comparator *string `json:"comparator"`
|
||||
Value *float64 `json:"value"`
|
||||
Palette *string `json:"palette"`
|
||||
CustomBgColor *string `json:"custom_bg_color,omitempty"`
|
||||
CustomFgColor *string `json:"custom_fg_color,omitempty"`
|
||||
ImageUrl *string `json:"image_url,omitempty"`
|
||||
HideValue *bool `json:"hide_value,omitempty"`
|
||||
Timeframe *string `json:"timeframe,omitempty"`
|
||||
}
|
||||
|
||||
// WidgetApmOrLogQuery represents an APM or a Log query
|
||||
type WidgetApmOrLogQuery struct {
|
||||
Index *string `json:"index"`
|
||||
Compute *ApmOrLogQueryCompute `json:"compute"`
|
||||
Search *ApmOrLogQuerySearch `json:"search,omitempty"`
|
||||
GroupBy []ApmOrLogQueryGroupBy `json:"group_by,omitempty"`
|
||||
}
|
||||
type ApmOrLogQueryCompute struct {
|
||||
Aggregation *string `json:"aggregation"`
|
||||
Facet *string `json:"facet,omitempty"`
|
||||
Interval *int `json:"interval,omitempty"`
|
||||
}
|
||||
type ApmOrLogQuerySearch struct {
|
||||
Query *string `json:"query"`
|
||||
}
|
||||
type ApmOrLogQueryGroupBy struct {
|
||||
Facet *string `json:"facet"`
|
||||
Limit *int `json:"limit,omitempty"`
|
||||
Sort *ApmOrLogQueryGroupBySort `json:"sort,omitempty"`
|
||||
}
|
||||
type ApmOrLogQueryGroupBySort struct {
|
||||
Aggregation *string `json:"aggregation"`
|
||||
Order *string `json:"order"`
|
||||
Facet *string `json:"facet,omitempty"`
|
||||
}
|
||||
|
||||
// WidgetProcessQuery represents a Process query
|
||||
type WidgetProcessQuery struct {
|
||||
Metric *string `json:"metric"`
|
||||
SearchBy *string `json:"search_by,omitempty"`
|
||||
FilterBy []string `json:"filter_by,omitempty"`
|
||||
Limit *int `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
// WidgetRequestStyle represents the style that can be apply to a request
|
||||
type WidgetRequestStyle struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
}
|
||||
59
vendor/github.com/zorkian/go-datadog-api/boards.go
generated
vendored
Normal file
59
vendor/github.com/zorkian/go-datadog-api/boards.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2019 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Board represents a user created dashboard. This is the full dashboard
|
||||
// struct when we load a dashboard in detail.
|
||||
type Board struct {
|
||||
Title *string `json:"title"`
|
||||
Widgets []BoardWidget `json:"widgets"`
|
||||
LayoutType *string `json:"layout_type"`
|
||||
Id *string `json:"id,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
TemplateVariables []TemplateVariable `json:"template_variables,omitempty"`
|
||||
IsReadOnly *bool `json:"is_read_only,omitempty"`
|
||||
NotifyList []string `json:"notify_list,omitempty"`
|
||||
AuthorHandle *string `json:"author_handle,omitempty"`
|
||||
Url *string `json:"url,omitempty"`
|
||||
CreatedAt *string `json:"created_at,omitempty"`
|
||||
ModifiedAt *string `json:"modified_at,omitempty"`
|
||||
}
|
||||
|
||||
// GetBoard returns a single dashboard created on this account.
|
||||
func (client *Client) GetBoard(id string) (*Board, error) {
|
||||
var board Board
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/dashboard/%s", id), nil, &board); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &board, nil
|
||||
}
|
||||
|
||||
// DeleteBoard deletes a dashboard by the identifier.
|
||||
func (client *Client) DeleteBoard(id string) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/dashboard/%s", id), nil, nil)
|
||||
}
|
||||
|
||||
// CreateBoard creates a new dashboard when given a Board struct.
|
||||
func (client *Client) CreateBoard(board *Board) (*Board, error) {
|
||||
var createdBoard Board
|
||||
if err := client.doJsonRequest("POST", "/v1/dashboard", board, &createdBoard); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &createdBoard, nil
|
||||
}
|
||||
|
||||
// UpdateBoard takes a Board struct and persists it back to the server.
|
||||
// Use this if you've updated your local and need to push it back.
|
||||
func (client *Client) UpdateBoard(board *Board) error {
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/dashboard/%s", *board.Id), board, nil)
|
||||
}
|
||||
25
vendor/github.com/zorkian/go-datadog-api/checks.go
generated
vendored
Normal file
25
vendor/github.com/zorkian/go-datadog-api/checks.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
package datadog
|
||||
|
||||
type Check struct {
|
||||
Check *string `json:"check,omitempty"`
|
||||
HostName *string `json:"host_name,omitempty"`
|
||||
Status *Status `json:"status,omitempty"`
|
||||
Timestamp *string `json:"timestamp,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
type Status int
|
||||
|
||||
const (
|
||||
OK Status = iota
|
||||
WARNING
|
||||
CRITICAL
|
||||
UNKNOWN
|
||||
)
|
||||
|
||||
// PostCheck posts the result of a check run to the server
|
||||
func (client *Client) PostCheck(check Check) error {
|
||||
return client.doJsonRequest("POST", "/v1/check_run",
|
||||
check, nil)
|
||||
}
|
||||
100
vendor/github.com/zorkian/go-datadog-api/client.go
generated
vendored
Normal file
100
vendor/github.com/zorkian/go-datadog-api/client.go
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Client is the object that handles talking to the Datadog API. This maintains
|
||||
// state information for a particular application connection.
|
||||
type Client struct {
|
||||
apiKey, appKey, baseUrl string
|
||||
|
||||
//The Http Client that is used to make requests
|
||||
HttpClient *http.Client
|
||||
RetryTimeout time.Duration
|
||||
}
|
||||
|
||||
// valid is the struct to unmarshal validation endpoint responses into.
|
||||
type valid struct {
|
||||
Errors []string `json:"errors"`
|
||||
IsValid bool `json:"valid"`
|
||||
}
|
||||
|
||||
// NewClient returns a new datadog.Client which can be used to access the API
|
||||
// methods. The expected argument is the API key.
|
||||
func NewClient(apiKey, appKey string) *Client {
|
||||
baseUrl := os.Getenv("DATADOG_HOST")
|
||||
if baseUrl == "" {
|
||||
baseUrl = "https://app.datadoghq.com"
|
||||
}
|
||||
|
||||
return &Client{
|
||||
apiKey: apiKey,
|
||||
appKey: appKey,
|
||||
baseUrl: baseUrl,
|
||||
HttpClient: http.DefaultClient,
|
||||
RetryTimeout: time.Duration(60 * time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
// SetKeys changes the value of apiKey and appKey.
|
||||
func (c *Client) SetKeys(apiKey, appKey string) {
|
||||
c.apiKey = apiKey
|
||||
c.appKey = appKey
|
||||
}
|
||||
|
||||
// SetBaseUrl changes the value of baseUrl.
|
||||
func (c *Client) SetBaseUrl(baseUrl string) {
|
||||
c.baseUrl = baseUrl
|
||||
}
|
||||
|
||||
// GetBaseUrl returns the baseUrl.
|
||||
func (c *Client) GetBaseUrl() string {
|
||||
return c.baseUrl
|
||||
}
|
||||
|
||||
// Validate checks if the API and application keys are valid.
|
||||
func (client *Client) Validate() (bool, error) {
|
||||
var out valid
|
||||
var resp *http.Response
|
||||
|
||||
uri, err := client.uriForAPI("/v1/validate")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", uri, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp, err = client.doRequestWithRetries(req, client.RetryTimeout)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(body, &out); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return out.IsValid, nil
|
||||
}
|
||||
72
vendor/github.com/zorkian/go-datadog-api/comments.go
generated
vendored
Normal file
72
vendor/github.com/zorkian/go-datadog-api/comments.go
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Comment is a special form of event that appears in a stream.
|
||||
type Comment struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
RelatedId *int `json:"related_event_id,omitempty"`
|
||||
Handle *string `json:"handle,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
Resource *string `json:"resource,omitempty"`
|
||||
Url *string `json:"url,omitempty"`
|
||||
}
|
||||
|
||||
// reqComment is the container for receiving commenst.
|
||||
type reqComment struct {
|
||||
Comment *Comment `json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
// CreateComment adds a new comment to the system.
|
||||
func (client *Client) CreateComment(handle, message string) (*Comment, error) {
|
||||
var out reqComment
|
||||
comment := Comment{Message: String(message)}
|
||||
if len(handle) > 0 {
|
||||
comment.Handle = String(handle)
|
||||
}
|
||||
if err := client.doJsonRequest("POST", "/v1/comments", &comment, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Comment, nil
|
||||
}
|
||||
|
||||
// CreateRelatedComment adds a new comment, but lets you specify the related
|
||||
// identifier for the comment.
|
||||
func (client *Client) CreateRelatedComment(handle, message string,
|
||||
relid int) (*Comment, error) {
|
||||
var out reqComment
|
||||
comment := Comment{Message: String(message), RelatedId: Int(relid)}
|
||||
if len(handle) > 0 {
|
||||
comment.Handle = String(handle)
|
||||
}
|
||||
if err := client.doJsonRequest("POST", "/v1/comments", &comment, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Comment, nil
|
||||
}
|
||||
|
||||
// EditComment changes the message and possibly handle of a particular comment.
|
||||
func (client *Client) EditComment(id int, handle, message string) error {
|
||||
comment := Comment{Message: String(message)}
|
||||
if len(handle) > 0 {
|
||||
comment.Handle = String(handle)
|
||||
}
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/comments/%d", id),
|
||||
&comment, nil)
|
||||
}
|
||||
|
||||
// DeleteComment does exactly what you expect.
|
||||
func (client *Client) DeleteComment(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/comments/%d", id),
|
||||
nil, nil)
|
||||
}
|
||||
137
vendor/github.com/zorkian/go-datadog-api/dashboard_lists.go
generated
vendored
Normal file
137
vendor/github.com/zorkian/go-datadog-api/dashboard_lists.go
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2018 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
DashboardListItemCustomTimeboard = "custom_timeboard"
|
||||
DashboardListItemCustomScreenboard = "custom_screenboard"
|
||||
DashboardListItemIntegerationTimeboard = "integration_timeboard"
|
||||
DashboardListItemIntegrationScreenboard = "integration_screenboard"
|
||||
DashboardListItemHostTimeboard = "host_timeboard"
|
||||
)
|
||||
|
||||
// DashboardList represents a dashboard list.
|
||||
type DashboardList struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
DashboardCount *int `json:"dashboard_count,omitempty"`
|
||||
}
|
||||
|
||||
// DashboardListItem represents a single dashboard in a dashboard list.
|
||||
type DashboardListItem struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
type reqDashboardListItems struct {
|
||||
Dashboards []DashboardListItem `json:"dashboards,omitempty"`
|
||||
}
|
||||
|
||||
type reqAddedDashboardListItems struct {
|
||||
Dashboards []DashboardListItem `json:"added_dashboards_to_list,omitempty"`
|
||||
}
|
||||
|
||||
type reqDeletedDashboardListItems struct {
|
||||
Dashboards []DashboardListItem `json:"deleted_dashboards_from_list,omitempty"`
|
||||
}
|
||||
|
||||
type reqUpdateDashboardList struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type reqGetDashboardLists struct {
|
||||
DashboardLists []DashboardList `json:"dashboard_lists,omitempty"`
|
||||
}
|
||||
|
||||
// GetDashboardList returns a single dashboard list created on this account.
|
||||
func (client *Client) GetDashboardList(id int) (*DashboardList, error) {
|
||||
var out DashboardList
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/dashboard/lists/manual/%d", id), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// GetDashboardLists returns a list of all dashboard lists created on this account.
|
||||
func (client *Client) GetDashboardLists() ([]DashboardList, error) {
|
||||
var out reqGetDashboardLists
|
||||
if err := client.doJsonRequest("GET", "/v1/dashboard/lists/manual", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.DashboardLists, nil
|
||||
}
|
||||
|
||||
// CreateDashboardList returns a single dashboard list created on this account.
|
||||
func (client *Client) CreateDashboardList(list *DashboardList) (*DashboardList, error) {
|
||||
var out DashboardList
|
||||
if err := client.doJsonRequest("POST", "/v1/dashboard/lists/manual", list, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// UpdateDashboardList returns a single dashboard list created on this account.
|
||||
func (client *Client) UpdateDashboardList(list *DashboardList) error {
|
||||
req := reqUpdateDashboardList{list.GetName()}
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/dashboard/lists/manual/%d", *list.Id), req, nil)
|
||||
}
|
||||
|
||||
// DeleteDashboardList deletes a dashboard list by the identifier.
|
||||
func (client *Client) DeleteDashboardList(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/dashboard/lists/manual/%d", id), nil, nil)
|
||||
}
|
||||
|
||||
// GetDashboardListItems fetches the dashboard list's dashboard definitions.
|
||||
func (client *Client) GetDashboardListItems(id int) ([]DashboardListItem, error) {
|
||||
var out reqDashboardListItems
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/dashboard/lists/manual/%d/dashboards", id), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Dashboards, nil
|
||||
}
|
||||
|
||||
// AddDashboardListItems adds dashboards to an existing dashboard list.
|
||||
//
|
||||
// Any items already in the list are ignored (not added twice).
|
||||
func (client *Client) AddDashboardListItems(dashboardListId int, items []DashboardListItem) ([]DashboardListItem, error) {
|
||||
req := reqDashboardListItems{items}
|
||||
var out reqAddedDashboardListItems
|
||||
if err := client.doJsonRequest("POST", fmt.Sprintf("/v1/dashboard/lists/manual/%d/dashboards", dashboardListId), req, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Dashboards, nil
|
||||
}
|
||||
|
||||
// UpdateDashboardListItems updates dashboards of an existing dashboard list.
|
||||
//
|
||||
// This will set the list of dashboards to contain only the items in items.
|
||||
func (client *Client) UpdateDashboardListItems(dashboardListId int, items []DashboardListItem) ([]DashboardListItem, error) {
|
||||
req := reqDashboardListItems{items}
|
||||
var out reqDashboardListItems
|
||||
if err := client.doJsonRequest("PUT", fmt.Sprintf("/v1/dashboard/lists/manual/%d/dashboards", dashboardListId), req, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Dashboards, nil
|
||||
}
|
||||
|
||||
// DeleteDashboardListItems deletes dashboards from an existing dashboard list.
|
||||
//
|
||||
// Deletes any dashboards in the list of items from the dashboard list.
|
||||
func (client *Client) DeleteDashboardListItems(dashboardListId int, items []DashboardListItem) ([]DashboardListItem, error) {
|
||||
req := reqDashboardListItems{items}
|
||||
var out reqDeletedDashboardListItems
|
||||
if err := client.doJsonRequest("DELETE", fmt.Sprintf("/v1/dashboard/lists/manual/%d/dashboards", dashboardListId), req, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Dashboards, nil
|
||||
}
|
||||
260
vendor/github.com/zorkian/go-datadog-api/dashboards.go
generated
vendored
Normal file
260
vendor/github.com/zorkian/go-datadog-api/dashboards.go
generated
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GraphDefinitionRequestStyle represents the graph style attributes
|
||||
type GraphDefinitionRequestStyle struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
Width *string `json:"width,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
// GraphDefinitionRequest represents the requests passed into each graph.
|
||||
type GraphDefinitionRequest struct {
|
||||
Query *string `json:"q,omitempty"`
|
||||
Stacked *bool `json:"stacked,omitempty"`
|
||||
Aggregator *string `json:"aggregator,omitempty"`
|
||||
ConditionalFormats []DashboardConditionalFormat `json:"conditional_formats,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Style *GraphDefinitionRequestStyle `json:"style,omitempty"`
|
||||
|
||||
// For change type graphs
|
||||
ChangeType *string `json:"change_type,omitempty"`
|
||||
OrderDirection *string `json:"order_dir,omitempty"`
|
||||
CompareTo *string `json:"compare_to,omitempty"`
|
||||
IncreaseGood *bool `json:"increase_good,omitempty"`
|
||||
OrderBy *string `json:"order_by,omitempty"`
|
||||
ExtraCol *string `json:"extra_col,omitempty"`
|
||||
Metadata map[string]GraphDefinitionMetadata `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
type GraphDefinitionMetadata TileDefMetadata
|
||||
|
||||
type GraphDefinitionMarker struct {
|
||||
Type *string `json:"type,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Val *json.Number `json:"val,omitempty"`
|
||||
Min *json.Number `json:"min,omitempty"`
|
||||
Max *json.Number `json:"max,omitempty"`
|
||||
}
|
||||
|
||||
type GraphEvent struct {
|
||||
Query *string `json:"q,omitempty"`
|
||||
}
|
||||
|
||||
type Yaxis struct {
|
||||
Min *float64 `json:"min,omitempty"`
|
||||
AutoMin bool `json:"-"`
|
||||
Max *float64 `json:"max,omitempty"`
|
||||
AutoMax bool `json:"-"`
|
||||
Scale *string `json:"scale,omitempty"`
|
||||
IncludeZero *bool `json:"includeZero,omitempty"`
|
||||
IncludeUnits *bool `json:"units,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON is a Custom Unmarshal for Yaxis.Min/Yaxis.Max. If the datadog API
|
||||
// returns "auto" for min or max, then we should set Yaxis.min or Yaxis.max to nil,
|
||||
// respectively.
|
||||
func (y *Yaxis) UnmarshalJSON(data []byte) error {
|
||||
type Alias Yaxis
|
||||
wrapper := &struct {
|
||||
Min *json.Number `json:"min,omitempty"`
|
||||
Max *json.Number `json:"max,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(y),
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &wrapper); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if wrapper.Min != nil {
|
||||
if *wrapper.Min == "auto" {
|
||||
y.AutoMin = true
|
||||
y.Min = nil
|
||||
} else {
|
||||
f, err := wrapper.Min.Float64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
y.Min = &f
|
||||
}
|
||||
}
|
||||
|
||||
if wrapper.Max != nil {
|
||||
if *wrapper.Max == "auto" {
|
||||
y.AutoMax = true
|
||||
y.Max = nil
|
||||
} else {
|
||||
f, err := wrapper.Max.Float64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
y.Max = &f
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Style struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
PaletteFlip *bool `json:"paletteFlip,omitempty"`
|
||||
FillMin *json.Number `json:"fillMin,omitempty"`
|
||||
FillMax *json.Number `json:"fillMax,omitempty"`
|
||||
}
|
||||
|
||||
type GraphDefinition struct {
|
||||
Viz *string `json:"viz,omitempty"`
|
||||
Requests []GraphDefinitionRequest `json:"requests,omitempty"`
|
||||
Events []GraphEvent `json:"events,omitempty"`
|
||||
Markers []GraphDefinitionMarker `json:"markers,omitempty"`
|
||||
|
||||
// For timeseries type graphs
|
||||
Yaxis Yaxis `json:"yaxis,omitempty"`
|
||||
|
||||
// For query value type graphs
|
||||
Autoscale *bool `json:"autoscale,omitempty"`
|
||||
TextAlign *string `json:"text_align,omitempty"`
|
||||
Precision *PrecisionT `json:"precision,omitempty"`
|
||||
CustomUnit *string `json:"custom_unit,omitempty"`
|
||||
|
||||
// For hostmaps
|
||||
Style *Style `json:"style,omitempty"`
|
||||
Groups []string `json:"group,omitempty"`
|
||||
IncludeNoMetricHosts *bool `json:"noMetricHosts,omitempty"`
|
||||
Scopes []string `json:"scope,omitempty"`
|
||||
IncludeUngroupedHosts *bool `json:"noGroupHosts,omitempty"`
|
||||
NodeType *string `json:"nodeType,omitempty"`
|
||||
}
|
||||
|
||||
// Graph represents a graph that might exist on a dashboard.
|
||||
type Graph struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
Definition *GraphDefinition `json:"definition"`
|
||||
}
|
||||
|
||||
// Template variable represents a template variable that might exist on a dashboard
|
||||
type TemplateVariable struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Prefix *string `json:"prefix,omitempty"`
|
||||
Default *string `json:"default,omitempty"`
|
||||
}
|
||||
|
||||
// Dashboard represents a user created dashboard. This is the full dashboard
|
||||
// struct when we load a dashboard in detail.
|
||||
type Dashboard struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
NewId *string `json:"new_id,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Graphs []Graph `json:"graphs,omitempty"`
|
||||
TemplateVariables []TemplateVariable `json:"template_variables,omitempty"`
|
||||
ReadOnly *bool `json:"read_only,omitempty"`
|
||||
}
|
||||
|
||||
// DashboardLite represents a user created dashboard. This is the mini
|
||||
// struct when we load the summaries.
|
||||
type DashboardLite struct {
|
||||
Id *int `json:"id,string,omitempty"` // TODO: Remove ',string'.
|
||||
Resource *string `json:"resource,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
ReadOnly *bool `json:"read_only,omitempty"`
|
||||
Created *string `json:"created,omitempty"`
|
||||
Modified *string `json:"modified,omitempty"`
|
||||
CreatedBy *CreatedBy `json:"created_by,omitempty"`
|
||||
}
|
||||
|
||||
// CreatedBy represents a field from DashboardLite.
|
||||
type CreatedBy struct {
|
||||
Disabled *bool `json:"disabled,omitempty"`
|
||||
Handle *string `json:"handle,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
IsAdmin *bool `json:"is_admin,omitempty"`
|
||||
Role *string `json:"role,omitempty"`
|
||||
AccessRole *string `json:"access_role,omitempty"`
|
||||
Verified *bool `json:"verified,omitempty"`
|
||||
Email *string `json:"email,omitempty"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
}
|
||||
|
||||
// reqGetDashboards from /api/v1/dash
|
||||
type reqGetDashboards struct {
|
||||
Dashboards []DashboardLite `json:"dashes,omitempty"`
|
||||
}
|
||||
|
||||
// reqGetDashboard from /api/v1/dash/:dashboard_id
|
||||
type reqGetDashboard struct {
|
||||
Resource *string `json:"resource,omitempty"`
|
||||
Url *string `json:"url,omitempty"`
|
||||
Dashboard *Dashboard `json:"dash,omitempty"`
|
||||
}
|
||||
|
||||
type DashboardConditionalFormat struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
Comparator *string `json:"comparator,omitempty"`
|
||||
CustomBgColor *string `json:"custom_bg_color,omitempty"`
|
||||
Value *json.Number `json:"value,omitempty"`
|
||||
Inverted *bool `json:"invert,omitempty"`
|
||||
CustomFgColor *string `json:"custom_fg_color,omitempty"`
|
||||
CustomImageUrl *string `json:"custom_image,omitempty"`
|
||||
}
|
||||
|
||||
// GetDashboard returns a single dashboard created on this account.
|
||||
func (client *Client) GetDashboard(id interface{}) (*Dashboard, error) {
|
||||
|
||||
stringId, err := GetStringId(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var out reqGetDashboard
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/dash/%s", stringId), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Dashboard, nil
|
||||
}
|
||||
|
||||
// GetDashboards returns a list of all dashboards created on this account.
|
||||
func (client *Client) GetDashboards() ([]DashboardLite, error) {
|
||||
var out reqGetDashboards
|
||||
if err := client.doJsonRequest("GET", "/v1/dash", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Dashboards, nil
|
||||
}
|
||||
|
||||
// DeleteDashboard deletes a dashboard by the identifier.
|
||||
func (client *Client) DeleteDashboard(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/dash/%d", id), nil, nil)
|
||||
}
|
||||
|
||||
// CreateDashboard creates a new dashboard when given a Dashboard struct. Note
|
||||
// that the Id, Resource, Url and similar elements are not used in creation.
|
||||
func (client *Client) CreateDashboard(dash *Dashboard) (*Dashboard, error) {
|
||||
var out reqGetDashboard
|
||||
if err := client.doJsonRequest("POST", "/v1/dash", dash, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Dashboard, nil
|
||||
}
|
||||
|
||||
// UpdateDashboard in essence takes a Dashboard struct and persists it back to
|
||||
// the server. Use this if you've updated your local and need to push it back.
|
||||
func (client *Client) UpdateDashboard(dash *Dashboard) error {
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/dash/%d", *dash.Id),
|
||||
dash, nil)
|
||||
}
|
||||
21374
vendor/github.com/zorkian/go-datadog-api/datadog-accessors.go
generated
vendored
Normal file
21374
vendor/github.com/zorkian/go-datadog-api/datadog-accessors.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
122
vendor/github.com/zorkian/go-datadog-api/downtimes.go
generated
vendored
Normal file
122
vendor/github.com/zorkian/go-datadog-api/downtimes.go
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DowntimeType are a classification of a given downtime scope
|
||||
type DowntimeType int
|
||||
|
||||
// The three downtime type classifications.
|
||||
const (
|
||||
StarDowntimeType DowntimeType = 0
|
||||
HostDowntimeType DowntimeType = 1
|
||||
OtherDowntimeType DowntimeType = 2
|
||||
)
|
||||
|
||||
type Recurrence struct {
|
||||
Period *int `json:"period,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
UntilDate *int `json:"until_date,omitempty"`
|
||||
UntilOccurrences *int `json:"until_occurrences,omitempty"`
|
||||
WeekDays []string `json:"week_days,omitempty"`
|
||||
}
|
||||
|
||||
type Downtime struct {
|
||||
Active *bool `json:"active,omitempty"`
|
||||
Canceled *int `json:"canceled,omitempty"`
|
||||
Disabled *bool `json:"disabled,omitempty"`
|
||||
End *int `json:"end,omitempty"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
MonitorId *int `json:"monitor_id,omitempty"`
|
||||
MonitorTags []string `json:"monitor_tags,omitempty"`
|
||||
ParentId *int `json:"parent_id,omitempty"`
|
||||
Timezone *string `json:"timezone,omitempty"`
|
||||
Recurrence *Recurrence `json:"recurrence,omitempty"`
|
||||
Scope []string `json:"scope,omitempty"`
|
||||
Start *int `json:"start,omitempty"`
|
||||
CreatorID *int `json:"creator_id,omitempty"`
|
||||
UpdaterID *int `json:"updater_id,omitempty"`
|
||||
Type *int `json:"downtime_type,omitempty"`
|
||||
}
|
||||
|
||||
// DowntimeType returns the canonical downtime type classification.
|
||||
// This is calculated based on the provided server response, but the logic is copied down here to calculate locally.
|
||||
func (d *Downtime) DowntimeType() DowntimeType {
|
||||
if d.Type != nil {
|
||||
switch *d.Type {
|
||||
case 0:
|
||||
return StarDowntimeType
|
||||
case 1:
|
||||
return HostDowntimeType
|
||||
default:
|
||||
return OtherDowntimeType
|
||||
}
|
||||
}
|
||||
if len(d.Scope) == 1 {
|
||||
if d.Scope[0] == "*" {
|
||||
return StarDowntimeType
|
||||
}
|
||||
if strings.HasPrefix(d.Scope[0], "host:") {
|
||||
return HostDowntimeType
|
||||
}
|
||||
}
|
||||
return OtherDowntimeType
|
||||
}
|
||||
|
||||
// reqDowntimes retrieves a slice of all Downtimes.
|
||||
type reqDowntimes struct {
|
||||
Downtimes []Downtime `json:"downtimes,omitempty"`
|
||||
}
|
||||
|
||||
// CreateDowntime adds a new downtme to the system. This returns a pointer
|
||||
// to a Downtime so you can pass that to UpdateDowntime or CancelDowntime
|
||||
// later if needed.
|
||||
func (client *Client) CreateDowntime(downtime *Downtime) (*Downtime, error) {
|
||||
var out Downtime
|
||||
if err := client.doJsonRequest("POST", "/v1/downtime", downtime, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// UpdateDowntime takes a downtime that was previously retrieved through some method
|
||||
// and sends it back to the server.
|
||||
func (client *Client) UpdateDowntime(downtime *Downtime) error {
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/downtime/%d", *downtime.Id),
|
||||
downtime, downtime)
|
||||
}
|
||||
|
||||
// Getdowntime retrieves an downtime by identifier.
|
||||
func (client *Client) GetDowntime(id int) (*Downtime, error) {
|
||||
var out Downtime
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/downtime/%d", id), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// DeleteDowntime removes an downtime from the system.
|
||||
func (client *Client) DeleteDowntime(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/downtime/%d", id),
|
||||
nil, nil)
|
||||
}
|
||||
|
||||
// GetDowntimes returns a slice of all downtimes.
|
||||
func (client *Client) GetDowntimes() ([]Downtime, error) {
|
||||
var out reqDowntimes
|
||||
if err := client.doJsonRequest("GET", "/v1/downtime", nil, &out.Downtimes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Downtimes, nil
|
||||
}
|
||||
87
vendor/github.com/zorkian/go-datadog-api/events.go
generated
vendored
Normal file
87
vendor/github.com/zorkian/go-datadog-api/events.go
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Event is a single event. If this is being used to post an event, then not
|
||||
// all fields will be filled out.
|
||||
type Event struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
Time *int `json:"date_happened,omitempty"` // UNIX time.
|
||||
Priority *string `json:"priority,omitempty"`
|
||||
AlertType *string `json:"alert_type,omitempty"`
|
||||
Host *string `json:"host,omitempty"`
|
||||
Aggregation *string `json:"aggregation_key,omitempty"`
|
||||
SourceType *string `json:"source_type_name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Url *string `json:"url,omitempty"`
|
||||
Resource *string `json:"resource,omitempty"`
|
||||
EventType *string `json:"event_type,omitempty"`
|
||||
}
|
||||
|
||||
// reqGetEvent is the container for receiving a single event.
|
||||
type reqGetEvent struct {
|
||||
Event *Event `json:"event,omitempty"`
|
||||
}
|
||||
|
||||
// reqGetEvents is for returning many events.
|
||||
type reqGetEvents struct {
|
||||
Events []Event `json:"events,omitempty"`
|
||||
}
|
||||
|
||||
// PostEvent takes as input an event and then posts it to the server.
|
||||
func (client *Client) PostEvent(event *Event) (*Event, error) {
|
||||
var out reqGetEvent
|
||||
if err := client.doJsonRequest("POST", "/v1/events", event, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Event, nil
|
||||
}
|
||||
|
||||
// GetEvent gets a single event given an identifier.
|
||||
func (client *Client) GetEvent(id int) (*Event, error) {
|
||||
var out reqGetEvent
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/events/%d", id), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Event, nil
|
||||
}
|
||||
|
||||
// GetEvents returns a slice of events from the query stream.
|
||||
func (client *Client) GetEvents(start, end int,
|
||||
priority, sources, tags string) ([]Event, error) {
|
||||
// Since this is a GET request, we need to build a query string.
|
||||
vals := url.Values{}
|
||||
vals.Add("start", strconv.Itoa(start))
|
||||
vals.Add("end", strconv.Itoa(end))
|
||||
if priority != "" {
|
||||
vals.Add("priority", priority)
|
||||
}
|
||||
if sources != "" {
|
||||
vals.Add("sources", sources)
|
||||
}
|
||||
if tags != "" {
|
||||
vals.Add("tags", tags)
|
||||
}
|
||||
|
||||
// Now the request and response.
|
||||
var out reqGetEvents
|
||||
if err := client.doJsonRequest("GET",
|
||||
fmt.Sprintf("/v1/events?%s", vals.Encode()), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Events, nil
|
||||
}
|
||||
3
vendor/github.com/zorkian/go-datadog-api/generate.go
generated
vendored
Normal file
3
vendor/github.com/zorkian/go-datadog-api/generate.go
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
package datadog
|
||||
|
||||
//go:generate go run cmd/tools/gen-accessors.go -v
|
||||
100
vendor/github.com/zorkian/go-datadog-api/helpers.go
generated
vendored
Normal file
100
vendor/github.com/zorkian/go-datadog-api/helpers.go
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2017 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Bool is a helper routine that allocates a new bool value
|
||||
// to store v and returns a pointer to it.
|
||||
func Bool(v bool) *bool { return &v }
|
||||
|
||||
// GetBool is a helper routine that returns a boolean representing
|
||||
// if a value was set, and if so, dereferences the pointer to it.
|
||||
func GetBool(v *bool) (bool, bool) {
|
||||
if v != nil {
|
||||
return *v, true
|
||||
}
|
||||
|
||||
return false, false
|
||||
}
|
||||
|
||||
// Int is a helper routine that allocates a new int value
|
||||
// to store v and returns a pointer to it.
|
||||
func Int(v int) *int { return &v }
|
||||
|
||||
// GetIntOk is a helper routine that returns a boolean representing
|
||||
// if a value was set, and if so, dereferences the pointer to it.
|
||||
func GetIntOk(v *int) (int, bool) {
|
||||
if v != nil {
|
||||
return *v, true
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// String is a helper routine that allocates a new string value
|
||||
// to store v and returns a pointer to it.
|
||||
func String(v string) *string { return &v }
|
||||
|
||||
// GetStringOk is a helper routine that returns a boolean representing
|
||||
// if a value was set, and if so, dereferences the pointer to it.
|
||||
func GetStringOk(v *string) (string, bool) {
|
||||
if v != nil {
|
||||
return *v, true
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
// JsonNumber is a helper routine that allocates a new string value
|
||||
// to store v and returns a pointer to it.
|
||||
func JsonNumber(v json.Number) *json.Number { return &v }
|
||||
|
||||
// GetJsonNumberOk is a helper routine that returns a boolean representing
|
||||
// if a value was set, and if so, dereferences the pointer to it.
|
||||
func GetJsonNumberOk(v *json.Number) (json.Number, bool) {
|
||||
if v != nil {
|
||||
return *v, true
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Precision is a helper routine that allocates a new precision value
|
||||
// to store v and returns a pointer to it.
|
||||
func Precision(v PrecisionT) *PrecisionT { return &v }
|
||||
|
||||
// GetPrecision is a helper routine that returns a boolean representing
|
||||
// if a value was set, and if so, dereferences the pointer to it.
|
||||
func GetPrecision(v *PrecisionT) (PrecisionT, bool) {
|
||||
if v != nil {
|
||||
return *v, true
|
||||
}
|
||||
|
||||
return PrecisionT(""), false
|
||||
}
|
||||
|
||||
// GetStringId is a helper routine that allows screenboards and timeboards to be retrieved
|
||||
// by either the legacy numerical format or the new string format.
|
||||
// It returns the id as is if it is a string, converts it to a string if it is an integer.
|
||||
// It return an error if the type is neither string or an integer
|
||||
func GetStringId(id interface{}) (string, error) {
|
||||
switch v := id.(type) {
|
||||
case int:
|
||||
return strconv.Itoa(v), nil
|
||||
case string:
|
||||
return v, nil
|
||||
default:
|
||||
return "", errors.New("unsupported id type")
|
||||
}
|
||||
}
|
||||
33
vendor/github.com/zorkian/go-datadog-api/hosts.go
generated
vendored
Normal file
33
vendor/github.com/zorkian/go-datadog-api/hosts.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
package datadog
|
||||
|
||||
type HostActionResp struct {
|
||||
Action string `json:"action"`
|
||||
Hostname string `json:"hostname"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type HostActionMute struct {
|
||||
Message *string `json:"message,omitempty"`
|
||||
EndTime *string `json:"end,omitempty"`
|
||||
Override *bool `json:"override,omitempty"`
|
||||
}
|
||||
|
||||
// MuteHost mutes all monitors for the given host
|
||||
func (client *Client) MuteHost(host string, action *HostActionMute) (*HostActionResp, error) {
|
||||
var out HostActionResp
|
||||
uri := "/v1/host/" + host + "/mute"
|
||||
if err := client.doJsonRequest("POST", uri, action, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// UnmuteHost unmutes all monitors for the given host
|
||||
func (client *Client) UnmuteHost(host string) (*HostActionResp, error) {
|
||||
var out HostActionResp
|
||||
uri := "/v1/host/" + host + "/unmute"
|
||||
if err := client.doJsonRequest("POST", uri, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
241
vendor/github.com/zorkian/go-datadog-api/integrations.go
generated
vendored
Normal file
241
vendor/github.com/zorkian/go-datadog-api/integrations.go
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2018 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
/*
|
||||
PagerDuty Integration
|
||||
*/
|
||||
|
||||
type servicePD struct {
|
||||
ServiceName *string `json:"service_name"`
|
||||
ServiceKey *string `json:"service_key"`
|
||||
}
|
||||
|
||||
type integrationPD struct {
|
||||
Services []servicePD `json:"services"`
|
||||
Subdomain *string `json:"subdomain"`
|
||||
Schedules []string `json:"schedules"`
|
||||
APIToken *string `json:"api_token"`
|
||||
}
|
||||
|
||||
// ServicePDRequest defines the Services struct that is part of the IntegrationPDRequest.
|
||||
type ServicePDRequest struct {
|
||||
ServiceName *string `json:"service_name"`
|
||||
ServiceKey *string `json:"service_key"`
|
||||
}
|
||||
|
||||
// IntegrationPDRequest defines the request payload for
|
||||
// creating & updating Datadog-PagerDuty integration.
|
||||
type IntegrationPDRequest struct {
|
||||
Services []ServicePDRequest `json:"services,omitempty"`
|
||||
Subdomain *string `json:"subdomain,omitempty"`
|
||||
Schedules []string `json:"schedules,omitempty"`
|
||||
APIToken *string `json:"api_token,omitempty"`
|
||||
RunCheck *bool `json:"run_check,omitempty"`
|
||||
}
|
||||
|
||||
// CreateIntegrationPD creates new PagerDuty Integrations.
|
||||
// Use this if you want to setup the integration for the first time
|
||||
// or to add more services/schedules.
|
||||
func (client *Client) CreateIntegrationPD(pdIntegration *IntegrationPDRequest) error {
|
||||
return client.doJsonRequest("POST", "/v1/integration/pagerduty", pdIntegration, nil)
|
||||
}
|
||||
|
||||
// UpdateIntegrationPD updates the PagerDuty Integration.
|
||||
// This will replace the existing values with the new values.
|
||||
func (client *Client) UpdateIntegrationPD(pdIntegration *IntegrationPDRequest) error {
|
||||
return client.doJsonRequest("PUT", "/v1/integration/pagerduty", pdIntegration, nil)
|
||||
}
|
||||
|
||||
// GetIntegrationPD gets all the PagerDuty Integrations from the system.
|
||||
func (client *Client) GetIntegrationPD() (*integrationPD, error) {
|
||||
var out integrationPD
|
||||
if err := client.doJsonRequest("GET", "/v1/integration/pagerduty", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// DeleteIntegrationPD removes the PagerDuty Integration from the system.
|
||||
func (client *Client) DeleteIntegrationPD() error {
|
||||
return client.doJsonRequest("DELETE", "/v1/integration/pagerduty", nil, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
Slack Integration
|
||||
*/
|
||||
|
||||
// ServiceHookSlackRequest defines the ServiceHooks struct that is part of the IntegrationSlackRequest.
|
||||
type ServiceHookSlackRequest struct {
|
||||
Account *string `json:"account"`
|
||||
Url *string `json:"url"`
|
||||
}
|
||||
|
||||
// ChannelSlackRequest defines the Channels struct that is part of the IntegrationSlackRequest.
|
||||
type ChannelSlackRequest struct {
|
||||
ChannelName *string `json:"channel_name"`
|
||||
TransferAllUserComments *bool `json:"transfer_all_user_comments,omitempty,string"`
|
||||
Account *string `json:"account"`
|
||||
}
|
||||
|
||||
// IntegrationSlackRequest defines the request payload for
|
||||
// creating & updating Datadog-Slack integration.
|
||||
type IntegrationSlackRequest struct {
|
||||
ServiceHooks []ServiceHookSlackRequest `json:"service_hooks,omitempty"`
|
||||
Channels []ChannelSlackRequest `json:"channels,omitempty"`
|
||||
RunCheck *bool `json:"run_check,omitempty,string"`
|
||||
}
|
||||
|
||||
// CreateIntegrationSlack creates new Slack Integrations.
|
||||
// Use this if you want to setup the integration for the first time
|
||||
// or to add more channels.
|
||||
func (client *Client) CreateIntegrationSlack(slackIntegration *IntegrationSlackRequest) error {
|
||||
return client.doJsonRequest("POST", "/v1/integration/slack", slackIntegration, nil)
|
||||
}
|
||||
|
||||
// UpdateIntegrationSlack updates the Slack Integration.
|
||||
// This will replace the existing values with the new values.
|
||||
func (client *Client) UpdateIntegrationSlack(slackIntegration *IntegrationSlackRequest) error {
|
||||
return client.doJsonRequest("PUT", "/v1/integration/slack", slackIntegration, nil)
|
||||
}
|
||||
|
||||
// GetIntegrationSlack gets all the Slack Integrations from the system.
|
||||
func (client *Client) GetIntegrationSlack() (*IntegrationSlackRequest, error) {
|
||||
var out IntegrationSlackRequest
|
||||
if err := client.doJsonRequest("GET", "/v1/integration/slack", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// DeleteIntegrationSlack removes the Slack Integration from the system.
|
||||
func (client *Client) DeleteIntegrationSlack() error {
|
||||
return client.doJsonRequest("DELETE", "/v1/integration/slack", nil, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
AWS Integration
|
||||
*/
|
||||
|
||||
// IntegrationAWSAccount defines the request payload for
|
||||
// creating & updating Datadog-AWS integration.
|
||||
type IntegrationAWSAccount struct {
|
||||
AccountID *string `json:"account_id"`
|
||||
RoleName *string `json:"role_name"`
|
||||
FilterTags []string `json:"filter_tags"`
|
||||
HostTags []string `json:"host_tags"`
|
||||
AccountSpecificNamespaceRules map[string]bool `json:"account_specific_namespace_rules"`
|
||||
}
|
||||
|
||||
// IntegrationAWSAccountCreateResponse defines the response payload for
|
||||
// creating & updating Datadog-AWS integration.
|
||||
type IntegrationAWSAccountCreateResponse struct {
|
||||
ExternalID string `json:"external_id"`
|
||||
}
|
||||
|
||||
type IntegrationAWSAccountGetResponse struct {
|
||||
Accounts []IntegrationAWSAccount `json:"accounts"`
|
||||
}
|
||||
|
||||
type IntegrationAWSAccountDeleteRequest struct {
|
||||
AccountID *string `json:"account_id"`
|
||||
RoleName *string `json:"role_name"`
|
||||
}
|
||||
|
||||
// CreateIntegrationAWS adds a new AWS Account in the AWS Integrations.
|
||||
// Use this if you want to setup the integration for the first time
|
||||
// or to add more accounts.
|
||||
func (client *Client) CreateIntegrationAWS(awsAccount *IntegrationAWSAccount) (*IntegrationAWSAccountCreateResponse, error) {
|
||||
var out IntegrationAWSAccountCreateResponse
|
||||
if err := client.doJsonRequest("POST", "/v1/integration/aws", awsAccount, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// GetIntegrationAWS gets all the AWS Accounts in the AWS Integrations from Datadog.
|
||||
func (client *Client) GetIntegrationAWS() (*[]IntegrationAWSAccount, error) {
|
||||
var response IntegrationAWSAccountGetResponse
|
||||
if err := client.doJsonRequest("GET", "/v1/integration/aws", nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response.Accounts, nil
|
||||
}
|
||||
|
||||
// DeleteIntegrationAWS removes a specific AWS Account from the AWS Integration.
|
||||
func (client *Client) DeleteIntegrationAWS(awsAccount *IntegrationAWSAccountDeleteRequest) error {
|
||||
return client.doJsonRequest("DELETE", "/v1/integration/aws", awsAccount, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
Google Cloud Platform Integration
|
||||
*/
|
||||
|
||||
// IntegrationGCP defines the response for listing Datadog-Google CloudPlatform integration.
|
||||
type IntegrationGCP struct {
|
||||
ProjectID *string `json:"project_id"`
|
||||
ClientEmail *string `json:"client_email"`
|
||||
HostFilters *string `json:"host_filters"`
|
||||
}
|
||||
|
||||
// IntegrationGCPCreateRequest defines the request payload for creating Datadog-Google CloudPlatform integration.
|
||||
type IntegrationGCPCreateRequest struct {
|
||||
Type *string `json:"type"` // Should be service_account
|
||||
ProjectID *string `json:"project_id"`
|
||||
PrivateKeyID *string `json:"private_key_id"`
|
||||
PrivateKey *string `json:"private_key"`
|
||||
ClientEmail *string `json:"client_email"`
|
||||
ClientID *string `json:"client_id"`
|
||||
AuthURI *string `json:"auth_uri"` // Should be https://accounts.google.com/o/oauth2/auth
|
||||
TokenURI *string `json:"token_uri"` // Should be https://accounts.google.com/o/oauth2/token
|
||||
AuthProviderX509CertURL *string `json:"auth_provider_x509_cert_url"` // Should be https://www.googleapis.com/oauth2/v1/certs
|
||||
ClientX509CertURL *string `json:"client_x509_cert_url"` // https://www.googleapis.com/robot/v1/metadata/x509/<CLIENT_EMAIL>
|
||||
HostFilters *string `json:"host_filters,omitempty"`
|
||||
}
|
||||
|
||||
// IntegrationGCPUpdateRequest defines the request payload for updating Datadog-Google CloudPlatform integration.
|
||||
type IntegrationGCPUpdateRequest struct {
|
||||
ProjectID *string `json:"project_id"`
|
||||
ClientEmail *string `json:"client_email"`
|
||||
HostFilters *string `json:"host_filters,omitempty"`
|
||||
}
|
||||
|
||||
// IntegrationGCPDeleteRequest defines the request payload for deleting Datadog-Google CloudPlatform integration.
|
||||
type IntegrationGCPDeleteRequest struct {
|
||||
ProjectID *string `json:"project_id"`
|
||||
ClientEmail *string `json:"client_email"`
|
||||
}
|
||||
|
||||
// ListIntegrationGCP gets all Google Cloud Platform Integrations.
|
||||
func (client *Client) ListIntegrationGCP() ([]*IntegrationGCP, error) {
|
||||
var list []*IntegrationGCP
|
||||
if err := client.doJsonRequest("GET", "/v1/integration/gcp", nil, &list); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// CreateIntegrationGCP creates a new Google Cloud Platform Integration.
|
||||
func (client *Client) CreateIntegrationGCP(cir *IntegrationGCPCreateRequest) error {
|
||||
return client.doJsonRequest("POST", "/v1/integration/gcp", cir, nil)
|
||||
}
|
||||
|
||||
// UpdateIntegrationGCP updates a Google Cloud Platform Integration.
|
||||
func (client *Client) UpdateIntegrationGCP(cir *IntegrationGCPUpdateRequest) error {
|
||||
return client.doJsonRequest("POST", "/v1/integration/gcp/host_filters", cir, nil)
|
||||
}
|
||||
|
||||
// DeleteIntegrationGCP deletes a Google Cloud Platform Integration.
|
||||
func (client *Client) DeleteIntegrationGCP(cir *IntegrationGCPDeleteRequest) error {
|
||||
return client.doJsonRequest("DELETE", "/v1/integration/gcp", cir, nil)
|
||||
}
|
||||
39
vendor/github.com/zorkian/go-datadog-api/metric_metadata.go
generated
vendored
Normal file
39
vendor/github.com/zorkian/go-datadog-api/metric_metadata.go
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import "fmt"
|
||||
|
||||
// MetricMetadata allows you to edit fields of a metric's metadata.
|
||||
type MetricMetadata struct {
|
||||
Type *string `json:"type,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
ShortName *string `json:"short_name,omitempty"`
|
||||
Unit *string `json:"unit,omitempty"`
|
||||
PerUnit *string `json:"per_unit,omitempty"`
|
||||
StatsdInterval *int `json:"statsd_interval,omitempty"`
|
||||
}
|
||||
|
||||
// ViewMetricMetadata allows you to get metadata about a specific metric.
|
||||
func (client *Client) ViewMetricMetadata(mn string) (*MetricMetadata, error) {
|
||||
var out MetricMetadata
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/metrics/%s", mn), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// EditMetricMetadata edits the metadata for the given metric.
|
||||
func (client *Client) EditMetricMetadata(mn string, mm *MetricMetadata) (*MetricMetadata, error) {
|
||||
var out MetricMetadata
|
||||
if err := client.doJsonRequest("PUT", fmt.Sprintf("/v1/metrics/%s", mn), mm, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
257
vendor/github.com/zorkian/go-datadog-api/monitors.go
generated
vendored
Normal file
257
vendor/github.com/zorkian/go-datadog-api/monitors.go
generated
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Period struct {
|
||||
Seconds *json.Number `json:"seconds,omitempty"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Unit *string `json:"unit,omitempty"`
|
||||
}
|
||||
|
||||
type LogSet struct {
|
||||
ID *json.Number `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type TimeRange struct {
|
||||
To *json.Number `json:"to,omitempty"`
|
||||
From *json.Number `json:"from,omitempty"`
|
||||
Live *bool `json:"live,omitempty"`
|
||||
}
|
||||
|
||||
type QueryConfig struct {
|
||||
LogSet *LogSet `json:"logset,omitempty"`
|
||||
TimeRange *TimeRange `json:"timeRange,omitempty"`
|
||||
QueryString *string `json:"queryString,omitempty"`
|
||||
QueryIsFailed *bool `json:"queryIsFailed,omitempty"`
|
||||
}
|
||||
|
||||
type ThresholdCount struct {
|
||||
Ok *json.Number `json:"ok,omitempty"`
|
||||
Critical *json.Number `json:"critical,omitempty"`
|
||||
Warning *json.Number `json:"warning,omitempty"`
|
||||
Unknown *json.Number `json:"unknown,omitempty"`
|
||||
CriticalRecovery *json.Number `json:"critical_recovery,omitempty"`
|
||||
WarningRecovery *json.Number `json:"warning_recovery,omitempty"`
|
||||
Period *Period `json:"period,omitempty"`
|
||||
TimeAggregator *string `json:"timeAggregator,omitempty"`
|
||||
}
|
||||
|
||||
type ThresholdWindows struct {
|
||||
RecoveryWindow *string `json:"recovery_window,omitempty"`
|
||||
TriggerWindow *string `json:"trigger_window,omitempty"`
|
||||
}
|
||||
|
||||
type NoDataTimeframe int
|
||||
|
||||
func (tf *NoDataTimeframe) UnmarshalJSON(data []byte) error {
|
||||
s := string(data)
|
||||
if s == "false" || s == "null" {
|
||||
*tf = 0
|
||||
} else {
|
||||
i, err := strconv.ParseInt(s, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*tf = NoDataTimeframe(i)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
NoDataTimeframe NoDataTimeframe `json:"no_data_timeframe,omitempty"`
|
||||
NotifyAudit *bool `json:"notify_audit,omitempty"`
|
||||
NotifyNoData *bool `json:"notify_no_data,omitempty"`
|
||||
RenotifyInterval *int `json:"renotify_interval,omitempty"`
|
||||
NewHostDelay *int `json:"new_host_delay,omitempty"`
|
||||
EvaluationDelay *int `json:"evaluation_delay,omitempty"`
|
||||
Silenced map[string]int `json:"silenced,omitempty"`
|
||||
TimeoutH *int `json:"timeout_h,omitempty"`
|
||||
EscalationMessage *string `json:"escalation_message,omitempty"`
|
||||
Thresholds *ThresholdCount `json:"thresholds,omitempty"`
|
||||
ThresholdWindows *ThresholdWindows `json:"threshold_windows,omitempty"`
|
||||
IncludeTags *bool `json:"include_tags,omitempty"`
|
||||
RequireFullWindow *bool `json:"require_full_window,omitempty"`
|
||||
Locked *bool `json:"locked,omitempty"`
|
||||
EnableLogsSample *bool `json:"enable_logs_sample,omitempty"`
|
||||
QueryConfig *QueryConfig `json:"queryConfig,omitempty"`
|
||||
}
|
||||
|
||||
type TriggeringValue struct {
|
||||
FromTs *int `json:"from_ts,omitempty"`
|
||||
ToTs *int `json:"to_ts,omitempty"`
|
||||
Value *int `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
type GroupData struct {
|
||||
LastNoDataTs *int `json:"last_nodata_ts,omitempty"`
|
||||
LastNotifiedTs *int `json:"last_notified_ts,omitempty"`
|
||||
LastResolvedTs *int `json:"last_resolved_ts,omitempty"`
|
||||
LastTriggeredTs *int `json:"last_triggered_ts,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Status *string `json:"status,omitempty"`
|
||||
TriggeringValue *TriggeringValue `json:"triggering_value,omitempty"`
|
||||
}
|
||||
|
||||
type State struct {
|
||||
Groups map[string]GroupData `json:"groups,omitempty"`
|
||||
}
|
||||
|
||||
// Monitor allows watching a metric or check that you care about,
|
||||
// notifying your team when some defined threshold is exceeded
|
||||
type Monitor struct {
|
||||
Creator *Creator `json:"creator,omitempty"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Query *string `json:"query,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
OverallState *string `json:"overall_state,omitempty"`
|
||||
OverallStateModified *string `json:"overall_state_modified,omitempty"`
|
||||
Tags []string `json:"tags"`
|
||||
Options *Options `json:"options,omitempty"`
|
||||
State State `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
// Creator contains the creator of the monitor
|
||||
type Creator struct {
|
||||
Email *string `json:"email,omitempty"`
|
||||
Handle *string `json:"handle,omitempty"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// MuteMonitorScope specifies which scope to mute and when to end the mute
|
||||
type MuteMonitorScope struct {
|
||||
Scope *string `json:"scope,omitempty"`
|
||||
End *int `json:"end,omitempty"`
|
||||
}
|
||||
|
||||
// UnmuteMonitorScopes specifies which scope(s) to unmute
|
||||
type UnmuteMonitorScopes struct {
|
||||
Scope *string `json:"scope,omitempty"`
|
||||
AllScopes *bool `json:"all_scopes,omitempty"`
|
||||
}
|
||||
|
||||
// reqMonitors receives a slice of all monitors
|
||||
type reqMonitors struct {
|
||||
Monitors []Monitor `json:"monitors,omitempty"`
|
||||
}
|
||||
|
||||
// CreateMonitor adds a new monitor to the system. This returns a pointer to a
|
||||
// monitor so you can pass that to UpdateMonitor later if needed
|
||||
func (client *Client) CreateMonitor(monitor *Monitor) (*Monitor, error) {
|
||||
var out Monitor
|
||||
// TODO: is this more pretty of frowned upon?
|
||||
if err := client.doJsonRequest("POST", "/v1/monitor", monitor, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// UpdateMonitor takes a monitor that was previously retrieved through some method
|
||||
// and sends it back to the server
|
||||
func (client *Client) UpdateMonitor(monitor *Monitor) error {
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/monitor/%d", *monitor.Id),
|
||||
monitor, nil)
|
||||
}
|
||||
|
||||
// GetMonitor retrieves a monitor by identifier
|
||||
func (client *Client) GetMonitor(id int) (*Monitor, error) {
|
||||
var out Monitor
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/monitor/%d", id), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// GetMonitorsByName retrieves monitors by name
|
||||
func (self *Client) GetMonitorsByName(name string) ([]Monitor, error) {
|
||||
var out reqMonitors
|
||||
query, err := url.ParseQuery(fmt.Sprintf("name=%v", name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = self.doJsonRequest("GET", fmt.Sprintf("/v1/monitor?%v", query.Encode()), nil, &out.Monitors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Monitors, nil
|
||||
}
|
||||
|
||||
// GetMonitorsByTags retrieves monitors by a slice of tags
|
||||
func (self *Client) GetMonitorsByTags(tags []string) ([]Monitor, error) {
|
||||
var out reqMonitors
|
||||
query, err := url.ParseQuery(fmt.Sprintf("monitor_tags=%v", strings.Join(tags, ",")))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = self.doJsonRequest("GET", fmt.Sprintf("/v1/monitor?%v", query.Encode()), nil, &out.Monitors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Monitors, nil
|
||||
}
|
||||
|
||||
// DeleteMonitor removes a monitor from the system
|
||||
func (client *Client) DeleteMonitor(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/monitor/%d", id),
|
||||
nil, nil)
|
||||
}
|
||||
|
||||
// GetMonitors returns a slice of all monitors
|
||||
func (client *Client) GetMonitors() ([]Monitor, error) {
|
||||
var out reqMonitors
|
||||
if err := client.doJsonRequest("GET", "/v1/monitor", nil, &out.Monitors); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Monitors, nil
|
||||
}
|
||||
|
||||
// MuteMonitors turns off monitoring notifications
|
||||
func (client *Client) MuteMonitors() error {
|
||||
return client.doJsonRequest("POST", "/v1/monitor/mute_all", nil, nil)
|
||||
}
|
||||
|
||||
// UnmuteMonitors turns on monitoring notifications
|
||||
func (client *Client) UnmuteMonitors() error {
|
||||
return client.doJsonRequest("POST", "/v1/monitor/unmute_all", nil, nil)
|
||||
}
|
||||
|
||||
// MuteMonitor turns off monitoring notifications for a monitor
|
||||
func (client *Client) MuteMonitor(id int) error {
|
||||
return client.doJsonRequest("POST", fmt.Sprintf("/v1/monitor/%d/mute", id), nil, nil)
|
||||
}
|
||||
|
||||
// MuteMonitorScope turns off monitoring notifications for a monitor for a given scope
|
||||
func (client *Client) MuteMonitorScope(id int, muteMonitorScope *MuteMonitorScope) error {
|
||||
return client.doJsonRequest("POST", fmt.Sprintf("/v1/monitor/%d/mute", id), muteMonitorScope, nil)
|
||||
}
|
||||
|
||||
// UnmuteMonitor turns on monitoring notifications for a monitor
|
||||
func (client *Client) UnmuteMonitor(id int) error {
|
||||
return client.doJsonRequest("POST", fmt.Sprintf("/v1/monitor/%d/unmute", id), nil, nil)
|
||||
}
|
||||
|
||||
// UnmuteMonitorScopes is similar to UnmuteMonitor, but provides finer-grained control to unmuting
|
||||
func (client *Client) UnmuteMonitorScopes(id int, unmuteMonitorScopes *UnmuteMonitorScopes) error {
|
||||
return client.doJsonRequest("POST", fmt.Sprintf("/v1/monitor/%d/unmute", id), unmuteMonitorScopes, nil)
|
||||
}
|
||||
213
vendor/github.com/zorkian/go-datadog-api/request.go
generated
vendored
Normal file
213
vendor/github.com/zorkian/go-datadog-api/request.go
generated
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff"
|
||||
)
|
||||
|
||||
// Response contains common fields that might be present in any API response.
|
||||
type Response struct {
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// uriForAPI is to be called with something like "/v1/events" and it will give
|
||||
// the proper request URI to be posted to.
|
||||
func (client *Client) uriForAPI(api string) (string, error) {
|
||||
apiBase, err := url.Parse(client.baseUrl + "/api" + api)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
q := apiBase.Query()
|
||||
q.Add("api_key", client.apiKey)
|
||||
q.Add("application_key", client.appKey)
|
||||
apiBase.RawQuery = q.Encode()
|
||||
return apiBase.String(), nil
|
||||
}
|
||||
|
||||
// redactError removes api and application keys from error strings
|
||||
func (client *Client) redactError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
errString := err.Error()
|
||||
|
||||
if len(client.apiKey) > 0 {
|
||||
errString = strings.Replace(errString, client.apiKey, "redacted", -1)
|
||||
}
|
||||
if len(client.appKey) > 0 {
|
||||
errString = strings.Replace(errString, client.appKey, "redacted", -1)
|
||||
}
|
||||
|
||||
// Return original error if no replacements were made to keep the original,
|
||||
// probably more useful error type information.
|
||||
if errString == err.Error() {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("%s", errString)
|
||||
}
|
||||
|
||||
// doJsonRequest is the simplest type of request: a method on a URI that
|
||||
// returns some JSON result which we unmarshal into the passed interface. It
|
||||
// wraps doJsonRequestUnredacted to redact api and application keys from
|
||||
// errors.
|
||||
func (client *Client) doJsonRequest(method, api string,
|
||||
reqbody, out interface{}) error {
|
||||
if err := client.doJsonRequestUnredacted(method, api, reqbody, out); err != nil {
|
||||
return client.redactError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// doJsonRequestUnredacted is the simplest type of request: a method on a URI that returns
|
||||
// some JSON result which we unmarshal into the passed interface.
|
||||
func (client *Client) doJsonRequestUnredacted(method, api string,
|
||||
reqbody, out interface{}) error {
|
||||
req, err := client.createRequest(method, api, reqbody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Perform the request and retry it if it's not a POST or PUT request
|
||||
var resp *http.Response
|
||||
if method == "POST" || method == "PUT" {
|
||||
resp, err = client.HttpClient.Do(req)
|
||||
} else {
|
||||
resp, err = client.doRequestWithRetries(req, client.RetryTimeout)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("API error %s: %s", resp.Status, body)
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If we got no body, by default let's just make an empty JSON dict. This
|
||||
// saves us some work in other parts of the code.
|
||||
if len(body) == 0 {
|
||||
body = []byte{'{', '}'}
|
||||
}
|
||||
|
||||
// Try to parse common response fields to check whether there's an error reported in a response.
|
||||
var common *Response
|
||||
err = json.Unmarshal(body, &common)
|
||||
if err != nil {
|
||||
// UnmarshalTypeError errors are ignored, because in some cases API response is an array that cannot be
|
||||
// unmarshalled into a struct.
|
||||
_, ok := err.(*json.UnmarshalTypeError)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if common != nil && common.Status == "error" {
|
||||
return fmt.Errorf("API returned error: %s", common.Error)
|
||||
}
|
||||
|
||||
// If they don't care about the body, then we don't care to give them one,
|
||||
// so bail out because we're done.
|
||||
if out == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.Unmarshal(body, &out)
|
||||
}
|
||||
|
||||
// doRequestWithRetries performs an HTTP request repeatedly for maxTime or until
|
||||
// no error and no acceptable HTTP response code was returned.
|
||||
func (client *Client) doRequestWithRetries(req *http.Request, maxTime time.Duration) (*http.Response, error) {
|
||||
var (
|
||||
err error
|
||||
resp *http.Response
|
||||
bo = backoff.NewExponentialBackOff()
|
||||
body []byte
|
||||
)
|
||||
|
||||
bo.MaxElapsedTime = maxTime
|
||||
|
||||
// Save the body for retries
|
||||
if req.Body != nil {
|
||||
body, err = ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
||||
operation := func() error {
|
||||
if body != nil {
|
||||
r := bytes.NewReader(body)
|
||||
req.Body = ioutil.NopCloser(r)
|
||||
}
|
||||
|
||||
resp, err = client.HttpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
// 2xx all done
|
||||
return nil
|
||||
} else if resp.StatusCode >= 400 && resp.StatusCode < 500 {
|
||||
// 4xx are not retryable
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Received HTTP status code %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
err = backoff.Retry(operation, bo)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (client *Client) createRequest(method, api string, reqbody interface{}) (*http.Request, error) {
|
||||
// Handle the body if they gave us one.
|
||||
var bodyReader io.Reader
|
||||
if method != "GET" && reqbody != nil {
|
||||
bjson, err := json.Marshal(reqbody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bodyReader = bytes.NewReader(bjson)
|
||||
}
|
||||
|
||||
apiUrlStr, err := client.uriForAPI(api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := http.NewRequest(method, apiUrlStr, bodyReader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if bodyReader != nil {
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
235
vendor/github.com/zorkian/go-datadog-api/screen_widgets.go
generated
vendored
Normal file
235
vendor/github.com/zorkian/go-datadog-api/screen_widgets.go
generated
vendored
Normal file
@@ -0,0 +1,235 @@
|
||||
package datadog
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type PrecisionT string
|
||||
|
||||
// UnmarshalJSON is a Custom Unmarshal for PrecisionT. The Datadog API can
|
||||
// return 1 (int), "1" (number, but a string type) or something like "100%" or
|
||||
// "*" (string).
|
||||
func (p *PrecisionT) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
var precisionNum json.Number
|
||||
if err = json.Unmarshal(data, &precisionNum); err == nil {
|
||||
*p = PrecisionT(precisionNum)
|
||||
return nil
|
||||
}
|
||||
|
||||
var precisionStr string
|
||||
if err = json.Unmarshal(data, &precisionStr); err == nil {
|
||||
*p = PrecisionT(precisionStr)
|
||||
return nil
|
||||
}
|
||||
|
||||
var p0 PrecisionT
|
||||
*p = p0
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type TileDef struct {
|
||||
Events []TileDefEvent `json:"events,omitempty"`
|
||||
Markers []TileDefMarker `json:"markers,omitempty"`
|
||||
Requests []TileDefRequest `json:"requests,omitempty"`
|
||||
Viz *string `json:"viz,omitempty"`
|
||||
CustomUnit *string `json:"custom_unit,omitempty"`
|
||||
Autoscale *bool `json:"autoscale,omitempty"`
|
||||
Precision *PrecisionT `json:"precision,omitempty"`
|
||||
TextAlign *string `json:"text_align,omitempty"`
|
||||
|
||||
// For hostmap
|
||||
NodeType *string `json:"nodeType,omitempty"`
|
||||
Scope []*string `json:"scope,omitempty"`
|
||||
Group []*string `json:"group,omitempty"`
|
||||
NoGroupHosts *bool `json:"noGroupHosts,omitempty"`
|
||||
NoMetricHosts *bool `json:"noMetricHosts,omitempty"`
|
||||
Style *TileDefStyle `json:"style,omitempty"`
|
||||
}
|
||||
|
||||
type TileDefEvent struct {
|
||||
Query *string `json:"q"`
|
||||
}
|
||||
|
||||
type TileDefMarker struct {
|
||||
Label *string `json:"label,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
type TileDefRequest struct {
|
||||
Query *string `json:"q,omitempty"`
|
||||
|
||||
// For Hostmap
|
||||
Type *string `json:"type,omitempty"`
|
||||
|
||||
// For Process
|
||||
QueryType *string `json:"query_type,omitempty"`
|
||||
Metric *string `json:"metric,omitempty"`
|
||||
TextFilter *string `json:"text_filter,omitempty"`
|
||||
TagFilters []*string `json:"tag_filters"`
|
||||
Limit *int `json:"limit,omitempty"`
|
||||
|
||||
ConditionalFormats []ConditionalFormat `json:"conditional_formats,omitempty"`
|
||||
Style *TileDefRequestStyle `json:"style,omitempty"`
|
||||
Aggregator *string `json:"aggregator,omitempty"`
|
||||
CompareTo *string `json:"compare_to,omitempty"`
|
||||
ChangeType *string `json:"change_type,omitempty"`
|
||||
OrderBy *string `json:"order_by,omitempty"`
|
||||
OrderDir *string `json:"order_dir,omitempty"`
|
||||
ExtraCol *string `json:"extra_col,omitempty"`
|
||||
IncreaseGood *bool `json:"increase_good,omitempty"`
|
||||
Metadata map[string]TileDefMetadata `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
type TileDefMetadata struct {
|
||||
Alias *string `json:"alias,omitempty"`
|
||||
}
|
||||
|
||||
type ConditionalFormat struct {
|
||||
Color *string `json:"color,omitempty"`
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
Comparator *string `json:"comparator,omitempty"`
|
||||
Invert *bool `json:"invert,omitempty"`
|
||||
CustomBgColor *string `json:"custom_bg_color,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
ImageURL *string `json:"image_url,omitempty"`
|
||||
}
|
||||
|
||||
type TileDefRequestStyle struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Width *string `json:"width,omitempty"`
|
||||
}
|
||||
|
||||
type TileDefStyle struct {
|
||||
Palette *string `json:"palette,omitempty"`
|
||||
PaletteFlip *string `json:"paletteFlip,omitempty"`
|
||||
FillMin *json.Number `json:"fillMin,omitempty"`
|
||||
FillMax *json.Number `json:"fillMax,omitempty"`
|
||||
}
|
||||
|
||||
type Time struct {
|
||||
LiveSpan *string `json:"live_span,omitempty"`
|
||||
}
|
||||
|
||||
type Widget struct {
|
||||
// Common attributes
|
||||
Type *string `json:"type,omitempty"`
|
||||
Title *bool `json:"title,omitempty"`
|
||||
TitleText *string `json:"title_text,omitempty"`
|
||||
TitleAlign *string `json:"title_align,omitempty"`
|
||||
TitleSize *int `json:"title_size,omitempty"`
|
||||
Height *int `json:"height,omitempty"`
|
||||
Width *int `json:"width,omitempty"`
|
||||
X *int `json:"x,omitempty"`
|
||||
Y *int `json:"y,omitempty"`
|
||||
|
||||
// For Timeseries, TopList, EventTimeline, EvenStream, AlertGraph, CheckStatus, ServiceSummary, LogStream widgets
|
||||
Time *Time `json:"time,omitempty"`
|
||||
|
||||
// For Timeseries, QueryValue, HostMap, Change, Toplist, Process widgets
|
||||
TileDef *TileDef `json:"tile_def,omitempty"`
|
||||
|
||||
// For FreeText widget
|
||||
Text *string `json:"text,omitempty"`
|
||||
Color *string `json:"color,omitempty"`
|
||||
|
||||
// For AlertValue widget
|
||||
TextSize *string `json:"text_size,omitempty"`
|
||||
Unit *string `json:"unit,omitempty"`
|
||||
Precision *PrecisionT `json:"precision,omitempty"`
|
||||
|
||||
// AlertGraph widget
|
||||
VizType *string `json:"viz_type,omitempty"`
|
||||
|
||||
// For AlertValue, QueryValue, FreeText, Note widgets
|
||||
TextAlign *string `json:"text_align,omitempty"`
|
||||
|
||||
// For FreeText, Note widgets
|
||||
FontSize *string `json:"font_size,omitempty"`
|
||||
|
||||
// For AlertValue, AlertGraph widgets
|
||||
AlertID *int `json:"alert_id,omitempty"`
|
||||
AutoRefresh *bool `json:"auto_refresh,omitempty"`
|
||||
|
||||
// For Timeseries, QueryValue, Toplist widgets
|
||||
Legend *bool `json:"legend,omitempty"`
|
||||
LegendSize *string `json:"legend_size,omitempty"`
|
||||
|
||||
// For EventTimeline, EventStream, Hostmap, LogStream widgets
|
||||
Query *string `json:"query,omitempty"`
|
||||
|
||||
// For Image, IFrame widgets
|
||||
URL *string `json:"url,omitempty"`
|
||||
|
||||
// For CheckStatus widget
|
||||
Tags []*string `json:"tags,omitempty"`
|
||||
Check *string `json:"check,omitempty"`
|
||||
Grouping *string `json:"grouping,omitempty"`
|
||||
GroupBy []*string `json:"group_by,omitempty"`
|
||||
Group *string `json:"group,omitempty"`
|
||||
|
||||
// Note widget
|
||||
TickPos *string `json:"tick_pos,omitempty"`
|
||||
TickEdge *string `json:"tick_edge,omitempty"`
|
||||
HTML *string `json:"html,omitempty"`
|
||||
Tick *bool `json:"tick,omitempty"`
|
||||
Bgcolor *string `json:"bgcolor,omitempty"`
|
||||
|
||||
// EventStream widget
|
||||
EventSize *string `json:"event_size,omitempty"`
|
||||
|
||||
// Image widget
|
||||
Sizing *string `json:"sizing,omitempty"`
|
||||
Margin *string `json:"margin,omitempty"`
|
||||
|
||||
// For ServiceSummary (trace_service) widget
|
||||
Env *string `json:"env,omitempty"`
|
||||
ServiceService *string `json:"serviceService,omitempty"`
|
||||
ServiceName *string `json:"serviceName,omitempty"`
|
||||
SizeVersion *string `json:"sizeVersion,omitempty"`
|
||||
LayoutVersion *string `json:"layoutVersion,omitempty"`
|
||||
MustShowHits *bool `json:"mustShowHits,omitempty"`
|
||||
MustShowErrors *bool `json:"mustShowErrors,omitempty"`
|
||||
MustShowLatency *bool `json:"mustShowLatency,omitempty"`
|
||||
MustShowBreakdown *bool `json:"mustShowBreakdown,omitempty"`
|
||||
MustShowDistribution *bool `json:"mustShowDistribution,omitempty"`
|
||||
MustShowResourceList *bool `json:"mustShowResourceList,omitempty"`
|
||||
|
||||
// For MonitorSummary (manage_status) widget
|
||||
DisplayFormat *string `json:"displayFormat,omitempty"`
|
||||
ColorPreference *string `json:"colorPreference,omitempty"`
|
||||
HideZeroCounts *bool `json:"hideZeroCounts,omitempty"`
|
||||
ManageStatusShowTitle *bool `json:"showTitle,omitempty"`
|
||||
ManageStatusTitleText *string `json:"titleText,omitempty"`
|
||||
ManageStatusTitleSize *string `json:"titleSize,omitempty"`
|
||||
ManageStatusTitleAlign *string `json:"titleAlign,omitempty"`
|
||||
Params *Params `json:"params,omitempty"`
|
||||
|
||||
// For LogStream widget
|
||||
Columns *string `json:"columns,omitempty"`
|
||||
Logset *string `json:"logset,omitempty"`
|
||||
|
||||
// For Uptime
|
||||
// Widget is undocumented, subject to breaking API changes, and without customer support
|
||||
Timeframes []*string `json:"timeframes,omitempty"`
|
||||
Rules map[string]*Rule `json:"rules,omitempty"`
|
||||
Monitor *ScreenboardMonitor `json:"monitor,omitempty"`
|
||||
}
|
||||
|
||||
type Params struct {
|
||||
Sort *string `json:"sort,omitempty"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
Count *string `json:"count,omitempty"`
|
||||
Start *string `json:"start,omitempty"`
|
||||
}
|
||||
|
||||
type Rule struct {
|
||||
Threshold *json.Number `json:"threshold,omitempty"`
|
||||
Timeframe *string `json:"timeframe,omitempty"`
|
||||
Color *string `json:"color,omitempty"`
|
||||
}
|
||||
|
||||
type ScreenboardMonitor struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
}
|
||||
99
vendor/github.com/zorkian/go-datadog-api/screenboards.go
generated
vendored
Normal file
99
vendor/github.com/zorkian/go-datadog-api/screenboards.go
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Screenboard represents a user created screenboard. This is the full screenboard
|
||||
// struct when we load a screenboard in detail.
|
||||
type Screenboard struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
NewId *string `json:"new_id,omitempty"`
|
||||
Title *string `json:"board_title,omitempty"`
|
||||
Height *int `json:"height,omitempty"`
|
||||
Width *int `json:"width,omitempty"`
|
||||
Shared *bool `json:"shared,omitempty"`
|
||||
TemplateVariables []TemplateVariable `json:"template_variables,omitempty"`
|
||||
Widgets []Widget `json:"widgets"`
|
||||
ReadOnly *bool `json:"read_only,omitempty"`
|
||||
}
|
||||
|
||||
// ScreenboardLite represents a user created screenboard. This is the mini
|
||||
// struct when we load the summaries.
|
||||
type ScreenboardLite struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Resource *string `json:"resource,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
// reqGetScreenboards from /api/v1/screen
|
||||
type reqGetScreenboards struct {
|
||||
Screenboards []*ScreenboardLite `json:"screenboards,omitempty"`
|
||||
}
|
||||
|
||||
// GetScreenboard returns a single screenboard created on this account.
|
||||
func (client *Client) GetScreenboard(id interface{}) (*Screenboard, error) {
|
||||
stringId, err := GetStringId(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := &Screenboard{}
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/screen/%s", stringId), nil, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GetScreenboards returns a list of all screenboards created on this account.
|
||||
func (client *Client) GetScreenboards() ([]*ScreenboardLite, error) {
|
||||
var out reqGetScreenboards
|
||||
if err := client.doJsonRequest("GET", "/v1/screen", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Screenboards, nil
|
||||
}
|
||||
|
||||
// DeleteScreenboard deletes a screenboard by the identifier.
|
||||
func (client *Client) DeleteScreenboard(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/screen/%d", id), nil, nil)
|
||||
}
|
||||
|
||||
// CreateScreenboard creates a new screenboard when given a Screenboard struct. Note
|
||||
// that the Id, Resource, Url and similar elements are not used in creation.
|
||||
func (client *Client) CreateScreenboard(board *Screenboard) (*Screenboard, error) {
|
||||
out := &Screenboard{}
|
||||
if err := client.doJsonRequest("POST", "/v1/screen", board, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UpdateScreenboard in essence takes a Screenboard struct and persists it back to
|
||||
// the server. Use this if you've updated your local and need to push it back.
|
||||
func (client *Client) UpdateScreenboard(board *Screenboard) error {
|
||||
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/screen/%d", *board.Id), board, nil)
|
||||
}
|
||||
|
||||
type ScreenShareResponse struct {
|
||||
BoardId int `json:"board_id"`
|
||||
PublicUrl string `json:"public_url"`
|
||||
}
|
||||
|
||||
// ShareScreenboard shares an existing screenboard, it takes and updates ScreenShareResponse
|
||||
func (client *Client) ShareScreenboard(id int, response *ScreenShareResponse) error {
|
||||
return client.doJsonRequest("POST", fmt.Sprintf("/v1/screen/share/%d", id), nil, response)
|
||||
}
|
||||
|
||||
// RevokeScreenboard revokes a currently shared screenboard
|
||||
func (client *Client) RevokeScreenboard(id int) error {
|
||||
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/screen/share/%d", id), nil, nil)
|
||||
}
|
||||
35
vendor/github.com/zorkian/go-datadog-api/search.go
generated
vendored
Normal file
35
vendor/github.com/zorkian/go-datadog-api/search.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
// reqSearch is the container for receiving search results.
|
||||
type reqSearch struct {
|
||||
Results struct {
|
||||
Hosts []string `json:"hosts,omitempty"`
|
||||
Metrics []string `json:"metrics,omitempty"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
// SearchHosts searches through the hosts facet, returning matching hostnames.
|
||||
func (client *Client) SearchHosts(search string) ([]string, error) {
|
||||
var out reqSearch
|
||||
if err := client.doJsonRequest("GET", "/v1/search?q=hosts:"+search, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Results.Hosts, nil
|
||||
}
|
||||
|
||||
// SearchMetrics searches through the metrics facet, returning matching ones.
|
||||
func (client *Client) SearchMetrics(search string) ([]string, error) {
|
||||
var out reqSearch
|
||||
if err := client.doJsonRequest("GET", "/v1/search?q=metrics:"+search, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Results.Metrics, nil
|
||||
}
|
||||
91
vendor/github.com/zorkian/go-datadog-api/series.go
generated
vendored
Normal file
91
vendor/github.com/zorkian/go-datadog-api/series.go
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// DataPoint is a tuple of [UNIX timestamp, value]. This has to use floats
|
||||
// because the value could be non-integer.
|
||||
type DataPoint [2]*float64
|
||||
|
||||
// Metric represents a collection of data points that we might send or receive
|
||||
// on one single metric line.
|
||||
type Metric struct {
|
||||
Metric *string `json:"metric,omitempty"`
|
||||
Points []DataPoint `json:"points,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Host *string `json:"host,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Unit *string `json:"unit,omitempty"`
|
||||
}
|
||||
|
||||
// Unit represents a unit definition that we might receive when query for timeseries data.
|
||||
type Unit struct {
|
||||
Family string `json:"family"`
|
||||
ScaleFactor float32 `json:"scale_factor"`
|
||||
Name string `json:"name"`
|
||||
ShortName string `json:"short_name"`
|
||||
Plural string `json:"plural"`
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
// A Series is characterized by 2 units as: x per y
|
||||
// One or both could be missing
|
||||
type UnitPair []*Unit
|
||||
|
||||
// Series represents a collection of data points we get when we query for timeseries data
|
||||
type Series struct {
|
||||
Metric *string `json:"metric,omitempty"`
|
||||
DisplayName *string `json:"display_name,omitempty"`
|
||||
Points []DataPoint `json:"pointlist,omitempty"`
|
||||
Start *float64 `json:"start,omitempty"`
|
||||
End *float64 `json:"end,omitempty"`
|
||||
Interval *int `json:"interval,omitempty"`
|
||||
Aggr *string `json:"aggr,omitempty"`
|
||||
Length *int `json:"length,omitempty"`
|
||||
Scope *string `json:"scope,omitempty"`
|
||||
Expression *string `json:"expression,omitempty"`
|
||||
Units *UnitPair `json:"unit,omitempty"`
|
||||
}
|
||||
|
||||
// reqPostSeries from /api/v1/series
|
||||
type reqPostSeries struct {
|
||||
Series []Metric `json:"series,omitempty"`
|
||||
}
|
||||
|
||||
// reqMetrics is the container for receiving metric results.
|
||||
type reqMetrics struct {
|
||||
Series []Series `json:"series,omitempty"`
|
||||
}
|
||||
|
||||
// PostMetrics takes as input a slice of metrics and then posts them up to the
|
||||
// server for posting data.
|
||||
func (client *Client) PostMetrics(series []Metric) error {
|
||||
return client.doJsonRequest("POST", "/v1/series",
|
||||
reqPostSeries{Series: series}, nil)
|
||||
}
|
||||
|
||||
// QueryMetrics takes as input from, to (seconds from Unix Epoch) and query string and then requests
|
||||
// timeseries data for that time peried
|
||||
func (client *Client) QueryMetrics(from, to int64, query string) ([]Series, error) {
|
||||
v := url.Values{}
|
||||
v.Add("from", strconv.FormatInt(from, 10))
|
||||
v.Add("to", strconv.FormatInt(to, 10))
|
||||
v.Add("query", query)
|
||||
|
||||
var out reqMetrics
|
||||
err := client.doJsonRequest("GET", "/v1/query?"+v.Encode(), nil, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Series, nil
|
||||
}
|
||||
45
vendor/github.com/zorkian/go-datadog-api/snapshot.go
generated
vendored
Normal file
45
vendor/github.com/zorkian/go-datadog-api/snapshot.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2016 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (client *Client) doSnapshotRequest(values url.Values) (string, error) {
|
||||
out := struct {
|
||||
SnapshotURL string `json:"snapshot_url,omitempty"`
|
||||
}{}
|
||||
if err := client.doJsonRequest("GET", "/v1/graph/snapshot?"+values.Encode(), nil, &out); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return out.SnapshotURL, nil
|
||||
}
|
||||
|
||||
// Snapshot creates an image from a graph and returns the URL of the image.
|
||||
func (client *Client) Snapshot(query string, start, end time.Time, eventQuery string) (string, error) {
|
||||
options := map[string]string{"metric_query": query, "event_query": eventQuery}
|
||||
|
||||
return client.SnapshotGeneric(options, start, end)
|
||||
}
|
||||
|
||||
// Generic function for snapshots, use map[string]string to create url.Values() instead of pre-defined params
|
||||
func (client *Client) SnapshotGeneric(options map[string]string, start, end time.Time) (string, error) {
|
||||
v := url.Values{}
|
||||
v.Add("start", fmt.Sprintf("%d", start.Unix()))
|
||||
v.Add("end", fmt.Sprintf("%d", end.Unix()))
|
||||
|
||||
for opt, val := range options {
|
||||
v.Add(opt, val)
|
||||
}
|
||||
|
||||
return client.doSnapshotRequest(v)
|
||||
}
|
||||
198
vendor/github.com/zorkian/go-datadog-api/synthetics.go
generated
vendored
Normal file
198
vendor/github.com/zorkian/go-datadog-api/synthetics.go
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// SyntheticsTest represents a synthetics test, either api or browser
|
||||
type SyntheticsTest struct {
|
||||
PublicId *string `json:"public_id,omitempty"`
|
||||
MonitorId *int `json:"monitor_id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Tags []string `json:"tags"`
|
||||
CreatedAt *string `json:"created_at,omitempty"`
|
||||
ModifiedAt *string `json:"modified_at,omitempty"`
|
||||
DeletedAt *string `json:"deleted_at,omitempty"`
|
||||
Config *SyntheticsConfig `json:"config,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
Options *SyntheticsOptions `json:"options,omitempty"`
|
||||
Locations []string `json:"locations,omitempty"`
|
||||
CreatedBy *SyntheticsUser `json:"created_by,omitempty"`
|
||||
ModifiedBy *SyntheticsUser `json:"modified_by,omitempty"`
|
||||
Status *string `json:"status,omitempty"`
|
||||
MonitorStatus *string `json:"monitor_status,omitempty"`
|
||||
}
|
||||
|
||||
type SyntheticsConfig struct {
|
||||
Request *SyntheticsRequest `json:"request,omitempty"`
|
||||
Assertions []SyntheticsAssertion `json:"assertions,omitempty"`
|
||||
Variables []interface{} `json:"variables,omitempty"`
|
||||
}
|
||||
|
||||
type SyntheticsRequest struct {
|
||||
Url *string `json:"url,omitempty"`
|
||||
Method *string `json:"method,omitempty"`
|
||||
Timeout *int `json:"timeout,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
Body *string `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
type SyntheticsAssertion struct {
|
||||
Operator *string `json:"operator,omitempty"`
|
||||
Property *string `json:"property,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
// sometimes target is string ( like "text/html; charset=UTF-8" for header content-type )
|
||||
// and sometimes target is int ( like 1200 for responseTime, 200 for statusCode )
|
||||
Target interface{} `json:"target,omitempty"`
|
||||
}
|
||||
|
||||
type SyntheticsOptions struct {
|
||||
TickEvery *int `json:"tick_every,omitempty"`
|
||||
FollowRedirects *bool `json:"follow_redirects,omitempty"`
|
||||
MinFailureDuration *int `json:"min_failure_duration,omitempty"`
|
||||
MinLocationFailed *int `json:"min_location_failed,omitempty"`
|
||||
DeviceIds []string `json:"device_ids,omitempty"`
|
||||
}
|
||||
|
||||
type SyntheticsUser struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Email *string `json:"email,omitempty"`
|
||||
Handle *string `json:"handle,omitempty"`
|
||||
}
|
||||
|
||||
type SyntheticsDevice struct {
|
||||
Id *string `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Height *int `json:"height,omitempty"`
|
||||
Width *int `json:"width,omitempty"`
|
||||
IsLandscape *bool `json:"isLandscape,omitempty"`
|
||||
IsMobile *bool `json:"isMobile,omitempty"`
|
||||
UserAgent *string `json:"userAgent,omitempty"`
|
||||
}
|
||||
|
||||
type SyntheticsLocation struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
DisplayName *string `json:"display_name,omitempty"`
|
||||
Region *string `json:"region,omitempty"`
|
||||
IsLandscape *bool `json:"is_active,omitempty"`
|
||||
}
|
||||
|
||||
type ToggleStatus struct {
|
||||
NewStatus *string `json:"new_status,omitempty"`
|
||||
}
|
||||
|
||||
// GetSyntheticsTests get all tests of type API
|
||||
func (client *Client) GetSyntheticsTests() ([]SyntheticsTest, error) {
|
||||
var out struct {
|
||||
SyntheticsTests []SyntheticsTest `json:"tests,omitempty"`
|
||||
}
|
||||
if err := client.doJsonRequest("GET", "/v1/synthetics/tests", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.SyntheticsTests, nil
|
||||
}
|
||||
|
||||
// GetSyntheticsTestsByType get all tests by type (e.g. api or browser)
|
||||
func (client *Client) GetSyntheticsTestsByType(testType string) ([]SyntheticsTest, error) {
|
||||
var out struct {
|
||||
SyntheticsTests []SyntheticsTest `json:"tests,omitempty"`
|
||||
}
|
||||
query, err := url.ParseQuery(fmt.Sprintf("type=%v", testType))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/synthetics/tests?%v", query.Encode()), nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.SyntheticsTests, nil
|
||||
}
|
||||
|
||||
// GetSyntheticsTest get test by public id
|
||||
func (client *Client) GetSyntheticsTest(publicId string) (*SyntheticsTest, error) {
|
||||
var out SyntheticsTest
|
||||
if err := client.doJsonRequest("GET", "/v1/synthetics/tests/"+publicId, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// CreateSyntheticsTest creates a test
|
||||
func (client *Client) CreateSyntheticsTest(syntheticsTest *SyntheticsTest) (*SyntheticsTest, error) {
|
||||
var out SyntheticsTest
|
||||
if err := client.doJsonRequest("POST", "/v1/synthetics/tests", syntheticsTest, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// UpdateSyntheticsTest updates a test
|
||||
func (client *Client) UpdateSyntheticsTest(publicId string, syntheticsTest *SyntheticsTest) (*SyntheticsTest, error) {
|
||||
var out SyntheticsTest
|
||||
if err := client.doJsonRequest("PUT", fmt.Sprintf("/v1/synthetics/tests/%s", publicId), syntheticsTest, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// PauseSyntheticsTest set a test status to live
|
||||
func (client *Client) PauseSyntheticsTest(publicId string) (*bool, error) {
|
||||
payload := ToggleStatus{NewStatus: String("paused")}
|
||||
out := Bool(false)
|
||||
if err := client.doJsonRequest("PUT", fmt.Sprintf("/v1/synthetics/tests/%s/status", publicId), &payload, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ResumeSyntheticsTest set a test status to live
|
||||
func (client *Client) ResumeSyntheticsTest(publicId string) (*bool, error) {
|
||||
payload := ToggleStatus{NewStatus: String("live")}
|
||||
out := Bool(false)
|
||||
if err := client.doJsonRequest("PUT", fmt.Sprintf("/v1/synthetics/tests/%s/status", publicId), &payload, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// string array of public_id
|
||||
type DeleteSyntheticsTestsPayload struct {
|
||||
PublicIds []string `json:"public_ids,omitempty"`
|
||||
}
|
||||
|
||||
// DeleteSyntheticsTests deletes tests
|
||||
func (client *Client) DeleteSyntheticsTests(publicIds []string) error {
|
||||
req := DeleteSyntheticsTestsPayload{
|
||||
PublicIds: publicIds,
|
||||
}
|
||||
if err := client.doJsonRequest("POST", "/v1/synthetics/tests/delete", req, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSyntheticsLocations get all test locations
|
||||
func (client *Client) GetSyntheticsLocations() ([]SyntheticsLocation, error) {
|
||||
var out struct {
|
||||
Locations []SyntheticsLocation `json:"locations,omitempty"`
|
||||
}
|
||||
if err := client.doJsonRequest("GET", "/v1/synthetics/locations", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Locations, nil
|
||||
}
|
||||
|
||||
// GetSyntheticsBrowserDevices get all test devices (for browser)
|
||||
func (client *Client) GetSyntheticsBrowserDevices() ([]SyntheticsDevice, error) {
|
||||
var out struct {
|
||||
Devices []SyntheticsDevice `json:"devices,omitempty"`
|
||||
}
|
||||
|
||||
if err := client.doJsonRequest("GET", "/v1/synthetics/browser/devices", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Devices, nil
|
||||
}
|
||||
93
vendor/github.com/zorkian/go-datadog-api/tags.go
generated
vendored
Normal file
93
vendor/github.com/zorkian/go-datadog-api/tags.go
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
// TagMap is used to receive the format given to us by the API.
|
||||
type TagMap map[string][]string
|
||||
|
||||
// reqGetTags is the container for receiving tags.
|
||||
type reqGetTags struct {
|
||||
Tags *TagMap `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
// regGetHostTags is for receiving a slice of tags.
|
||||
type reqGetHostTags struct {
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
// GetTags returns a map of tags.
|
||||
func (client *Client) GetTags(source string) (TagMap, error) {
|
||||
var out reqGetTags
|
||||
uri := "/v1/tags/hosts"
|
||||
if source != "" {
|
||||
uri += "?source=" + source
|
||||
}
|
||||
if err := client.doJsonRequest("GET", uri, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *out.Tags, nil
|
||||
}
|
||||
|
||||
// GetHostTags returns a slice of tags for a given host and source.
|
||||
func (client *Client) GetHostTags(host, source string) ([]string, error) {
|
||||
var out reqGetHostTags
|
||||
uri := "/v1/tags/hosts/" + host
|
||||
if source != "" {
|
||||
uri += "?source=" + source
|
||||
}
|
||||
if err := client.doJsonRequest("GET", uri, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Tags, nil
|
||||
}
|
||||
|
||||
// GetHostTagsBySource is a different way of viewing the tags. It returns a map
|
||||
// of source:[tag,tag].
|
||||
func (client *Client) GetHostTagsBySource(host, source string) (TagMap, error) {
|
||||
var out reqGetTags
|
||||
uri := "/v1/tags/hosts/" + host + "?by_source=true"
|
||||
if source != "" {
|
||||
uri += "&source=" + source
|
||||
}
|
||||
if err := client.doJsonRequest("GET", uri, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *out.Tags, nil
|
||||
}
|
||||
|
||||
// AddTagsToHost does exactly what it says on the tin. Given a list of tags,
|
||||
// add them to the host. The source is optionally specified, and defaults to
|
||||
// "users" as per the API documentation.
|
||||
func (client *Client) AddTagsToHost(host, source string, tags []string) error {
|
||||
uri := "/v1/tags/hosts/" + host
|
||||
if source != "" {
|
||||
uri += "?source=" + source
|
||||
}
|
||||
return client.doJsonRequest("POST", uri, reqGetHostTags{Tags: tags}, nil)
|
||||
}
|
||||
|
||||
// UpdateHostTags overwrites existing tags for a host, allowing you to specify
|
||||
// a new set of tags for the given source. This defaults to "users".
|
||||
func (client *Client) UpdateHostTags(host, source string, tags []string) error {
|
||||
uri := "/v1/tags/hosts/" + host
|
||||
if source != "" {
|
||||
uri += "?source=" + source
|
||||
}
|
||||
return client.doJsonRequest("PUT", uri, reqGetHostTags{Tags: tags}, nil)
|
||||
}
|
||||
|
||||
// RemoveHostTags removes all tags from a host for the given source. If none is
|
||||
// given, the API defaults to "users".
|
||||
func (client *Client) RemoveHostTags(host, source string) error {
|
||||
uri := "/v1/tags/hosts/" + host
|
||||
if source != "" {
|
||||
uri += "?source=" + source
|
||||
}
|
||||
return client.doJsonRequest("DELETE", uri, nil, nil)
|
||||
}
|
||||
95
vendor/github.com/zorkian/go-datadog-api/users.go
generated
vendored
Normal file
95
vendor/github.com/zorkian/go-datadog-api/users.go
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Datadog API for Go
|
||||
*
|
||||
* Please see the included LICENSE file for licensing information.
|
||||
*
|
||||
* Copyright 2013 by authors and contributors.
|
||||
*/
|
||||
|
||||
package datadog
|
||||
|
||||
type User struct {
|
||||
Handle *string `json:"handle,omitempty"`
|
||||
Email *string `json:"email,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Role *string `json:"role,omitempty"`
|
||||
AccessRole *string `json:"access_role,omitempty"`
|
||||
Verified *bool `json:"verified,omitempty"`
|
||||
Disabled *bool `json:"disabled,omitempty"`
|
||||
|
||||
// DEPRECATED: IsAdmin is deprecated and will be removed in the next major
|
||||
// revision. For more info on why it is being removed, see discussion on
|
||||
// https://github.com/zorkian/go-datadog-api/issues/126.
|
||||
IsAdmin *bool `json:"is_admin,omitempty"`
|
||||
}
|
||||
|
||||
// reqInviteUsers contains email addresses to send invitations to.
|
||||
type reqInviteUsers struct {
|
||||
Emails []string `json:"emails,omitempty"`
|
||||
}
|
||||
|
||||
// InviteUsers takes a slice of email addresses and sends invitations to them.
|
||||
func (client *Client) InviteUsers(emails []string) error {
|
||||
return client.doJsonRequest("POST", "/v1/invite_users",
|
||||
reqInviteUsers{Emails: emails}, nil)
|
||||
}
|
||||
|
||||
// CreateUser creates an user account for an email address
|
||||
func (self *Client) CreateUser(handle, name *string) (*User, error) {
|
||||
in := struct {
|
||||
Handle *string `json:"handle"`
|
||||
Name *string `json:"name"`
|
||||
}{
|
||||
Handle: handle,
|
||||
Name: name,
|
||||
}
|
||||
|
||||
out := struct {
|
||||
*User `json:"user"`
|
||||
}{}
|
||||
if err := self.doJsonRequest("POST", "/v1/user", in, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.User, nil
|
||||
}
|
||||
|
||||
// internal type to retrieve users from the api
|
||||
type usersData struct {
|
||||
Users []User `json:"users,omitempty"`
|
||||
}
|
||||
|
||||
// GetUsers returns all user, or an error if not found
|
||||
func (client *Client) GetUsers() (users []User, err error) {
|
||||
var udata usersData
|
||||
uri := "/v1/user"
|
||||
err = client.doJsonRequest("GET", uri, nil, &udata)
|
||||
users = udata.Users
|
||||
return
|
||||
}
|
||||
|
||||
// internal type to retrieve single user from the api
|
||||
type userData struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
|
||||
// GetUser returns the user that match a handle, or an error if not found
|
||||
func (client *Client) GetUser(handle string) (user User, err error) {
|
||||
var udata userData
|
||||
uri := "/v1/user/" + handle
|
||||
err = client.doJsonRequest("GET", uri, nil, &udata)
|
||||
user = udata.User
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateUser updates a user with the content of `user`,
|
||||
// and returns an error if the update failed
|
||||
func (client *Client) UpdateUser(user User) error {
|
||||
uri := "/v1/user/" + *user.Handle
|
||||
return client.doJsonRequest("PUT", uri, user, nil)
|
||||
}
|
||||
|
||||
// DeleteUser deletes a user and returns an error if deletion failed
|
||||
func (client *Client) DeleteUser(handle string) error {
|
||||
uri := "/v1/user/" + handle
|
||||
return client.doJsonRequest("DELETE", uri, nil, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user