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)
|
cfg := cryptolive.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = cryptolive.NewWidget(app, cfg)
|
widget = cryptolive.NewWidget(app, cfg)
|
||||||
case "datadog":
|
case "datadog":
|
||||||
widget = datadog.NewWidget(app)
|
cfg := datadog.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = datadog.NewWidget(app, cfg)
|
||||||
case "gcal":
|
case "gcal":
|
||||||
widget = gcal.NewWidget(app)
|
widget = gcal.NewWidget(app)
|
||||||
case "gerrit":
|
case "gerrit":
|
||||||
|
@ -1,34 +1,23 @@
|
|||||||
package datadog
|
package datadog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
datadog "github.com/zorkian/go-datadog-api"
|
datadog "github.com/zorkian/go-datadog-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Monitors returns a list of newrelic monitors
|
// Monitors returns a list of newrelic monitors
|
||||||
func Monitors() ([]datadog.Monitor, error) {
|
func (widget *Widget) Monitors() ([]datadog.Monitor, error) {
|
||||||
client := datadog.NewClient(apiKey(), applicationKey())
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return monitors, nil
|
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 {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, "Datadog", "datadog", false),
|
TextWidget: wtf.NewTextWidget(app, "Datadog", "datadog", false),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
@ -23,7 +27,7 @@ func NewWidget(app *tview.Application) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
monitors, monitorErr := Monitors()
|
monitors, monitorErr := widget.Monitors()
|
||||||
|
|
||||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name())))
|
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name())))
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user