Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit 9137c40

Browse files
committed
Add support for dashboard and panel ids
1 parent b5f4840 commit 9137c40

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

library/grafana_annotations.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@
4848
required: true
4949
description:
5050
- Text to be displayed in the annotation
51-
secure:
51+
dashboard_id:
5252
required: false
53-
default: false
5453
description:
55-
- If true, an https connection will be established with the Grafana server.
54+
- The dashboard id where the annotation will be added
55+
panel_id:
56+
required: false
57+
description:
58+
- The panel id where the annotation will be added
5659
'''
5760

5861
EXAMPLES = '''
@@ -186,14 +189,19 @@ def send_annotation(self, annotation):
186189

187190
class Annotation(object):
188191

189-
def __init__(self, text, tags, tstamp=None, end_tstamp=None):
192+
def __init__(self, text, tags, tstamp=None, end_tstamp=None,
193+
dashboard_id=None, panel_id=None):
190194
self.text = text
191195
self.tags = tags
192196
self._set_time(tstamp)
193197
self.isRegion = False
194198
if end_tstamp:
195199
self.timeEnd = int(end_tstamp) * 1000
196200
self.isRegion = True
201+
if dashboard_id:
202+
self.dashboardId = dashboard_id
203+
if panel_id:
204+
self.panelId = panel_id
197205

198206
def _set_time(self, tstamp=None, end_tstamp=None):
199207
if tstamp:
@@ -219,6 +227,8 @@ def main():
219227
end_tstamp=dict(required=False, default=None, type='int'),
220228
tags=dict(required=False, default=[], type='list'),
221229
text=dict(required=True, type='str'),
230+
dashboard_id=dict(required=False, type='int', default=None),
231+
panel_id=dict(required=False, type='int', default=None)
222232
)
223233
module = AnsibleModule(
224234
argument_spec=base_arg_spec,
@@ -234,8 +244,11 @@ def main():
234244
end_tstamp = module.params['end_tstamp']
235245
tags = ["ansible"] + module.params['tags']
236246
text = module.params['text']
247+
dashboard_id = module.params['dashboard_id']
248+
panel_id = module.params['panel_id']
237249

238-
annotation = Annotation(text, tags, tstamp=tstamp, end_tstamp=end_tstamp)
250+
annotation = Annotation(text, tags, tstamp=tstamp, end_tstamp=end_tstamp,
251+
dashboard_id=dashboard_id, panel_id=panel_id)
239252

240253
grafana = GrafanaManager(module, url, url_username, url_password, token)
241254

0 commit comments

Comments
 (0)