forked from freak12techno/grafana-interacter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboards_show.go
50 lines (40 loc) · 1.27 KB
/
dashboards_show.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"strings"
tele "gopkg.in/telebot.v3"
)
func HandleShowDashboard(c tele.Context) error {
log.Info().
Str("sender", c.Sender().Username).
Str("text", c.Text()).
Msg("Got dashboard query")
args := strings.SplitN(c.Text(), " ", 2)
_, args = args[0], args[1:] // removing first argument as it's always /render
if len(args) != 1 {
return c.Reply("Usage: /dashboard <dashboard>")
}
dashboards, err := Grafana.GetAllDashboards()
if err != nil {
return c.Reply(fmt.Sprintf("Error querying for dashboards: %s", err))
}
dashboard, found := FindDashboardByName(dashboards, args[0])
if !found {
return c.Reply("Could not find dashboard. See /dashboards for dashboards list.")
}
dashboardEnriched, err := Grafana.GetDashboard(dashboard.UID)
if err != nil {
return c.Reply(fmt.Sprintf("Could not get dashboard: %s", err))
}
var sb strings.Builder
sb.WriteString(fmt.Sprintf("<strong>Dashboard</strong> %s\n", Grafana.GetDashboardLink(*dashboard)))
sb.WriteString("Panels:\n")
for _, panel := range dashboardEnriched.Dashboard.Panels {
sb.WriteString(fmt.Sprintf("- %s\n", Grafana.GetPanelLink(PanelStruct{
DashboardURL: dashboard.URL,
PanelID: panel.ID,
Name: panel.Title,
})))
}
return BotReply(c, sb.String())
}