Documentation ¶
Index ¶
- func DeleteDashboards(filenames []string, contents map[string][]byte, client *Client)
- func FilterIgnored(filesToPush *map[string][]byte, cfg *config.Config) (err error)
- func FolderIDFromFolderUID(versionsFile VersionFile, folderUID string) (folderID int)
- func GetFilesContents(filenames []string, contents *map[string][]byte, subdir string, ...) (err error)
- func LoadFilesFromDirectory(cfg *config.Config, dir string, subdir string) (filenames []string, contents map[string][]byte, err error)
- func Push(cfg *config.Config, fileVersionFile VersionFile, ...) (err error)
- func PushFiles(filenames []string, contents map[string][]byte, versionsFile VersionFile, ...)
- func PushFolders(filenames []string, contents map[string][]byte, versionsFile VersionFile, ...) (err error)
- type Client
- func (c *Client) CreateFolders(folders []string, contents map[string][]byte) (err error)
- func (c *Client) CreateOrUpdateDashboard(contentJSON []byte, folderID int) (err error)
- func (c *Client) CreateOrUpdateFolder(title string, uid string) (err error)
- func (c *Client) DeleteDashboard(slug string) (err error)
- func (c *Client) DeleteFolder(uid string) (err error)
- func (c *Client) GetDashboard(URI string) (db *Dashboard, err error)
- func (c *Client) GetDashboardsURIs() (URIs []string, dashboardMetaBySlug map[string]DbSearchResponse, ...)
- type Dashboard
- type DashboardVersion
- type DbSearchResponse
- type Folder
- type VersionFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteDashboards ¶
DeleteDashboards takes a slice of files' names and a map mapping a file's name to its content, and iterates over the first slice. For each file name, extract a dashboard's slug from the content, in the map, that matches the name, and will use it to send a deletion request to the Grafana API. Logs any errors encountered during an iteration, but doesn't return until all deletion requests have been performed.
func FilterIgnored ¶
FilterIgnored takes a map mapping files' names to their contents and remove all the files that are supposed to be ignored by the dashboard manager. An ignored file is either named "versions.json" or describing a dashboard which slug starts with a given prefix. Returns an error if the slug couldn't be tested against the prefix.
func FolderIDFromFolderUID ¶
func FolderIDFromFolderUID(versionsFile VersionFile, folderUID string) (folderID int)
func GetFilesContents ¶
func GetFilesContents( filenames []string, contents *map[string][]byte, subdir string, cfg *config.Config, ) (err error)
getFilesContents takes a slice of files' names and a map mapping a file's name to its content and appends to it the current content of all of the files for which the name appears in the slice. Returns an error if there was an issue reading a file.
func LoadFilesFromDirectory ¶
func Push ¶
func Push(cfg *config.Config, fileVersionFile VersionFile, grafanaVersionFile VersionFile, files []string, contents map[string][]byte, client *Client) (err error)
func PushFiles ¶
func PushFiles(filenames []string, contents map[string][]byte, versionsFile VersionFile, grafanaVersionFile VersionFile, client *Client)
PushFiles takes a slice of files' names and a map mapping a file's name to its content, and iterates over the first slice. For each file name, it will push to Grafana the content from the map that matches the name, as a creation or an update of an existing dashboard. Logs any errors encountered during an iteration, but doesn't return until all creation and/or update requests have been performed.
func PushFolders ¶
func PushFolders(filenames []string, contents map[string][]byte, versionsFile VersionFile, grafanaVersionFile VersionFile, client *Client) (err error)
PushFolders takes a slice of files' names and a map mapping a file's name to its content, and iterates over the first slice. For each file name, it will push to Grafana the content from the map that matches the name, as a creation or an update of an existing dashboard. Logs any errors encountered during an iteration, but doesn't return until all creation and/or update requests have been performed.
Types ¶
type Client ¶
type Client struct { BaseURL string APIKey string Username string Password string SkipVerify bool // contains filtered or unexported fields }
Client implements a Grafana API client, and contains the instance's base URL and API key, along with an HTTP client used to request the API. use either APIKey or Username/Password
func NewClient ¶
func NewClient(baseURL string, apiKey string, username string, password string, SkipVerify bool) (c *Client)
NewClient returns a new Grafana API client from a given base URL and API key.
func (*Client) CreateFolders ¶
func (*Client) CreateOrUpdateDashboard ¶
CreateOrUpdateDashboard takes a given JSON content (as []byte) and create the dashboard if it doesn't exist on the Grafana instance, else updates the existing one. The Grafana API decides whether to create or update based on the "id" attribute in the dashboard's JSON: If it's unkown or null, it's a creation, else it's an update. Returns an error if there was an issue generating the request body, performing the request or decoding the response's body.
func (*Client) CreateOrUpdateFolder ¶
CreateOrUpdateFolder takes a given JSON content (as []byte) and create the dashboard if it doesn't exist on the Grafana instance, else updates the existing one. The Grafana API decides whether to create or update based on the "id" attribute in the dashboard's JSON: If it's unkown or null, it's a creation, else it's an update. Returns an error if there was an issue generating the request body, performing the request or decoding the response's body.
func (*Client) DeleteDashboard ¶
DeleteDashboard deletes the dashboard identified by a given slug on the Grafana API. Returns an error if the process failed.
func (*Client) DeleteFolder ¶
DeleteFolder deletes the dashboard identified by a given uid on the Grafana API. NB this also deletes all graphs stored inside! Returns an error if the process failed.
func (*Client) GetDashboard ¶
GetDashboard requests the Grafana API for a dashboard identified by a given URI (using the same format as GetDashboardsURIs). Returns the dashboard as an instance of the Dashboard structure. Returns an error if there was an issue requesting the dashboard or parsing the response body.
func (*Client) GetDashboardsURIs ¶
func (c *Client) GetDashboardsURIs() (URIs []string, dashboardMetaBySlug map[string]DbSearchResponse, FoldersMetaByUID map[string]DbSearchResponse, Folders []DbSearchResponse, err error)
GetDashboardsURIs requests the Grafana API for the list of all dashboards, then returns the dashboards' URIs. An URI will look like "uid/[UID]". Returns an error if there was an issue requesting the URIs or parsing the response body.
type Dashboard ¶
Dashboard represents a Grafana dashboard, with its JSON definition, slug and current version.
func (*Dashboard) UnmarshalJSON ¶
UnmarshalJSON tells the JSON parser how to unmarshal JSON data into an instance of the Dashboard structure. Returns an error if there was an issue unmarshalling the JSON.
type DashboardVersion ¶
type DashboardVersion struct {
Meta DbSearchResponse
}
type DbSearchResponse ¶
type DbSearchResponse struct { ID int `json:"id"` Title string `json:"title"` URI string `json:"uri"` Type string `json:"type"` Tags []string `json:"tags"` Starred bool `json:"isStarred"` UID string `json:"uid"` FolderUID string `json:"folderUid,omitEmpty"` FolderID int `json:"folderId,omitEmpty"` }
DbSearchResponse represents an element of the response to a dashboard search query
type VersionFile ¶
type VersionFile struct { DashboardMetaByTitle map[string]DbSearchResponse `json:"dashboardMetaByTitle"` DashboardMetaBySlug map[string]DbSearchResponse `json:"dashboardMetaBySlug"` DashboardBySlug map[string]*Dashboard `json:"-"` FoldersMetaByUID map[string]DbSearchResponse `json:"foldersMetaByUID"` DashboardVersionBySlug map[string]int `json:"dashboardVersionBySlug"` }