Skip to content

Commit ea51109

Browse files
Merge pull request #54 from glesica/glesica/add-monitoring-dashboards
Add a searcher for monitoring dashboards
2 parents 058e2a4 + 9957ae3 commit ea51109

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Here are the GCP resources currently searchable through the workflow:
103103
| 🗃️ Artifact Registry | Repositories |
104104
| 🏃‍♂️ Cloud Run | Functions (Gen1), Services (Gen2) |
105105
| 📋 Cloud Tasks | Queues |
106+
| 📊 Monitoring | Dashboards |
106107

107108

108109
## Contributing

gcloud/dashboards.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package gcloud
2+
3+
type Dashboard struct {
4+
DisplayName string `json:"displayName"`
5+
Name string `json:"name"`
6+
}
7+
8+
func ListMonitoringDashboards(config *Config) ([]Dashboard, error) {
9+
return runGCloudCmd[[]Dashboard](config,
10+
"monitoring", "dashboards", "list", "--format=json(displayName,name)")
11+
}

searchers/monitoring/dashboard.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package monitoring
2+
3+
import (
4+
aw "github.com/deanishe/awgo"
5+
6+
gc "github.com/dineshgowda24/alfred-gcp-workflow/gcloud"
7+
"github.com/dineshgowda24/alfred-gcp-workflow/parser"
8+
"github.com/dineshgowda24/alfred-gcp-workflow/services"
9+
"github.com/dineshgowda24/alfred-gcp-workflow/workflow/resource"
10+
)
11+
12+
type DashboardSearcher struct{}
13+
14+
func (s *DashboardSearcher) Search(
15+
wf *aw.Workflow, svc *services.Service, cfg *gc.Config, q *parser.Result,
16+
) error {
17+
builder := resource.NewBuilder(
18+
"monitoring_dashboards",
19+
wf,
20+
cfg,
21+
q,
22+
gc.ListMonitoringDashboards,
23+
func(wf *aw.Workflow, dash gc.Dashboard) {
24+
sb := FromGCloudMonitoringDashboard(&dash)
25+
resource.NewItem(wf, cfg, sb, svc.Icon())
26+
},
27+
)
28+
29+
return builder.Build()
30+
}

searchers/monitoring/dto.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package monitoring
2+
3+
import (
4+
"strings"
5+
6+
"github.com/dineshgowda24/alfred-gcp-workflow/gcloud"
7+
)
8+
9+
type Dashboard struct {
10+
DisplayName string
11+
Name string
12+
}
13+
14+
func (d Dashboard) Title() string {
15+
return d.DisplayName
16+
}
17+
18+
func (d Dashboard) Subtitle() string {
19+
return d.ID()
20+
}
21+
22+
func (d Dashboard) URL(config *gcloud.Config) string {
23+
id := d.ID()
24+
return "https://console.cloud.google.com/monitoring/dashboards/builder/" + id + "?project=" + config.Project
25+
26+
}
27+
28+
func (d Dashboard) ID() string {
29+
parts := strings.Split(d.Name, "/")
30+
return parts[len(parts)-1]
31+
}
32+
33+
func FromGCloudMonitoringDashboard(board *gcloud.Dashboard) Dashboard {
34+
return Dashboard{
35+
DisplayName: board.DisplayName,
36+
Name: board.Name,
37+
}
38+
}

searchers/searcher.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package searchers
22

33
import (
44
aw "github.com/deanishe/awgo"
5+
56
"github.com/dineshgowda24/alfred-gcp-workflow/gcloud"
67
"github.com/dineshgowda24/alfred-gcp-workflow/parser"
78
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/artifactregistry"
@@ -11,6 +12,7 @@ import (
1112
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/filestore"
1213
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/k8s"
1314
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/memorystore"
15+
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/monitoring"
1416
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/netconnectivity"
1517
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/netservices"
1618
"github.com/dineshgowda24/alfred-gcp-workflow/searchers/pubsub"
@@ -66,6 +68,7 @@ func GetDefaultRegistry() *Registry {
6668
"filestore/instances": &filestore.InstanceSearcher{},
6769
"gke/clusters": &k8s.ClusterSearcher{},
6870
"memorystore/redis": &memorystore.RedisInstanceSearcher{},
71+
"monitoring/dashboards": &monitoring.DashboardSearcher{},
6972
"netconnectivity/cloudrouter": &netconnectivity.CloudRouterSearcher{},
7073
"netconnectivity/vpngateway": &netconnectivity.VPNGatewaySearcher{},
7174
"netconnectivity/vpntunnel": &netconnectivity.VPNTunnelSearcher{},

services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,12 @@
576576
description: Infrastructure and application quality checks
577577
url: https://console.cloud.google.com/monitoring?project={{ .Project }}
578578
logo_path: assets/gcp/cloud_monitoring.png
579+
sub_services:
580+
- id: dashboards
581+
name: Dashboards
582+
description: Custom dashboards for monitoring
583+
url: https://console.cloud.google.com/monitoring/dashboards?project={{ .Project }}
584+
logo_path: assets/gcp/cloud_monitoring.png
579585
- id: netconnectivity
580586
name: Network Connectivity
581587
description: Network and hybrid connectivity options

0 commit comments

Comments
 (0)