mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Basic New Relic deploy info
This commit is contained in:
parent
a82db2bea8
commit
6303acc9a4
@ -19,6 +19,10 @@ wtf:
|
|||||||
username: "senorprogrammer"
|
username: "senorprogrammer"
|
||||||
jira:
|
jira:
|
||||||
refreshInterval: 900
|
refreshInterval: 900
|
||||||
|
newrelic:
|
||||||
|
applicationId: 10549735
|
||||||
|
deployCount: 5
|
||||||
|
refreshInterval: 900
|
||||||
opsgenie:
|
opsgenie:
|
||||||
refreshInterval: 21600
|
refreshInterval: 21600
|
||||||
security:
|
security:
|
||||||
|
30
newrelic/client.go
Normal file
30
newrelic/client.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package newrelic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
nr "github.com/yfronto/newrelic"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Application() (*nr.Application, error) {
|
||||||
|
client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY"))
|
||||||
|
|
||||||
|
application, err := client.GetApplication(Config.UInt("wtf.newrelic.applicationId"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return application, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Deployments() ([]nr.ApplicationDeployment, error) {
|
||||||
|
client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY"))
|
||||||
|
|
||||||
|
opts := &nr.ApplicationDeploymentOptions{Page: 1}
|
||||||
|
deployments, err := client.GetApplicationDeployments(Config.UInt("wtf.newrelic.applicationId"), opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return deployments, nil
|
||||||
|
}
|
87
newrelic/widget.go
Normal file
87
newrelic/widget.go
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package newrelic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
"github.com/rivo/tview"
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
|
nr "github.com/yfronto/newrelic"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Config *config.Config
|
||||||
|
|
||||||
|
type Widget struct {
|
||||||
|
wtf.BaseWidget
|
||||||
|
|
||||||
|
View *tview.TextView
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWidget() *Widget {
|
||||||
|
widget := Widget{
|
||||||
|
BaseWidget: wtf.BaseWidget{
|
||||||
|
Name: "New Relic",
|
||||||
|
RefreshedAt: time.Now(),
|
||||||
|
RefreshInt: Config.UInt("wtf.newrelic.refreshInterval", 900),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.addView()
|
||||||
|
|
||||||
|
return &widget
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) Refresh() {
|
||||||
|
app, _ := Application()
|
||||||
|
deploys, _ := Deployments()
|
||||||
|
|
||||||
|
widget.View.SetTitle(fmt.Sprintf(" New Relic: [green]%s[white] ", app.Name))
|
||||||
|
widget.RefreshedAt = time.Now()
|
||||||
|
|
||||||
|
widget.View.Clear()
|
||||||
|
fmt.Fprintf(widget.View, "%s", widget.contentFrom(deploys))
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) addView() {
|
||||||
|
view := tview.NewTextView()
|
||||||
|
|
||||||
|
view.SetBorder(true)
|
||||||
|
view.SetBorderColor(tcell.ColorGray)
|
||||||
|
view.SetDynamicColors(true)
|
||||||
|
view.SetTitle(widget.Name)
|
||||||
|
view.SetWrap(false)
|
||||||
|
|
||||||
|
widget.View = view
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
||||||
|
str := "\n"
|
||||||
|
str = str + " [red]Latest Deploys[white]\n"
|
||||||
|
|
||||||
|
revisions := []string{}
|
||||||
|
|
||||||
|
for _, deploy := range deploys {
|
||||||
|
if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) {
|
||||||
|
str = str + fmt.Sprintf(
|
||||||
|
" [green]%4s[white] %s %s\n",
|
||||||
|
deploy.Revision[len(deploy.Revision)-4:],
|
||||||
|
deploy.Timestamp.Format("Jan 2 15:04"),
|
||||||
|
wtf.NameFromEmail(deploy.User),
|
||||||
|
)
|
||||||
|
|
||||||
|
revisions = append(revisions, deploy.Revision)
|
||||||
|
|
||||||
|
if len(revisions) == Config.UInt("wtf.newrelic.deployCount", 5) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
@ -67,7 +67,7 @@ func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string {
|
|||||||
if len(data.Recipients) == 0 {
|
if len(data.Recipients) == 0 {
|
||||||
str = str + " [gray]no one[white]\n"
|
str = str + " [gray]no one[white]\n"
|
||||||
} else {
|
} else {
|
||||||
str = str + fmt.Sprintf(" %s\n", strings.Join(widget.namesFromEmails(data.Recipients), ", "))
|
str = str + fmt.Sprintf(" %s\n", strings.Join(wtf.NamesFromEmails(data.Recipients), ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str + "\n"
|
str = str + "\n"
|
||||||
@ -79,14 +79,3 @@ func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string {
|
|||||||
func (widget *Widget) cleanScheduleName(schedule string) string {
|
func (widget *Widget) cleanScheduleName(schedule string) string {
|
||||||
return strings.Replace(schedule, "_", " ", -1)
|
return strings.Replace(schedule, "_", " ", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) namesFromEmails(emails []string) []string {
|
|
||||||
names := []string{}
|
|
||||||
|
|
||||||
for _, email := range emails {
|
|
||||||
parts := strings.Split(email, "@")
|
|
||||||
names = append(names, strings.Title(strings.Replace(parts[0], ".", " ", -1)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return names
|
|
||||||
}
|
|
||||||
|
7
wtf.go
7
wtf.go
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/git"
|
"github.com/senorprogrammer/wtf/git"
|
||||||
"github.com/senorprogrammer/wtf/github"
|
"github.com/senorprogrammer/wtf/github"
|
||||||
"github.com/senorprogrammer/wtf/jira"
|
"github.com/senorprogrammer/wtf/jira"
|
||||||
|
"github.com/senorprogrammer/wtf/newrelic"
|
||||||
"github.com/senorprogrammer/wtf/opsgenie"
|
"github.com/senorprogrammer/wtf/opsgenie"
|
||||||
"github.com/senorprogrammer/wtf/security"
|
"github.com/senorprogrammer/wtf/security"
|
||||||
"github.com/senorprogrammer/wtf/status"
|
"github.com/senorprogrammer/wtf/status"
|
||||||
@ -63,6 +64,11 @@ func main() {
|
|||||||
jira.Refresh()
|
jira.Refresh()
|
||||||
go wtf.Schedule(jira)
|
go wtf.Schedule(jira)
|
||||||
|
|
||||||
|
newrelic.Config = Config
|
||||||
|
newrelic := newrelic.NewWidget()
|
||||||
|
newrelic.Refresh()
|
||||||
|
go wtf.Schedule(newrelic)
|
||||||
|
|
||||||
opsgenie.Config = Config
|
opsgenie.Config = Config
|
||||||
opsgenie := opsgenie.NewWidget()
|
opsgenie := opsgenie.NewWidget()
|
||||||
opsgenie.Refresh()
|
opsgenie.Refresh()
|
||||||
@ -91,6 +97,7 @@ func main() {
|
|||||||
grid.AddItem(cal.View, 2, 1, 4, 1, 0, 0, false)
|
grid.AddItem(cal.View, 2, 1, 4, 1, 0, 0, false)
|
||||||
grid.AddItem(git.View, 0, 2, 2, 3, 0, 0, false)
|
grid.AddItem(git.View, 0, 2, 2, 3, 0, 0, false)
|
||||||
grid.AddItem(github.View, 2, 2, 2, 3, 0, 0, false)
|
grid.AddItem(github.View, 2, 2, 2, 3, 0, 0, false)
|
||||||
|
grid.AddItem(newrelic.View, 4, 2, 1, 3, 0, 0, false)
|
||||||
grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false)
|
grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false)
|
||||||
grid.AddItem(sec.View, 5, 0, 1, 1, 0, 0, false)
|
grid.AddItem(sec.View, 5, 0, 1, 1, 0, 0, false)
|
||||||
grid.AddItem(opsgenie.View, 2, 0, 2, 1, 0, 0, false)
|
grid.AddItem(opsgenie.View, 2, 0, 2, 1, 0, 0, false)
|
||||||
|
25
wtf/utils.go
25
wtf/utils.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,6 +35,30 @@ func ExecuteCommand(cmd *exec.Cmd) string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Exclude(strs []string, val string) bool {
|
||||||
|
for _, str := range strs {
|
||||||
|
if val == str {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func NameFromEmail(email string) string {
|
||||||
|
parts := strings.Split(email, "@")
|
||||||
|
return strings.Title(strings.Replace(parts[0], ".", " ", -1))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NamesFromEmails(emails []string) []string {
|
||||||
|
names := []string{}
|
||||||
|
|
||||||
|
for _, email := range emails {
|
||||||
|
names = append(names, NameFromEmail(email))
|
||||||
|
}
|
||||||
|
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
func PrettyDate(dateStr string) string {
|
func PrettyDate(dateStr string) string {
|
||||||
newTime, _ := time.Parse(DateFormat, dateStr)
|
newTime, _ := time.Parse(DateFormat, dateStr)
|
||||||
return fmt.Sprint(newTime.Format("Jan 2, 2006"))
|
return fmt.Sprint(newTime.Format("Jan 2, 2006"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user