A Go implementation of the Datadog API.
Clone or download
nyanshak Merge pull request #187 from nyanshak/more-yaxis-fields
Add support for units and includeZero in Yaxis
Latest commit f3f6d2f Nov 12, 2018
Permalink
Failed to load latest commit information.
cmd/tools correct comment in getter generation template Oct 9, 2018
integration Bugfix fix screenboard (#190) Nov 3, 2018
scripts assert gofmt agrees Oct 9, 2018
tests/fixtures Bugfix fix screenboard (#190) Nov 3, 2018
vendor Update Testify to use "ElementsMatch" feature Jun 25, 2018
.gitignore Initial commit Aug 10, 2013
.travis.yml Add 1.11 to Travis build Oct 31, 2018
LICENSE Initial commit Aug 10, 2013
Makefile Generate accessors. Feb 16, 2017
README.md Support dashboard lists May 11, 2018
alerts.go GH-56: Refactor to use pointers for all fields. Adds a few helpers to… Jan 27, 2017
checks.go Make use of omitempty consistent accross all types. Jan 31, 2017
checks_test.go Add support for checks API Mar 2, 2016
client.go Add retry logic to client's Validate method (#150) Apr 18, 2018
comments.go Add backwards-compatible fix to make handle optional (#143) Mar 5, 2018
dashboard_lists.go Clean up docstrings for dashboard lists May 11, 2018
dashboards.go Add support for units and includeZero in Yaxis Oct 25, 2018
dashboards_test.go Add support for units and includeZero in Yaxis Oct 25, 2018
datadog-accessors.go Merge pull request #187 from nyanshak/more-yaxis-fields Nov 12, 2018
downtimes.go Add MonitorId to Downtime Apr 6, 2017
events.go GH-56: Refactor to use pointers for all fields. Adds a few helpers to… Jan 27, 2017
generate.go Move generate comments to generate.go, renamed generation source file… Feb 16, 2017
helper_test.go Generate accessors. Feb 16, 2017
helpers.go Move generate comments to generate.go, renamed generation source file… Feb 16, 2017
hosts.go hosts: Add Host Muting/Unmuting capability (#123) Oct 24, 2017
integrations.go Fix comments and add "omitempty" to HostFilters' json tag Oct 17, 2018
metric_metadata.go metrics metadata: fix statsd interval to be an int (#117) Aug 30, 2017
monitors.go Add ThresholdWindows option to Datadog monitors (#188) Nov 3, 2018
monitors_test.go Add even more status deserialization from datadog Oct 4, 2018
request.go Propagate errors from JSON response Sep 25, 2018
request_test.go Propagate errors from JSON response Sep 25, 2018
screen_widgets.go Bugfix fix screenboard (#190) Nov 3, 2018
screenboards.go Bugfix fix screenboard (#190) Nov 3, 2018
screenboards_test.go Bugfix fix screenboard (#190) Nov 3, 2018
search.go Refactor receiver names to be a reflection of their identity. Check i… Dec 6, 2016
series.go Add even more status deserialization from datadog Oct 4, 2018
snapshot.go use map[string]string to pass query options for snapshot (#110) Aug 27, 2017
tags.go GH-56: Refactor to use pointers for all fields. Adds a few helpers to… Jan 27, 2017
users.go Replace `is_admin` with `access_role` (#127) Jan 1, 2018

README.md

GoDoc License Build status Go Report Card

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:

    import "github.com/zorkian/go-datadog-api"

Or, if you need to control which version to use, import using gopkg.in. Like so:

    import "gopkg.in/zorkian/go-datadog-api.v2"

Using go get:

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:

    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:

	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:

	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:

make generate

COPYRIGHT AND LICENSE

Please see the LICENSE file for the included license information.

Copyright 2013-2017 by authors and contributors.