mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 DataDog extracted to new config format
This commit is contained in:
parent
27b4274d38
commit
5e1fdef5d4
3
main.go
3
main.go
@ -205,7 +205,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
cfg := cryptolive.NewSettingsFromYAML(wtf.Config)
|
||||
widget = cryptolive.NewWidget(app, cfg)
|
||||
case "datadog":
|
||||
widget = datadog.NewWidget(app)
|
||||
cfg := datadog.NewSettingsFromYAML(wtf.Config)
|
||||
widget = datadog.NewWidget(app, cfg)
|
||||
case "gcal":
|
||||
widget = gcal.NewWidget(app)
|
||||
case "gerrit":
|
||||
|
@ -1,34 +1,23 @@
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/wtfutil/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())
|
||||
func (widget *Widget) Monitors() ([]datadog.Monitor, error) {
|
||||
client := datadog.NewClient(
|
||||
widget.settings.apiKey,
|
||||
widget.settings.applicationKey,
|
||||
)
|
||||
|
||||
monitors, err := client.GetMonitorsByTags(wtf.ToStrs(wtf.Config.UList("wtf.mods.datadog.monitors.tags")))
|
||||
tags := wtf.ToStrs(widget.settings.tags)
|
||||
|
||||
monitors, err := client.GetMonitorsByTags(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"),
|
||||
)
|
||||
}
|
||||
|
29
modules/datadog/settings.go
Normal file
29
modules/datadog/settings.go
Normal file
@ -0,0 +1,29 @@
|
||||
package datadog
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string
|
||||
applicationKey string
|
||||
tags []interface{}
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_DATADOG_API_KEY")),
|
||||
applicationKey: localConfig.UString("applicationKey", os.Getenv("WTF_DATADOG_APPLICATION_KEY")),
|
||||
tags: localConfig.UList("monitors.tags"),
|
||||
}
|
||||
|
||||
return &settings
|
||||
}
|
@ -10,11 +10,15 @@ import (
|
||||
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application) *Widget {
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(app, "Datadog", "datadog", false),
|
||||
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
return &widget
|
||||
@ -23,7 +27,7 @@ func NewWidget(app *tview.Application) *Widget {
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
monitors, monitorErr := Monitors()
|
||||
monitors, monitorErr := widget.Monitors()
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name())))
|
||||
widget.View.Clear()
|
||||
|
Loading…
x
Reference in New Issue
Block a user