Skip to content

Commit

Permalink
Add initial datadog widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Smith committed Aug 22, 2018
1 parent 816a3d4 commit 07ee35b
Show file tree
Hide file tree
Showing 46 changed files with 16,566 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,8 @@
[prune]
go-tests = true
unused-packages = true


[[constraint]]
branch = "master"
name = "github.com/zorkian/go-datadog-api"
59 changes: 59 additions & 0 deletions _site/content/modules/datadog.md
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`.
Binary file added _site/static/imgs/modules/datadog_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _site/static/imgs/modules/datadog_ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions datadog/client.go
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"),
)
}
73 changes: 73 additions & 0 deletions datadog/widget.go
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
}
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/senorprogrammer/wtf/cryptoexchanges/bittrex"
"github.com/senorprogrammer/wtf/cryptoexchanges/blockfolio"
"github.com/senorprogrammer/wtf/cryptoexchanges/cryptolive"
"github.com/senorprogrammer/wtf/datadog"
"github.com/senorprogrammer/wtf/flags"
"github.com/senorprogrammer/wtf/gcal"
"github.com/senorprogrammer/wtf/gerrit"
Expand Down Expand Up @@ -195,6 +196,8 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) {
widgets = append(widgets, cmdrunner.NewWidget())
case "cryptolive":
widgets = append(widgets, cryptolive.NewWidget())
case "datadog":
widgets = append(widgets, datadog.NewWidget())
case "gcal":
widgets = append(widgets, gcal.NewWidget())
case "gerrit":
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/cenkalti/backoff/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/cenkalti/backoff/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/cenkalti/backoff/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions vendor/github.com/cenkalti/backoff/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions vendor/github.com/cenkalti/backoff/backoff.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07ee35b

Please sign in to comment.