From b2b6618a6e9be971928be7e5f0d6bbb3e135afc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20REY?= Date: Sun, 15 Mar 2020 19:01:05 +0100 Subject: [PATCH] Port ansible-collection-migration diff Closes: #66 --- plugins/callback/grafana_annotations.py | 177 ++++++++++++------------ plugins/lookup/grafana_dashboard.py | 29 ++-- tests/sanity/ignore-2.9.txt | 7 - 3 files changed, 101 insertions(+), 112 deletions(-) diff --git a/plugins/callback/grafana_annotations.py b/plugins/callback/grafana_annotations.py index 61efcd04..cd8925f9 100644 --- a/plugins/callback/grafana_annotations.py +++ b/plugins/callback/grafana_annotations.py @@ -27,95 +27,92 @@ from ansible.plugins.callback import CallbackBase -DOCUMENTATION = '''callback: grafana_annotations -callback_type: notification -short_description: send ansible events as annotations on charts to grafana over http - api. -author: Rémi REY (@rrey) -description: -- This callback will report start, failed and stats events to Grafana as annotations - (https://grafana.com) -requirements: -- whitelisting in configuration -options: - grafana_url: - description: Grafana annotations api URL - required: true - env: - - name: GRAFANA_URL - ini: - - section: callback_grafana_annotations - key: grafana_url - type: string - validate_certs: - description: validate the SSL certificate of the Grafana server. (For HTTPS url) - env: - - name: GRAFANA_VALIDATE_CERT - ini: - - section: callback_grafana_annotations - key: validate_grafana_certs - - section: callback_grafana_annotations - key: validate_certs - default: true - type: bool - aliases: - - validate_grafana_certs - http_agent: - description: The HTTP 'User-agent' value to set in HTTP requets. - env: - - name: HTTP_AGENT - ini: - - section: callback_grafana_annotations - key: http_agent - default: Ansible (grafana_annotations callback) - type: string - grafana_api_key: - description: Grafana API key, allowing to authenticate when posting on the HTTP - API. If not provided, grafana_login and grafana_password will be required. - env: - - name: GRAFANA_API_KEY - ini: - - section: callback_grafana_annotations - key: grafana_api_key - type: string - grafana_user: - description: Grafana user used for authentication. Ignored if grafana_api_key - is provided. - env: - - name: GRAFANA_USER - ini: - - section: callback_grafana_annotations - key: grafana_user - default: ansible - type: string - grafana_password: - description: Grafana password used for authentication. Ignored if grafana_api_key - is provided. - env: - - name: GRAFANA_PASSWORD - ini: - - section: callback_grafana_annotations - key: grafana_password - default: ansible - type: string - grafana_dashboard_id: - description: The grafana dashboard id where the annotation shall be created. - env: - - name: GRAFANA_DASHBOARD_ID - ini: - - section: callback_grafana_annotations - key: grafana_dashboard_id - type: integer - grafana_panel_ids: - description: The grafana panel ids where the annotation shall be created. Give - a single integer or a comma-separated list of integers. - env: - - name: GRAFANA_PANEL_IDS - ini: - - section: callback_grafana_annotations - key: grafana_panel_ids - default: [] - type: list +DOCUMENTATION = ''' + callback: grafana_annotations + callback_type: notification + short_description: send ansible events as annotations on charts to grafana over http api. + author: "Rémi REY (@rrey)" + description: + - This callback will report start, failed and stats events to Grafana as annotations (https://grafana.com) + requirements: + - whitelisting in configuration + options: + grafana_url: + description: Grafana annotations api URL + required: True + env: + - name: GRAFANA_URL + ini: + - section: callback_grafana_annotations + key: grafana_url + type: string + validate_certs: + description: validate the SSL certificate of the Grafana server. (For HTTPS url) + env: + - name: GRAFANA_VALIDATE_CERT + ini: + - section: callback_grafana_annotations + key: validate_grafana_certs + - section: callback_grafana_annotations + key: validate_certs + default: True + type: bool + aliases: [ validate_grafana_certs ] + http_agent: + description: The HTTP 'User-agent' value to set in HTTP requets. + env: + - name: HTTP_AGENT + ini: + - section: callback_grafana_annotations + key: http_agent + default: 'Ansible (grafana_annotations callback)' + type: string + grafana_api_key: + description: Grafana API key, allowing to authenticate when posting on the HTTP API. + If not provided, grafana_login and grafana_password will + be required. + env: + - name: GRAFANA_API_KEY + ini: + - section: callback_grafana_annotations + key: grafana_api_key + type: string + grafana_user: + description: Grafana user used for authentication. Ignored if grafana_api_key is provided. + env: + - name: GRAFANA_USER + ini: + - section: callback_grafana_annotations + key: grafana_user + default: ansible + type: string + grafana_password: + description: Grafana password used for authentication. Ignored if grafana_api_key is provided. + env: + - name: GRAFANA_PASSWORD + ini: + - section: callback_grafana_annotations + key: grafana_password + default: ansible + type: string + grafana_dashboard_id: + description: The grafana dashboard id where the annotation shall be created. + env: + - name: GRAFANA_DASHBOARD_ID + ini: + - section: callback_grafana_annotations + key: grafana_dashboard_id + type: integer + grafana_panel_ids: + description: The grafana panel ids where the annotation shall be created. + Give a single integer or a comma-separated list of integers. + env: + - name: GRAFANA_PANEL_IDS + ini: + - section: callback_grafana_annotations + key: grafana_panel_ids + default: [] + type: list ''' @@ -165,7 +162,7 @@ class CallbackModule(CallbackBase): CALLBACK_VERSION = 2.0 CALLBACK_TYPE = 'aggregate' - CALLBACK_NAME = 'ansible_community.grafana.grafana_annotations' + CALLBACK_NAME = 'community.grafana.grafana_annotations' CALLBACK_NEEDS_WHITELIST = True def __init__(self, display=None): diff --git a/plugins/lookup/grafana_dashboard.py b/plugins/lookup/grafana_dashboard.py index 36e77a36..245e14b8 100644 --- a/plugins/lookup/grafana_dashboard.py +++ b/plugins/lookup/grafana_dashboard.py @@ -7,46 +7,45 @@ 'status': ['preview'], 'supported_by': 'community'} -DOCUMENTATION = '''lookup: grafana_dashboard +DOCUMENTATION = ''' +lookup: grafana_dashboard author: Thierry Salle (@seuf) short_description: list or search grafana dashboards description: -- This lookup returns a list of grafana dashboards with possibility to filter them - by query. + - This lookup returns a list of grafana dashboards with possibility to filter them by query. options: grafana_url: description: url of grafana. env: - - name: GRAFANA_URL + - name: GRAFANA_URL default: http://127.0.0.1:3000 grafana_api_key: description: - - api key of grafana. - - when C(grafana_api_key) is set, the options C(grafan_user), C(grafana_password) - and C(grafana_org_id) are ignored. - - Attention, please remove the two == at the end of the grafana_api_key - - because ansible lookup plugins options are split on = (see example). + - api key of grafana. + - when C(grafana_api_key) is set, the options C(grafan_user), C(grafana_password) and C(grafana_org_id) are ignored. + - Attention, please remove the two == at the end of the grafana_api_key + - because ansible lookup plugins options are split on = (see example). env: - - name: GRAFANA_API_KEY + - name: GRAFANA_API_KEY grafana_user: description: grafana authentication user. env: - - name: GRAFANA_USER + - name: GRAFANA_USER default: admin grafana_password: - description: grafana authentication password. + description: grafana authentication password. env: - - name: GRAFANA_PASSWORD + - name: GRAFANA_PASSWORD default: admin grafana_org_id: description: grafana organisation id. env: - - name: GRAFANA_ORG_ID + - name: GRAFANA_ORG_ID default: 1 search: description: optional filter for dashboard search. env: - - name: GRAFANA_DASHBOARD_SEARCH + - name: GRAFANA_DASHBOARD_SEARCH ''' EXAMPLES = """ diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 50d3c0de..81db56a9 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -1,8 +1 @@ -plugins/modules/grafana_dashboard.py validate-modules:parameter-type-not-in-doc -plugins/modules/grafana_dashboard.py validate-modules:doc-missing-type -plugins/modules/grafana_datasource.py validate-modules:doc-default-does-not-match-spec -plugins/modules/grafana_datasource.py validate-modules:parameter-type-not-in-doc -plugins/modules/grafana_datasource.py validate-modules:doc-missing-type -plugins/modules/grafana_plugin.py validate-modules:parameter-type-not-in-doc -plugins/modules/grafana_plugin.py validate-modules:doc-missing-type tests/unit/modules/grafana/grafana_plugin/test_grafana_plugin.py pep8:W291