Created
September 19, 2017 04:44
-
-
Save gnilchee/4ea98850bdc0acd11c63f2c8421c21a9 to your computer and use it in GitHub Desktop.
A few examples of different calls using zorkian's go datadog api library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"log" | |
"gopkg.in/zorkian/go-datadog-api.v2" | |
) | |
func main() { | |
// Get api and app key from environment var | |
api_key := os.Getenv("DG_API_KEY") | |
app_key := os.Getenv("DG_APP_KEY") | |
// Get all downtimes | |
client := datadog.NewClient(api_key, app_key) | |
downtime, err := client.GetDowntimes() | |
if err != nil { | |
log.Fatalf("%s\n", err) | |
} | |
for _, v := range downtime { | |
if *v.Active == true { | |
log.Printf("active downtime: %s\n", v.Scope) | |
} | |
} | |
// search host by query "httpbin" | |
hosts, err := client.SearchHosts("httpbin") | |
if err != nil { | |
log.Fatalf("%v\n", err) | |
} | |
for _, h := range hosts { | |
log.Printf("Search result: %s", h) | |
} | |
// Get tags by host "httpbin.org", source = "" | |
tags, err := client.GetHostTags("httpbin.org", "") | |
if err != nil { | |
log.Fatalf("%v\n", err) | |
} | |
log.Printf("Tags for requested host: %s", tags) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment