grafana

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

Grafana

Extract dashboard and datasource metadata from a Grafana server.

Usage

source:
  name: grafana
  config:
    base_url: http://localhost:3000
    api_key: Bearer qweruqwryqwLKJ
    # extract specifies which entity types to extract.
    # Defaults to all: ["dashboards", "datasources"]
    extract:
      - dashboards
      - datasources
    exclude:
      dashboards:
        - dashboard_uid_1
        - dashboard_uid_2
      panels:
        - dashboard_uid_3.panel_id_1

Configuration

Key Type Required Description
base_url string Yes URL of the Grafana server.
api_key string Yes API key to access the Grafana API.
extract []string No Entity types to extract. Defaults to ["dashboards", "datasources"].
exclude.dashboards []string No Dashboard UIDs to exclude from extraction.
exclude.panels []string No Panel IDs to exclude, in the format {dashboard_uid}.{panel_id}.

Entities

Dashboard
  • Entity type: dashboard
  • URN format: urn:grafana:{scope}:dashboard:{uid}
Properties
Property Type Description
url string Full URL to the dashboard.
description string Dashboard description (if set).
folder string Folder name containing the dashboard.
created_by string User who created the dashboard.
updated_by string User who last updated the dashboard.
tags []string Dashboard tags.
charts []object List of panel/chart objects (see below).
Chart sub-fields
Field Type Description
urn string Panel URN (urn:grafana:{scope}:panel:{dashboard_uid}.{panel_id}).
name string Panel title.
type string Panel visualization type (e.g. table, graph).
source string Always grafana.
description string Panel description (if set).
url string Direct URL to the panel.
data_source string Data source type (if set).
raw_query string Raw SQL query from the first target (if set).
dashboard_urn string Parent dashboard URN.
dashboard_source string Always grafana.
Datasource
  • Entity type: datasource
  • URN format: urn:grafana:{scope}:datasource:{uid}
Properties
Property Type Description
type string Datasource type (e.g. postgres, prometheus).
url string Connection URL.
database string Database name (if applicable).
is_default bool Whether this is the default datasource.

Edges

Source Target Type Description
dashboard datasource derived_from Dashboard panels consume data from this datasource.

Contributing

Refer to the contribution guide for information on contributing to this module.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, config Config) (*Client, error)

func (*Client) GetAllDashboardDetails

func (c *Client) GetAllDashboardDetails(ctx context.Context, uids []string) ([]DashboardDetail, error)

func (*Client) GetAllDatasources

func (c *Client) GetAllDatasources(ctx context.Context) (map[string]DataSource, error)

func (*Client) GetDashboardDetail

func (c *Client) GetDashboardDetail(uid string) (DashboardDetail, error)

func (*Client) SearchAllDashboardUIDs

func (c *Client) SearchAllDashboardUIDs(ctx context.Context) ([]string, error)

type Config

type Config struct {
	BaseURL string   `json:"base_url" yaml:"base_url" mapstructure:"base_url" validate:"required,url"`
	APIKey  string   `json:"api_key" yaml:"api_key" mapstructure:"api_key" validate:"required"`
	Extract []string `json:"extract" yaml:"extract" mapstructure:"extract" validate:"omitempty,dive,oneof=dashboards datasources"`
	Exclude Exclude  `json:"exclude" yaml:"exclude" mapstructure:"exclude"`
}

Config holds the set of configuration for the grafana extractor

type Dashboard

type Dashboard struct {
	UID         string   `json:"uid"`
	Description string   `json:"description"`
	Panels      []Panel  `json:"panels"`
	Tags        []string `json:"tags"`
}

type DashboardDetail

type DashboardDetail struct {
	Meta      Meta      `json:"meta"`
	Dashboard Dashboard `json:"dashboard"`
}

type DataSource

type DataSource struct {
	UID       string `json:"uid"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	URL       string `json:"url"`
	Database  string `json:"database"`
	IsDefault bool   `json:"isDefult"`
}

type Exclude

type Exclude struct {
	Dashboards []string `json:"dashboards" yaml:"dashboards" mapstructure:"dashboards"`
	Panels     []string `json:"panels" yaml:"panels" mapstructure:"panels"`
}

type Extractor

type Extractor struct {
	plugins.BaseExtractor
	// contains filtered or unexported fields
}

Extractor manages the communication with the Grafana Server

func New

func New(logger log.Logger) *Extractor

New returns a pointer to an initialized Extractor Object

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, emit plugins.Emit) error

Extract checks if the extractor is configured and if so, then it extracts the metadata from the extractor.

func (*Extractor) Init

func (e *Extractor) Init(ctx context.Context, config plugins.Config) error

Init initializes the extractor

type Meta

type Meta struct {
	Slug        string `json:"slug"`
	URL         string `json:"url"`
	CreatedBy   string `json:"createdBy"`
	UpdatedBy   string `json:"updatedBy"`
	FolderTitle string `json:"folderTitle"`
	FolderUID   string `json:"folderUid"`
	FolderURL   string `json:"folderUrl"`
}

type Panel

type Panel struct {
	ID            int      `json:"id"`
	Title         string   `json:"title"`
	Type          string   `json:"type"`
	Description   string   `json:"description"`
	DataSource    string   `json:"datasource"`
	DataSourceUID string   `json:"-"` // resolved from datasource lookup
	Targets       []Target `json:"targets"`
}

type Target

type Target struct {
	RawSQL string `json:"rawSQL"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL