CLI Usage¶
Common templating¶
Grafanarmadillo includes a CLI to do the most common operation of importing and exporting templates with a find-replace templator. For example: You might have a dashboard for developers to test new alerts and visualisations titled “MySystem TEST”. When the devs are happy, they want an instance of the dashboard created for each of 3 deployments with the correct names and deployment_ids. They also want to be able to check the template into git so they can revert to a previous version.
Grafanarmadillo’s CLI makes this easy!
Create a config for connecting to Grafana. These parameters will be passed in directly to the grafana_client.GrafanaApi . You can set it directly in a variable or save it to a file and use a URI of “file://path/to/file.json”
{ "auth": ["admin", "admin"], "host": "localhost", "port": 3000, "protocol": "http" }
Create a mapping file for strings to findreplace. The format consists of names of environments mapped to dictionaries of replacements. Each key in the replacement is the name in the template, and each value is what that key should be expanded to. For example, to represent the deployment name “TEST” we might use
"$deployment_name": "TEST". The “$” is not necessary, but might help prevent spurious replacements.{ "template": { "deployment_name": "$deployment_name", "deployment_id": "$deployment_id" }, "dev": { "deployment_name": "TEST", "deployment_id": "dev" }, "east": { "deployment_name": "East Deployment", "deployment_id": "0" }, "west": { "deployment_name": "West Deployment", "deployment_id": "1" }, "north": { "deployment_name": "North Deployment", "deployment_id": "2" } }
Capture the template (you can commit this into git).
grafanarmadillo --cfg "$grafanarmadillo_cfg" --api-version "${GRAFANARMADILLO_API_VERSION}" dashboard export --mapping 'file://mapping.json' --src '/dev/MySystem TEST' --dst ./my_system.json --env-grafana dev --env-template template
Deploy the template to Grafana
for deployment in "east" "west" "north"; do grafanarmadillo --cfg "$grafanarmadillo_cfg" --api-version "${GRAFANARMADILLO_API_VERSION}" dashboard import --mapping 'file://mapping.json' --src ./my_system.json --dst "/$deployment/my_system" --env-grafana "$deployment" --env-template template done
Migrations¶
Bulk operations¶
Grafanarmadillo also includes some tools from performing some migrations. grafanarmadillo resources export and grafanarmadillo resources import allow for a bulk export and import of all alerts. These tools map between the Grafana instance and a filesystem:
dashboards
org0
folder0
dashboard.json
alerts
org0
folder0
alert.json
Migrating from Classic to Unified alerting¶
Another migrator included in Grafanarmadillo upgrades from Classic to Unified alerting. This needs to happen as a database migration. Grafanarmadillo clones the DB and uses a docker container to run the migrations. It then uses bulk operations to copy the upgraded dashboards and alerts and save them to disk. You can then inspect and filter the exported alerts, for example to only migrate a single org. The bulk importer can then be used to move these into a new Grafana instance.