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)
|
settings := nbascore.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = nbascore.NewWidget(app, pages, settings)
|
widget = nbascore.NewWidget(app, pages, settings)
|
||||||
case "newrelic":
|
case "newrelic":
|
||||||
widget = newrelic.NewWidget(app)
|
settings := newrelic.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = newrelic.NewWidget(app, settings)
|
||||||
case "opsgenie":
|
case "opsgenie":
|
||||||
widget = opsgenie.NewWidget(app)
|
widget = opsgenie.NewWidget(app)
|
||||||
case "pagerduty":
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
@ -11,15 +10,20 @@ import (
|
|||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
client *Client
|
|
||||||
|
client *Client
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, "New Relic", "newrelic", false),
|
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
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
|||||||
|
|
||||||
revisions = append(revisions, deploy.Revision)
|
revisions = append(revisions, deploy.Revision)
|
||||||
|
|
||||||
if len(revisions) == wtf.Config.UInt("wtf.mods.newrelic.deployCount", 5) {
|
if len(revisions) == widget.settings.deployCount {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,10 +93,3 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
|||||||
|
|
||||||
return str
|
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")
|
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
|
||||||
|
|
||||||
settings := Settings{
|
settings := Settings{
|
||||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
|
|
||||||
filePath: localConfig.UString("filename"),
|
filePath: localConfig.UString("filename"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user