From 3dd6b89e731154c80198d4976bee81b678d8348c Mon Sep 17 00:00:00 2001 From: wangyingtao Date: Fri, 27 Aug 2021 16:53:48 +0800 Subject: [PATCH] add tags filtering for search grafana dashboards Signed-off-by: wangyingtao --- pkg/commands/analyse.go | 3 +++ pkg/commands/analyse_grafana.go | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/commands/analyse.go b/pkg/commands/analyse.go index 4b7b987c6..744987970 100644 --- a/pkg/commands/analyse.go +++ b/pkg/commands/analyse.go @@ -48,6 +48,9 @@ func (cmd *AnalyseCommand) Register(app *kingpin.Application) { Envar("GRAFANA_API_KEY"). Default(""). StringVar(&gaCmd.apiKey) + grafanaAnalyseCmd.Flag("tags", "Tags used for filtering dashboards for alanyse, seperate multiple tags with comma"). + Default(""). + StringVar(&gaCmd.tags) grafanaAnalyseCmd.Flag("read-timeout", "timeout for read requests"). Default("300s"). DurationVar(&gaCmd.readTimeout) diff --git a/pkg/commands/analyse_grafana.go b/pkg/commands/analyse_grafana.go index b6de73766..db4a01a5e 100644 --- a/pkg/commands/analyse_grafana.go +++ b/pkg/commands/analyse_grafana.go @@ -24,8 +24,8 @@ type GrafanaAnalyseCommand struct { address string apiKey string readTimeout time.Duration - - outputFile string + tags string + outputFile string } func (cmd *GrafanaAnalyseCommand) run(k *kingpin.ParseContext) error { @@ -40,7 +40,8 @@ func (cmd *GrafanaAnalyseCommand) run(k *kingpin.ParseContext) error { return err } - boardLinks, err := c.SearchDashboards(ctx, "", false) + tags := strings.Split(cmd.tags, ",") + boardLinks, err := c.SearchDashboards(ctx, "", false, tags...) if err != nil { return err }