From bf1c2166da57138bd6e73beef4750a07659f1c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20REY?= Date: Sat, 10 Nov 2018 23:24:46 +0100 Subject: [PATCH] Add support for dashboard and panel ids --- library/grafana_annotations.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/library/grafana_annotations.py b/library/grafana_annotations.py index 7bf08b7..4963a6f 100644 --- a/library/grafana_annotations.py +++ b/library/grafana_annotations.py @@ -48,6 +48,14 @@ required: true description: - Text to be displayed in the annotation + dashboard_id: + required: false + description: + - The dashboard id where the annotation will be added + panel_id: + required: false + description: + - The panel id where the annotation will be added ''' EXAMPLES = ''' @@ -186,7 +194,8 @@ def send_annotation(self, annotation): class Annotation(object): - def __init__(self, text, tags, tstamp=None, end_tstamp=None): + def __init__(self, text, tags, tstamp=None, end_tstamp=None, + dashboard_id=None, panel_id=None): self.text = text self.tags = tags self._set_time(tstamp) @@ -194,6 +203,10 @@ def __init__(self, text, tags, tstamp=None, end_tstamp=None): if end_tstamp: self.timeEnd = int(end_tstamp) * 1000 self.isRegion = True + if dashboard_id: + self.dashboardId = dashboard_id + if panel_id: + self.panelId = panel_id def _set_time(self, tstamp=None, end_tstamp=None): if tstamp: @@ -219,6 +232,8 @@ def main(): end_tstamp=dict(required=False, default=None, type='int'), tags=dict(required=False, default=[], type='list'), text=dict(required=True, type='str'), + dashboard_id=dict(required=False, type='int', default=None), + panel_id=dict(required=False, type='int', default=None) ) module = AnsibleModule( argument_spec=base_arg_spec, @@ -234,8 +249,11 @@ def main(): end_tstamp = module.params['end_tstamp'] tags = ["ansible"] + module.params['tags'] text = module.params['text'] + dashboard_id = module.params['dashboard_id'] + panel_id = module.params['panel_id'] - annotation = Annotation(text, tags, tstamp=tstamp, end_tstamp=end_tstamp) + annotation = Annotation(text, tags, tstamp=tstamp, end_tstamp=end_tstamp, + dashboard_id=dashboard_id, panel_id=panel_id) grafana = GrafanaManager(module, url, url_username, url_password, token)