https://github.com/active-group/active-grafana
https://github.com/active-group/active-grafana
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/active-group/active-grafana
- Owner: active-group
- License: other
- Created: 2023-11-08T07:38:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-12-01T11:34:46.000Z (7 months ago)
- Last Synced: 2025-12-27T08:23:42.606Z (6 months ago)
- Language: Clojure
- Size: 60.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# active-grafana
A Clojure script/project designed to help dealing with Grafana.
## Features
- Copying a grafana dashboard from one instance to another instance.
- Copying alert-rules associated with this grafana dashboard.
- Copying library-panels associated with this grafana dashboard.
- Adjusting library-panels where a specific target structure needs repetition
with different datasources.
## Usage
### Babashka
If you check out this repository you can use [babashka](https://book.babashka.org/).
This project contains two main-functions:
```
active-grafana.main-copy
active-grafana.main-adjust
```
With babaskha-tasks (see `bb.edn` or https://book.babashka.org/#tasks) you can start at the root of the project with:
```
active-grafana $ bb copy -h
```
or
```
active-grafana $ bb adjust -h
```
If this does not work try:
```
active-grafana $ bb -m active-grafana.main-copy -- -h
active-grafana $ bb -m active-grafana.main-adjust -- -h
```
The help shows variables like `URL`, `FROM_URL` or `TO_MESSAGE`, which can
alternatively be provided by environment variables. For example:
```
$ export FROM_URL=http://localhost:3000
$ export FROM_TOKEN=glsa_FcOPTbFuJ9ZO0q6AzdTSoKjVLHaxsBw5_4ece1975
active-grafana $ TO_URL=http://localhost:3001 \
TO_TOKEN=glsa_sr9e9M1JI0ARODVP347uVKm7L1wqKvGa_3543afe4 \
TO_MESSAGE="Changes to the speed-check-panel." \
bb -m active-grafana.main-copy -- \
-b -a --board-uid=b3b41ced-1237-45a1-9f63-08d8b4191c57 \
--to-board-folder-uid=afb10bf4-f0b1-4e2b-af04-1061844be119 \
--to-alerts-folder-uid=afb10bf4-f0b1-4e2b-af04-1061844be119
```
All variables can be found in `active-grafana.settings`.
### Leiningen
If you check out this repository you can use lein.
This project contains two main-functions:
```
active-grafana.main-copy
active-grafana.main-adjust
```
To start, type at the root of the repository:
For main-copy:
```
active-grafana $ lein run -m active-grafana.main-copy -- -h
```
or
```
active-grafana $ lein with-profile as-copy run -- -h
```
For main-adjust:
```
active-grafana $ lein run -m active-grafana.main-adjust -- -h
```
or
```
active-grafana $ lein with-profile as-adjust run -- -h
```
The help shows variables like `URL`, `FROM_URL` or `TO_MESSAGE`, which can
alternatively be provided by environment variables. For example:
```
$ export FROM_URL=http://localhost:3000
$ export FROM_TOKEN=glsa_FcOPTbFuJ9ZO0q6AzdTSoKjVLHaxsBw5_4ece1975
active-grafana $ TO_URL=http://localhost:3001 \
TO_TOKEN=glsa_sr9e9M1JI0ARODVP347uVKm7L1wqKvGa_3543afe4 \
TO_MESSAGE="Changes to the speed-check-panel." \
lein run -m active-grafana.main-copy -- \
-b -a --board-uid=b3b41ced-1237-45a1-9f63-08d8b4191c57 \
--to-board-folder-uid=afb10bf4-f0b1-4e2b-af04-1061844be119 \
--to-alerts-folder-uid=afb10bf4-f0b1-4e2b-af04-1061844be119
```
All variables can be found in `active-grafana.settings`.
### Babashka-Pod
This project can also be used as a [babashka-pod](https://github.com/babashka/pods).
The pod-interface can be found in `active-grafana.pod`.
A usage example with [docker](https://www.docker.com/).
Check out this repository as `active-grafana`.`
```
active-grafana $ docker build -t active-grafana -f Dockerfile-pod .
active-grafana $ docker run active-grafana
active-grafana $ docker run active-grafana copy --help
active-grafana $ docker run active-grafana adjust --help
```
### Standalone Applications
With the help of [GraalVM](https://www.graalvm.org/) we can create a [native
image](https://www.graalvm.org/latest/reference-manual/native-image/).
A usage example with [docker](https://www.docker.com/).
Check out this repository as `active-grafana`.`
#### For copy:
```
active-grafana $ docker build -t active-grafana-copy -f Dockerfile-standalone-copy .
active-grafana $ docker run -it active-grafana-copy sh
# ./active-grafana-copy --help
```
Note: The Dockerfile contains this line:
```
RUN wget https://github.com/active-group/active-grafana/releases/download/v0.1/active-grafana-copy.jar
```
Check https://github.com/active-group/active-grafana/releases for other releases.
#### For adjust:
```
active-grafana $ docker build -t active-grafana-adjust -f Dockerfile-standalone-adjust .
active-grafana $ docker run -it active-grafana-adjust sh
# ./active-grafana-adjust --help
```
Note: The Dockerfile contains this line:
```
RUN wget https://github.com/active-group/active-grafana/releases/download/v0.1/active-grafana-adjust.jar
```
Check https://github.com/active-group/active-grafana/releases for other releases.
## Adjusting library-panels `--i-am-an-expert`-argument
The standard way of adjusting a library-panel is:
- get the library-panel with the given `PANEL_UID`
- take the first `target` as reference target
- create the new target list by repeating the reference target adjusted for the
datasource-uid and the reference-id based on the provided `DATASOURCE-UIDS`.
- update the library panel with the newly created target list
Sometimes one or more targets need more adjustments than the datasource-uid and
the reference-id. Use the `--i-am-an-expert` argument to achieve more advanced
adjustments. Example:
```
adjust --adjust --url= --token= --panel-uid= \
--datasource-uids=",,...," \
--i-am-an-expert="{:path \"target>\" :data }"
```
The `i-am-an-expert` argument gets transformed to a map using
`clojure.edn/read-string`. The `path` is processed with `(load-string (slurp
path))`. That is, the path should lead to a file containing a function like the
following:
```
(defn f-target->target
[reference-target uid data]
(assoc (assoc-in reference-target ["datasource" "uid"] uid) "refId" (get data uid)))
```
The `data` is provided to this loaded function, e.g.:
```
{"" "ref-id-1"
"" "ref-id-2"
"..." "..."
"" "ref-id-n"}
```
The result of this example is, that the target does not use the datasource-uid
as reference-id, but a reference-id provided as {"uid" "ref-id"}-map via the
command-line.
Note: make sure to escape strings in the `--i-am-an-expert`
command-line-argument in the proper way, e.g.:
```
adjust --adjust ... --i-am-an-expert="{:path \"file.path\" :data {\"uid-1\" \"my-uid-1-data\"}}"
```
## Known Issues and 'good to know'
- The application uses the environment variable `BABASHKA_POD` (as described
[here](https://github.com/babashka/pods?tab=readme-ov-file#environment)) to
determine, whether the application should behave as a pod.
- Error handling:
If something goes wrong, you are immediately provided with the plain
grafana-api-error-messages. Currently, there is no fallback or further help
provided.
- Testing:
There is no testing within the project.
- Logging and Debugging:
The current logging and debugging system is rudimentary and might even be
confusing.
## License
Copyright © 2023-2026 Active Group GmbH
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License, v. 2.0 are satisfied: GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or (at your
option) any later version, with the GNU Classpath Exception which is available
at https://www.gnu.org/software/classpath/license.html.