mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge branch 'feat/nr-multi' of github.com:Seanstoppable/wtf into Seanstoppable-feat/nr-multi
This commit is contained in:
commit
7dd4e4909b
@ -167,7 +167,7 @@ func MakeWidget(
|
|||||||
widget = nbascore.NewWidget(app, pages, settings)
|
widget = nbascore.NewWidget(app, pages, settings)
|
||||||
case "newrelic":
|
case "newrelic":
|
||||||
settings := newrelic.NewSettingsFromYAML(moduleName, moduleConfig, config)
|
settings := newrelic.NewSettingsFromYAML(moduleName, moduleConfig, config)
|
||||||
widget = newrelic.NewWidget(app, settings)
|
widget = newrelic.NewWidget(app, pages, settings)
|
||||||
case "opsgenie":
|
case "opsgenie":
|
||||||
settings := opsgenie.NewSettingsFromYAML(moduleName, moduleConfig, config)
|
settings := opsgenie.NewSettingsFromYAML(moduleName, moduleConfig, config)
|
||||||
widget = opsgenie.NewWidget(app, settings)
|
widget = opsgenie.NewWidget(app, settings)
|
||||||
|
74
modules/newrelic/display.go
Normal file
74
modules/newrelic/display.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package newrelic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/wtfutil/wtf/utils"
|
||||||
|
"github.com/wtfutil/wtf/wtf"
|
||||||
|
nr "github.com/yfronto/newrelic"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
client := widget.currentData()
|
||||||
|
if client == nil {
|
||||||
|
return widget.CommonSettings().Title, " NewRelic data unavailable ", false
|
||||||
|
}
|
||||||
|
app, appErr := client.Application()
|
||||||
|
deploys, depErr := client.Deployments()
|
||||||
|
|
||||||
|
appName := "error"
|
||||||
|
if appErr == nil {
|
||||||
|
appName = app.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
var content string
|
||||||
|
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, appName)
|
||||||
|
wrap := false
|
||||||
|
if depErr != nil {
|
||||||
|
wrap = true
|
||||||
|
content = depErr.Error()
|
||||||
|
} else {
|
||||||
|
content = widget.contentFrom(deploys)
|
||||||
|
}
|
||||||
|
|
||||||
|
return title, content, wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
||||||
|
str := fmt.Sprintf(
|
||||||
|
" %s\n",
|
||||||
|
"[red]Latest Deploys[white]",
|
||||||
|
)
|
||||||
|
|
||||||
|
revisions := []string{}
|
||||||
|
|
||||||
|
for _, deploy := range deploys {
|
||||||
|
if (deploy.Revision != "") && utils.DoesNotInclude(revisions, deploy.Revision) {
|
||||||
|
lineColor := "white"
|
||||||
|
if wtf.IsToday(deploy.Timestamp) {
|
||||||
|
lineColor = "lightblue"
|
||||||
|
}
|
||||||
|
|
||||||
|
revLen := 8
|
||||||
|
if revLen > len(deploy.Revision) {
|
||||||
|
revLen = len(deploy.Revision)
|
||||||
|
}
|
||||||
|
|
||||||
|
str += fmt.Sprintf(
|
||||||
|
" [green]%s[%s] %s %-.16s[white]\n",
|
||||||
|
deploy.Revision[0:revLen],
|
||||||
|
lineColor,
|
||||||
|
deploy.Timestamp.Format("Jan 02 15:04 MST"),
|
||||||
|
utils.NameFromEmail(deploy.User),
|
||||||
|
)
|
||||||
|
|
||||||
|
revisions = append(revisions, deploy.Revision)
|
||||||
|
|
||||||
|
if len(revisions) == widget.settings.deployCount {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
9
modules/newrelic/keyboard.go
Normal file
9
modules/newrelic/keyboard.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package newrelic
|
||||||
|
|
||||||
|
import "github.com/gdamore/tcell"
|
||||||
|
|
||||||
|
func (widget *Widget) initializeKeyboardControls() {
|
||||||
|
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help window")
|
||||||
|
widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous application")
|
||||||
|
widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next application")
|
||||||
|
}
|
@ -13,8 +13,8 @@ type Settings struct {
|
|||||||
common *cfg.Common
|
common *cfg.Common
|
||||||
|
|
||||||
apiKey string `help:"Your New Relic API token."`
|
apiKey string `help:"Your New Relic API token."`
|
||||||
applicationID int `help:"The integer ID of the New Relic application you wish to report on."`
|
|
||||||
deployCount int `help:"The number of past deploys to display on screen." optional:"true"`
|
deployCount int `help:"The number of past deploys to display on screen." optional:"true"`
|
||||||
|
applicationIDs []interface{} `help:"The integer ID of the New Relic application you wish to report on."`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||||
@ -22,9 +22,9 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
|||||||
settings := Settings{
|
settings := Settings{
|
||||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
|
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
|
||||||
|
|
||||||
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_NEW_RELIC_API_KEY"))),
|
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_NEW_RELIC_API_KEY")),
|
||||||
applicationID: ymlConfig.UInt("applicationID"),
|
|
||||||
deployCount: ymlConfig.UInt("deployCount", 5),
|
deployCount: ymlConfig.UInt("deployCount", 5),
|
||||||
|
applicationIDs: ymlConfig.UList("applicationIDs"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &settings
|
return &settings
|
||||||
|
@ -1,29 +1,46 @@
|
|||||||
package newrelic
|
package newrelic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"sort"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
"github.com/wtfutil/wtf/view"
|
"github.com/wtfutil/wtf/view"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
|
view.KeyboardWidget
|
||||||
|
view.MultiSourceWidget
|
||||||
view.TextWidget
|
view.TextWidget
|
||||||
|
|
||||||
client *Client
|
Clients []*Client
|
||||||
|
|
||||||
settings *Settings
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: view.NewTextWidget(app, settings.common, false),
|
KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common),
|
||||||
|
MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "applicationID", "applicationIDs"),
|
||||||
|
TextWidget: view.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.client = NewClient(widget.settings.apiKey, widget.settings.applicationID)
|
widget.initializeKeyboardControls()
|
||||||
|
widget.View.SetInputCapture(widget.InputCapture)
|
||||||
|
|
||||||
|
for _, id := range utils.ToInts(widget.settings.applicationIDs) {
|
||||||
|
widget.Clients = append(widget.Clients, NewClient(widget.settings.apiKey, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(widget.Clients, func(i, j int) bool {
|
||||||
|
return widget.Clients[i].applicationId < widget.Clients[j].applicationId
|
||||||
|
})
|
||||||
|
|
||||||
|
widget.SetDisplayFunction(widget.Refresh)
|
||||||
|
|
||||||
|
widget.KeyboardWidget.SetView(widget.View)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -36,57 +53,20 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) HelpText() string {
|
||||||
app, appErr := widget.client.Application()
|
return widget.KeyboardWidget.HelpText()
|
||||||
deploys, depErr := widget.client.Deployments()
|
}
|
||||||
|
|
||||||
appName := "error"
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
if appErr == nil {
|
|
||||||
appName = app.Name
|
func (widget *Widget) currentData() *Client {
|
||||||
}
|
if len(widget.Clients) == 0 {
|
||||||
|
return nil
|
||||||
var content string
|
}
|
||||||
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, appName)
|
|
||||||
wrap := false
|
if widget.Idx < 0 || widget.Idx >= len(widget.Clients) {
|
||||||
if depErr != nil {
|
return nil
|
||||||
wrap = true
|
}
|
||||||
content = depErr.Error()
|
|
||||||
} else {
|
return widget.Clients[widget.Idx]
|
||||||
content += fmt.Sprintf(
|
|
||||||
" %s\n",
|
|
||||||
"[red]Latest Deploys[white]",
|
|
||||||
)
|
|
||||||
|
|
||||||
revisions := []string{}
|
|
||||||
|
|
||||||
for _, deploy := range deploys {
|
|
||||||
if (deploy.Revision != "") && utils.DoesNotInclude(revisions, deploy.Revision) {
|
|
||||||
lineColor := "white"
|
|
||||||
if wtf.IsToday(deploy.Timestamp) {
|
|
||||||
lineColor = "lightblue"
|
|
||||||
}
|
|
||||||
|
|
||||||
revLen := 8
|
|
||||||
if revLen > len(deploy.Revision) {
|
|
||||||
revLen = len(deploy.Revision)
|
|
||||||
}
|
|
||||||
|
|
||||||
content += fmt.Sprintf(
|
|
||||||
" [green]%s[%s] %s %-.16s[white]\n",
|
|
||||||
deploy.Revision[0:revLen],
|
|
||||||
lineColor,
|
|
||||||
deploy.Timestamp.Format("Jan 02 15:04 MST"),
|
|
||||||
utils.NameFromEmail(deploy.User),
|
|
||||||
)
|
|
||||||
|
|
||||||
revisions = append(revisions, deploy.Revision)
|
|
||||||
|
|
||||||
if len(revisions) == widget.settings.deployCount {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return title, content, wrap
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user