Skip to content

Commit 2461548

Browse files
committed
refactor structure
1 parent af24b16 commit 2461548

File tree

7 files changed

+35
-28
lines changed

7 files changed

+35
-28
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ deploy:
1414
on:
1515
tags: true
1616
distributions: sdist bdist_wheel
17-
repo: ohmrefresh/GrafanaSnapshotLibrary
17+
repo: ohmrefresh/GrafanaSnapshot

GrafanaSnapshotLibrary/GenerateSnapshot.py renamed to GrafanaSnapshot/GenerateSnapshot.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ class GenerateSnapshot:
1111
def __init__(self, auth, host, port, protocol):
1212
self.api = GrafanaFace(auth=auth, host=host, port=port, protocol=protocol, verify=False)
1313

14-
def generate(self, tags, time_from, time_to):
14+
def generate(self, tags, time_from, time_to, expires=300):
15+
16+
"""
17+
Generate Grafana snapshot with expires
18+
:param tags:
19+
:param time_from:
20+
:param time_to:
21+
:param expires:
22+
:return:
23+
"""
24+
1525
dashboards_info = self.api.search.search_dashboards(tag=tags)
1626
dashboards = {}
1727
for dashboard_info in dashboards_info:
@@ -29,10 +39,9 @@ def generate(self, tags, time_from, time_to):
2939
snapshot_name = "{}_{}_{}".format(uri.replace("db/", ""), dashboard["time"]["from"],
3040
dashboard["time"]["to"])
3141

32-
snapshot = self.api.snapshots.create_new_snapshot(dashboard, name=snapshot_name, expires=300)
42+
snapshot = self.api.snapshots.create_new_snapshot(dashboard, name=snapshot_name, expires=expires)
3343
snapshot_list.append(snapshot)
3444

35-
print(snapshot_list)
3645
return snapshot_list
3746

3847
@staticmethod
File renamed without changes.
File renamed without changes.

README.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
# Current status in development
44

5+
## Install
6+
If you want to use the API algorithms in your code, it is as simple as:
57

6-
# grafana_api = GrafanaFace(auth='',
7-
# host='xx', port=3000, protocol="https", verify=False)
8-
9-
#
10-
# dashboards_info = grafana_api.search.search_dashboards(tag='tags')
11-
# print(dashboards_info)
12-
# dashboards = {}
13-
# for dashboard_info in dashboards_info:
14-
# uid = dashboard_info["uid"]
15-
# dashboards[dashboard_info['uri']] = grafana_api.dashboard.get_dashboard(uid);
16-
#
17-
# snapshot_list = []
18-
# for uri, dashboard in dashboards.items():
19-
# dashboard = dashboard["dashboard"] if "dashboard" in dashboard else dashboard
20-
# if time_from:
21-
# dashboard["time"]["from"] = time_str_from_unix_ms(time_from)
22-
# if time_to:
23-
# dashboard["time"]["to"] = time_str_from_unix_ms(time_to)
24-
# snapshot = grafana_api.snapshots.create_new_snapshot(dashboard, name=uri.replace("db/", ""),expires=300)
25-
# print(snapshot)
26-
8+
$ pip3 install grafana-snapshot
9+
10+
You can test by creating a python file:
11+
12+
```python3
13+
from GenerateSnapshot import GenerateSnapshot
14+
15+
if __name__ == "__main__":
16+
grafana = GenerateSnapshot(auth='', host='xx', port=3000, protocol="https", verify=False)
17+
grafana.generate(tags="tags", time_from="1563183710618", time_to="1563185212275")
18+
19+
```
20+
21+
## Uninstall
22+
If you want to uninstall grafana-snapshot, it is as simple as:
23+
24+
$ pip3 uninstall -y grafana-snapshot

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import setuptools
66

77
# Read version from file without loading the module
8-
with open('GrafanaSnapshotLibrary/version.py', 'r') as version_file:
8+
with open('GrafanaSnapshot/version.py', 'r') as version_file:
99
version_match = re.search(r"^VERSION ?= ?['\"]([^'\"]*)['\"]",
1010
version_file.read(), re.M)
1111
with open("README.md", "r") as fh:
@@ -32,14 +32,14 @@
3232
]
3333

3434
setuptools.setup(
35-
name="GrafanaSnapshotLibrary",
35+
name="grafana-snapshot",
3636
version=VERSION,
3737
author="Authapon Kongkaew",
3838
author_email="[email protected]",
3939
description="A small example package",
4040
long_description=long_description,
4141
long_description_content_type="text/markdown",
42-
url="https://github.com/ohmrefresh/GrafanaSnapshotLibrary.git",
42+
url="https://github.com/ohmrefresh/GrafanaSnapshot.git",
4343
install_requires=requirements,
4444
packages=setuptools.find_packages(),
4545
classifiers=[
File renamed without changes.

0 commit comments

Comments
 (0)