• Stars
    star
    183
  • Rank 208,931 (Top 5 %)
  • Language
    Go
  • License
    BSD 3-Clause "New...
  • Created about 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Go implementation of the Datadog API.

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-2019 by authors and contributors.

More Repositories

1

nagios-api

A REST-like, JSON interface to Nagios
Python
586
star
2

lca2015

linux.conf.au 2015 tutorial on Building Services in Go
HTML
180
star
3

mysql-sniffer

MySQL Query Sniffer
Go
101
star
4

marshal

A Kafka consumer coordination library for Go.
Go
33
star
5

nagios-plugins

Mark's Nagios Plugins: various plugins and checkers I've written.
Python
19
star
6

distributor

File distribution.
Go
12
star
7

riak-sniffer

A request sniffer for Riak's protobufs.
Go
10
star
8

dtorrent

Enhanced CTorrent
C++
7
star
9

lca2014

Code from my Introduction to Go tutorial at LCA2014.
Go
7
star
10

singularity

A cluster management tool for Linux servers.
Go
5
star
11

downpour

Perl BitTorrent Modules
Perl
4
star
12

nagios-irc-bot

IRC bot for Nagios
Perl
3
star
13

aurora

A simple blogging engine powered by git.
Python
3
star
14

nagios-generator

Nagios config generator.
Python
3
star
15

portal

A set of utilities for building portals in Kafka.
Go
2
star
16

Backend-Status

Determine the status of your Apache backends (requires Perlbal frontend).
Go
2
star
17

acron

A Cron replacement written in Python
Python
2
star
18

fortissimo

PHP killboard for EVE Online
PHP
2
star
19

http-headerparser-xs

HTTP::HeaderParser::XS Perl module
C
1
star
20

rcfiles

Maintaining my RC files...
Shell
1
star
21

eveapi

EVE Online API Perl module
Perl
1
star
22

sds

Simple (JSON) Document Storage
Python
1
star
23

cascade

Work in progress.
Python
1
star
24

rediprox

Caching, sharding Redis proxy
Rust
1
star
25

dw-docker

ApacheConf
1
star
26

proximo

Perl Proxy for MySQL
Perl
1
star
27

lifewiki

LifeWiki, a Mason/Perl based wiki
Perl
1
star
28

flow

Don't even look yet...
Python
1
star