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

Commit 8aa0866

Browse files
committed
Add support for dashboard and panel ids
1 parent e5e1c65 commit 8aa0866

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

library/grafana_annotations.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
required: true
4949
description:
5050
- Text to be displayed in the annotation
51+
dashboard_id:
52+
required: false
53+
description:
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
5159
'''
5260

5361
EXAMPLES = '''
@@ -179,14 +187,19 @@ def send_annotation(self, annotation):
179187

180188
class Annotation(object):
181189

182-
def __init__(self, text, tags, tstamp=None, end_tstamp=None):
190+
def __init__(self, text, tags, tstamp=None, end_tstamp=None,
191+
dashboard_id=None, panel_id=None):
183192
self.text = text
184193
self.tags = tags
185194
self._set_time(tstamp)
186195
self.isRegion = False
187196
if end_tstamp:
188197
self.timeEnd = int(end_tstamp) * 1000
189198
self.isRegion = True
199+
if dashboard_id:
200+
self.dashboardId = dashboard_id
201+
if panel_id:
202+
self.panelId = panel_id
190203

191204
def _set_time(self, tstamp=None, end_tstamp=None):
192205
if tstamp:
@@ -212,6 +225,8 @@ def main():
212225
end_tstamp=dict(required=False, default=None, type='int'),
213226
tags=dict(required=False, default=[], type='list'),
214227
text=dict(required=True, type='str'),
228+
dashboard_id=dict(required=False, type='int', default=None),
229+
panel_id=dict(required=False, type='int', default=None)
215230
)
216231
module = AnsibleModule(
217232
argument_spec=base_arg_spec,
@@ -227,8 +242,11 @@ def main():
227242
end_tstamp = module.params['end_tstamp']
228243
tags = ["ansible"] + module.params['tags']
229244
text = module.params['text']
245+
dashboard_id = module.params['dashboard_id']
246+
panel_id = module.params['panel_id']
230247

231-
annotation = Annotation(text, tags, tstamp=tstamp, end_tstamp=end_tstamp)
248+
annotation = Annotation(text, tags, tstamp=tstamp, end_tstamp=end_tstamp,
249+
dashboard_id=dashboard_id, panel_id=panel_id)
232250

233251
grafana = GrafanaManager(module, url, url_username, url_password, token)
234252

0 commit comments

Comments
 (0)