File tree 3 files changed +56
-2
lines changed 3 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 5
5
## Unreleased
6
6
- Improved Python API authentication when using URL-based connectivity,
7
7
by respecting the ` credential ` keyword argument
8
+ - Added basic example program about how to import a dashboard
8
9
9
10
## 0.4.0 (2024-10-16)
10
11
- Fixed folder argument issue
Original file line number Diff line number Diff line change
1
+ """
2
+ ## About
3
+
4
+ Upload a Grafana dashboard file in JSON format to the Grafana server.
5
+
6
+ ## Walkthrough
7
+
8
+ 1. Start Grafana
9
+
10
+ docker run --rm -it --publish=3000:3000 --env='GF_SECURITY_ADMIN_PASSWORD=admin' grafana/grafana:11.5.2
11
+
12
+ 2. Import dashboard
13
+
14
+ wget https://github.com/simonprickett/mongodb-hotel-jobs/raw/refs/heads/main/grafana_dashboard.json
15
+ python examples/dashboard_import.py grafana_dashboard.json
16
+
17
+ 3. Visit Grafana
18
+
19
+ http://admin:admin@localhost:3000/
20
+ Log in using admin:admin.
21
+ """
22
+
23
+ import json
24
+ import sys
25
+ from pathlib import Path
26
+
27
+ from grafana_import .grafana import Grafana
28
+
29
+
30
+ def main ():
31
+
32
+ # Read single positional CLI argument.
33
+ dashboard_path = Path (sys .argv [1 ])
34
+
35
+ # Load dashboard JSON from filesystem.
36
+ dashboard = json .loads (dashboard_path .read_text ())
37
+
38
+ # Import dashboard JSON to Grafana.
39
+ # Note: Adjust parameters to match your Grafana.
40
+ # You can use many variants to authenticate with its API.
41
+ gio = Grafana (url = "http://localhost:3000" , credential = ("admin" , "admin" ))
42
+ outcome = gio .import_dashboard (dashboard )
43
+ if outcome :
44
+ print ("Grafana dashboard imported successfully" )
45
+ else :
46
+ print ("Grafana dashboard import failed" )
47
+
48
+
49
+ if __name__ == "__main__" :
50
+ main ()
Original file line number Diff line number Diff line change @@ -36,8 +36,11 @@ lint.extend-ignore = [
36
36
]
37
37
38
38
lint.per-file-ignores."grafana_import/cli.py" = [
39
- # `print` found
40
- " T201" ,
39
+ " T201" , # `print` found
40
+ ]
41
+
42
+ lint.per-file-ignores."examples/*" = [
43
+ " T201" , # `print` found
41
44
]
42
45
43
46
# ===================
You can’t perform that action at this time.
0 commit comments