RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
grafana.grafana_widget_tool Namespace Reference

Classes

class  GrafanaConfig
 Simple data class holding configuration for Grafana. More...
 

Functions

dict|None fetch_json (str url, GrafanaConfig config)
 Helper function fetching JSON from Grafana REST API.
 
dict|None post_json (str url, dict payload, GrafanaConfig config)
 Helper function sending JSON payload to Grafana REST API via POST method.
 
dict|None put_json (str url, dict payload, GrafanaConfig config)
 Helper function sending JSON payload to Grafana REST API via PUT method.
 
dict|None patch_json (str url, dict payload, GrafanaConfig config)
 Helper function sending JSON payload to Grafana REST API via PATCH method.
 
dict|None del_req (str url, GrafanaConfig config)
 Helper function sending DELETE request to Grafana REST API.
 
 ensure_dir (str path)
 Creates directory if it doesn't exist.
 
 find_json_files (str path)
 Returns a list of .json files in the given directory.
 
 load_json_file (str path)
 Load and return JSON data from the given file.
 
 save_json (str path, dict data)
 Save dictionary as JSON to the given file with formatting.
 
str format_title (str title)
 Convert a title string to lowercase with underscores instead of spaces.
 
str format_name (str name)
 Convert a name string to lowercase, underscores, and remove slashes.
 
 export_data_sources (GrafanaConfig config)
 Export all Grafana data sources to JSON files in the configured data directory.
 
 export_folders (GrafanaConfig config)
 Export all Grafana folders to the configured data directory.
 
 export_dashboards (GrafanaConfig config)
 Export all Grafana dashboards to JSON files in the configured data directory.
 
 export_library_panels (GrafanaConfig config)
 Export all Grafana libary pannels to JSON files in the configured data directory.
 
 export_alerts (GrafanaConfig config)
 Export all Grafana alerts to JSON files in the configured data directory.
 
 import_data_sources (GrafanaConfig config, str secrets)
 Import data sources into Grafana, optionally injecting secret tokens.
 
 import_folders (GrafanaConfig config)
 Import Grafana folders from JSON files, creating or updating them.
 
 import_dashboards (GrafanaConfig config)
 Import Grafana dashboards from JSON files, creating or updating them.
 
 import_library_panels (GrafanaConfig config)
 Import Grafana library panels from JSON files, creating or updating them.
 
 import_alerts (GrafanaConfig config)
 Import Grafana alerts from JSON files, creating or updating them.
 
 rtctk_grafana_import (uri=None, token=None, data_dir=None, secrets=None)
 Import all Grafana resources in a specific order: data sources, folders, alerts, library panels, and dashboards.
 
 rtctk_grafana_export (uri=None, token=None, data_dir=None)
 Export Grafana resources from API and saves them as JSON files in the configured data directory.
 
 rtctk_grafana_cleanup (uri=None, token=None, data_dir=None)
 Remove all Grafana resources previously exported or imported from the data directory.
 

Variables

 logger = CiiLogManager.get_logger()
 
int REQ_TIMEOUT = 10
 

Function Documentation

◆ del_req()

dict | None grafana.grafana_widget_tool.del_req ( str url,
GrafanaConfig config )

Helper function sending DELETE request to Grafana REST API.

◆ ensure_dir()

grafana.grafana_widget_tool.ensure_dir ( str path)

Creates directory if it doesn't exist.

◆ export_alerts()

grafana.grafana_widget_tool.export_alerts ( GrafanaConfig config)

Export all Grafana alerts to JSON files in the configured data directory.

◆ export_dashboards()

grafana.grafana_widget_tool.export_dashboards ( GrafanaConfig config)

Export all Grafana dashboards to JSON files in the configured data directory.

◆ export_data_sources()

grafana.grafana_widget_tool.export_data_sources ( GrafanaConfig config)

Export all Grafana data sources to JSON files in the configured data directory.

◆ export_folders()

grafana.grafana_widget_tool.export_folders ( GrafanaConfig config)

Export all Grafana folders to the configured data directory.

◆ export_library_panels()

grafana.grafana_widget_tool.export_library_panels ( GrafanaConfig config)

Export all Grafana libary pannels to JSON files in the configured data directory.

◆ fetch_json()

dict | None grafana.grafana_widget_tool.fetch_json ( str url,
GrafanaConfig config )

Helper function fetching JSON from Grafana REST API.

◆ find_json_files()

grafana.grafana_widget_tool.find_json_files ( str path)

Returns a list of .json files in the given directory.

Logs warnings if none found.

◆ format_name()

str grafana.grafana_widget_tool.format_name ( str name)

Convert a name string to lowercase, underscores, and remove slashes.

◆ format_title()

str grafana.grafana_widget_tool.format_title ( str title)

Convert a title string to lowercase with underscores instead of spaces.

◆ import_alerts()

grafana.grafana_widget_tool.import_alerts ( GrafanaConfig config)

Import Grafana alerts from JSON files, creating or updating them.

◆ import_dashboards()

grafana.grafana_widget_tool.import_dashboards ( GrafanaConfig config)

Import Grafana dashboards from JSON files, creating or updating them.

◆ import_data_sources()

grafana.grafana_widget_tool.import_data_sources ( GrafanaConfig config,
str secrets )

Import data sources into Grafana, optionally injecting secret tokens.

◆ import_folders()

grafana.grafana_widget_tool.import_folders ( GrafanaConfig config)

Import Grafana folders from JSON files, creating or updating them.

◆ import_library_panels()

grafana.grafana_widget_tool.import_library_panels ( GrafanaConfig config)

Import Grafana library panels from JSON files, creating or updating them.

◆ load_json_file()

grafana.grafana_widget_tool.load_json_file ( str path)

Load and return JSON data from the given file.

◆ patch_json()

dict | None grafana.grafana_widget_tool.patch_json ( str url,
dict payload,
GrafanaConfig config )

Helper function sending JSON payload to Grafana REST API via PATCH method.

◆ post_json()

dict | None grafana.grafana_widget_tool.post_json ( str url,
dict payload,
GrafanaConfig config )

Helper function sending JSON payload to Grafana REST API via POST method.

◆ put_json()

dict | None grafana.grafana_widget_tool.put_json ( str url,
dict payload,
GrafanaConfig config )

Helper function sending JSON payload to Grafana REST API via PUT method.

◆ rtctk_grafana_cleanup()

grafana.grafana_widget_tool.rtctk_grafana_cleanup ( uri = None,
token = None,
data_dir = None )

Remove all Grafana resources previously exported or imported from the data directory.

This function scans the configured data directory for JSON files corresponding to dashboards, library panels, alerts, folders, and data sources. It then deletes each resource from the Grafana instance using the UIDs of each resource.

◆ rtctk_grafana_export()

grafana.grafana_widget_tool.rtctk_grafana_export ( uri = None,
token = None,
data_dir = None )

Export Grafana resources from API and saves them as JSON files in the configured data directory.

◆ rtctk_grafana_import()

grafana.grafana_widget_tool.rtctk_grafana_import ( uri = None,
token = None,
data_dir = None,
secrets = None )

Import all Grafana resources in a specific order: data sources, folders, alerts, library panels, and dashboards.

◆ save_json()

grafana.grafana_widget_tool.save_json ( str path,
dict data )

Save dictionary as JSON to the given file with formatting.

Variable Documentation

◆ logger

grafana.grafana_widget_tool.logger = CiiLogManager.get_logger()

◆ REQ_TIMEOUT

int grafana.grafana_widget_tool.REQ_TIMEOUT = 10