Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

region configuration added to support the datadog .eu domain #2

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ You can use events to notify something bad happened:
- failure
```

You can change the datadog site region to EU (com is default)

```yml
- name: notify-pipeline
image: masci/drone-datadog
settings:
region: eu
api_key:
from_secret: datadog_api_key
events:
- title: "Build failure"
text: "Build ${DRONE_BUILD_NUMBER} has failed"
alert_type: "error"
when:
status:
- failure
```

You can look at [this repo .drone.yml](.drone.yml) file for a real world example.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
type Config struct {
APIKey string
DryRun bool
Region string
}

// Metric represents a point that'll be sent to Datadog
Expand Down Expand Up @@ -97,12 +98,17 @@ func parseConfig() (*Config, error) {
cfg := &Config{
APIKey: os.Getenv("PLUGIN_API_KEY"),
DryRun: os.Getenv("PLUGIN_DRY_RUN") == "true",
Region: os.Getenv("PLUGIN_REGION"),
}

if cfg.APIKey == "" && !cfg.DryRun {
return nil, fmt.Errorf("Datadog API Key is missing")
}

if cfg.Region == "" && !cfg.DryRun {
cfg.Region = "com"
}

return cfg, nil
}

Expand Down Expand Up @@ -190,7 +196,7 @@ func main() {
if err != nil {
log.Printf("error encoding metrics: %v", err)
} else {
url := fmt.Sprintf("https://api.datadoghq.com/api/v1/series?api_key=%s", cfg.APIKey)
url := fmt.Sprintf("https://api.datadoghq.%s/api/v1/series?api_key=%s", cfg.Region, cfg.APIKey)
if err := send(url, payload, cfg.DryRun); err != nil {
log.Fatalf("unable to send metrics: %v", err)
}
Expand All @@ -202,7 +208,7 @@ func main() {
}

if events, err := parseEvents(); err == nil {
url := fmt.Sprintf("https://api.datadoghq.com/api/v1/events?api_key=%s", cfg.APIKey)
url := fmt.Sprintf("https://api.datadoghq.%s/api/v1/events?api_key=%s", cfg.Region, cfg.APIKey)
successCount := 0
// events must be posted one at a time
for _, ev := range events {
Expand Down