mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 NewRelic extracted to new config format
This commit is contained in:
parent
8ad8d942d0
commit
b6d845b734
3
main.go
3
main.go
@ -253,7 +253,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
settings := nbascore.NewSettingsFromYAML(wtf.Config)
|
||||
widget = nbascore.NewWidget(app, pages, settings)
|
||||
case "newrelic":
|
||||
widget = newrelic.NewWidget(app)
|
||||
settings := newrelic.NewSettingsFromYAML(wtf.Config)
|
||||
widget = newrelic.NewWidget(app, settings)
|
||||
case "opsgenie":
|
||||
widget = opsgenie.NewWidget(app)
|
||||
case "pagerduty":
|
||||
|
30
modules/newrelic/settings.go
Normal file
30
modules/newrelic/settings.go
Normal file
@ -0,0 +1,30 @@
|
||||
package newrelic
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string
|
||||
applicationID int
|
||||
deployCount int
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.newrelic")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
|
||||
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_NEW_RELIC_API_KEY")),
|
||||
applicationID: localConfig.UInt("applicationID"),
|
||||
deployCount: localConfig.UInt("deployCount", 5),
|
||||
}
|
||||
|
||||
return &settings
|
||||
}
|
@ -2,7 +2,6 @@ package newrelic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
@ -11,15 +10,20 @@ import (
|
||||
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
client *Client
|
||||
|
||||
client *Client
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application) *Widget {
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(app, "New Relic", "newrelic", false),
|
||||
client: NewClient(apiKey(), wtf.Config.UInt("wtf.mods.newrelic.applicationId")),
|
||||
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.client = NewClient(widget.settings.apiKey, widget.settings.applicationID)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@ -81,7 +85,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
||||
|
||||
revisions = append(revisions, deploy.Revision)
|
||||
|
||||
if len(revisions) == wtf.Config.UInt("wtf.mods.newrelic.deployCount", 5) {
|
||||
if len(revisions) == widget.settings.deployCount {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -89,10 +93,3 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func apiKey() string {
|
||||
return wtf.Config.UString(
|
||||
"wtf.mods.newrelic.apiKey",
|
||||
os.Getenv("WTF_NEW_RELIC_API_KEY"),
|
||||
)
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
|
||||
filePath: localConfig.UString("filename"),
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user