-
-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
title: "Datadog" | ||
date: 2018-08-18T00:00:00Z | ||
draft: false | ||
weight: 160 | ||
--- | ||
|
||
<img class="screenshot" src="/imgs/modules/newrelic.png" width="640" height="189" alt="newrelic screenshot" /> | ||
|
||
Connects to the Datadog API and displays alerting modules | ||
|
||
## Source Code | ||
|
||
```bash | ||
wtf/datadog/ | ||
``` | ||
|
||
## Configuration | ||
|
||
```yaml | ||
datadog: | ||
apiKey: "<yourapikey>" | ||
applicationKey: "<yourapplicationkey>" | ||
enabled: true | ||
position: | ||
top: 4 | ||
left: 3 | ||
height: 1 | ||
width: 2 | ||
monitors: | ||
tags: | ||
- "team:ops" | ||
``` | ||
### Attributes | ||
`apiKey` <br /> | ||
Value: Your <a href="https://docs.datadoghq.com/api/?lang=python#overview">Datadog API</a> key. | ||
|
||
`applicationKey` <br /> | ||
The integer ID of the New Relic application you wish to report on. <br/> | ||
Value: Your <a href="https://docs.datadoghq.com/api/?lang=python#overview">Datadog Application</a> key. | ||
|
||
`monitors` <br /> | ||
Configuration for the monitors functionality. | ||
|
||
`tags` <br /> | ||
Array of tags you want to query monitors by. | ||
|
||
`enabled` <br /> | ||
Determines whether or not this module is executed and if its data displayed onscreen. <br /> | ||
Values: `true`, `false`. | ||
|
||
`position` <br /> | ||
Defines where in the grid this module's widget will be displayed. <br /> | ||
|
||
`refreshInterval` <br /> | ||
How often, in seconds, this module will update its data. <br /> | ||
Values: A positive integer, `0..n`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package datadog | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/senorprogrammer/wtf/wtf" | ||
datadog "github.com/zorkian/go-datadog-api" | ||
) | ||
|
||
// Monitors returns a list of newrelic monitors | ||
func Monitors() ([]datadog.Monitor, error) { | ||
client := datadog.NewClient(apiKey(), applicationKey()) | ||
|
||
monitors, err := client.GetMonitorsByTags(wtf.ToStrs(wtf.Config.UList("wtf.mods.datadog.monitors.tags"))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return monitors, nil | ||
} | ||
|
||
func apiKey() string { | ||
return wtf.Config.UString( | ||
"wtf.mods.datadog.apiKey", | ||
os.Getenv("WTF_DATADOG_API_KEY"), | ||
) | ||
} | ||
|
||
func applicationKey() string { | ||
return wtf.Config.UString( | ||
"wtf.mods.datadog.applicationKey", | ||
os.Getenv("WTF_DATADOG_APPLICATION_KEY"), | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package datadog | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/senorprogrammer/wtf/wtf" | ||
datadog "github.com/zorkian/go-datadog-api" | ||
) | ||
|
||
type Widget struct { | ||
wtf.TextWidget | ||
} | ||
|
||
func NewWidget() *Widget { | ||
widget := Widget{ | ||
TextWidget: wtf.NewTextWidget("Datadog", "datadog", false), | ||
} | ||
|
||
return &widget | ||
} | ||
|
||
/* -------------------- Exported Functions -------------------- */ | ||
|
||
func (widget *Widget) Refresh() { | ||
monitors, monitorErr := Monitors() | ||
|
||
widget.UpdateRefreshedAt() | ||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name))) | ||
widget.View.Clear() | ||
|
||
var content string | ||
if monitorErr != nil { | ||
widget.View.SetWrap(true) | ||
content = monitorErr.Error() | ||
} else { | ||
widget.View.SetWrap(false) | ||
content = widget.contentFrom(monitors) | ||
} | ||
|
||
widget.View.SetText(content) | ||
} | ||
|
||
/* -------------------- Unexported Functions -------------------- */ | ||
|
||
func (widget *Widget) contentFrom(monitors []datadog.Monitor) string { | ||
var str string | ||
|
||
triggeredMonitors := []datadog.Monitor{} | ||
|
||
for _, monitor := range monitors { | ||
state := *monitor.OverallState | ||
switch state { | ||
case "Alert": | ||
triggeredMonitors = append(triggeredMonitors, monitor) | ||
} | ||
} | ||
if len(triggeredMonitors) > 0 { | ||
str = str + fmt.Sprintf( | ||
" %s\n", | ||
"[red]Triggered Monitors[white]", | ||
) | ||
for _, triggeredMonitor := range triggeredMonitors { | ||
str = str + fmt.Sprintf("[red] %s\n", *triggeredMonitor.Name) | ||
} | ||
} else { | ||
str = str + fmt.Sprintf( | ||
" %s\n", | ||
"[green]No Triggered Monitors[white]", | ||
) | ||
} | ||
|
||
return str | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.