From c8522174f555bb5f460e214f5d97060d4c823d78 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:04:22 +0100 Subject: [PATCH 01/11] feat: added org_name param and orga by name function --- plugins/modules/grafana_datasource.py | 202 +++++++++++--------------- 1 file changed, 81 insertions(+), 121 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 468313cb..11c15a5d 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -128,9 +128,9 @@ default: false org_id: description: - - Grafana Organisation ID in which the datasource should be created. + - Grafana organization ID in which the datasource should be created. - Not used when C(grafana_api_key) is set, because the C(grafana_api_key) only - belong to one organisation. + belong to one organization. default: 1 type: int state: @@ -687,10 +687,10 @@ def __init__(self, module): "Bearer %s" % module.params["grafana_api_key"] ) else: - self.headers["Authorization"] = basic_auth_header( - module.params["url_username"], module.params["url_password"] - ) - self.switch_organisation(module.params["org_id"]) + self.headers["Authorization"] = basic_auth_header(module.params['url_username'], module.params['url_password']) + if module.params['org_name']: + module.params['org_id'] = organization_by_name(module.params['org_name']) + self.switch_organization(module.params['org_id']) # }}} def _send_request(self, url, data=None, headers=None, method="GET"): @@ -721,10 +721,19 @@ def _send_request(self, url, data=None, headers=None, method="GET"): % (status_code, url, data), ) - def switch_organisation(self, org_id): + def switch_organization(self, org_id): url = "/api/user/using/%d" % org_id response = self._send_request(url, headers=self.headers, method="POST") + def organization_by_name(self, org_name): + url = "/api/user/orgs" + organizations = self._send_request(url, headers=self.headers, method='GET') + for org in organizations: + if org['name'] == org_name: + return org['orgId'] + + return self._module.fail_json(failed=True, msg="Current user isn't member of organization: %s" % org_name) + def datasource_by_name(self, name): datasource_exists = False ds = {} @@ -748,125 +757,76 @@ def setup_module_object(): argument_spec = base.grafana_argument_spec() argument_spec.update( - name=dict(required=True, type="str"), - uid=dict(type="str"), - ds_type=dict( - choices=[ - "graphite", - "prometheus", - "elasticsearch", - "influxdb", - "opentsdb", - "mysql", - "postgres", - "cloudwatch", - "alexanderzobnin-zabbix-datasource", - "grafana-azure-monitor-datasource", - "camptocamp-prometheus-alertmanager-datasource", - "sni-thruk-datasource", - "redis-datasource", - "loki", - "tempo", - ] - ), - ds_url=dict(type="str"), - access=dict(default="proxy", choices=["proxy", "direct"]), - database=dict(type="str", default=""), - user=dict(default="", type="str"), - password=dict(default="", no_log=True, type="str"), - basic_auth_user=dict(type="str"), - basic_auth_password=dict(type="str", no_log=True), - with_credentials=dict(default=False, type="bool"), - tls_client_cert=dict(type="str", no_log=True), - tls_client_key=dict(type="str", no_log=True), - tls_ca_cert=dict(type="str", no_log=True), - tls_skip_verify=dict(type="bool", default=False), - is_default=dict(default=False, type="bool"), - org_id=dict(default=1, type="int"), - es_version=dict( - type="str", - default="7.10+", - choices=["2", "5", "56", "60", "70", "7.7+", "7.10+", "8.0+"], - ), - max_concurrent_shard_requests=dict(type="int", default=256), - time_field=dict(default="@timestamp", type="str"), - time_interval=dict(type="str"), - interval=dict( - type="str", - choices=["", "Hourly", "Daily", "Weekly", "Monthly", "Yearly"], - default="", - ), - tsdb_version=dict(type="int", default=1, choices=[1, 2, 3]), - tsdb_resolution=dict( - type="str", default="second", choices=["second", "millisecond"] - ), - sslmode=dict( - default="disable", - choices=["disable", "require", "verify-ca", "verify-full"], - ), - trends=dict(default=False, type="bool"), - aws_auth_type=dict( - default="keys", choices=["keys", "credentials", "arn", "default"] - ), - aws_default_region=dict( - default="us-east-1", - choices=[ - "ap-northeast-1", - "ap-northeast-2", - "ap-southeast-1", - "ap-southeast-2", - "ap-south-1", - "ca-central-1", - "cn-north-1", - "cn-northwest-1", - "eu-central-1", - "eu-west-1", - "eu-west-2", - "eu-west-3", - "sa-east-1", - "us-east-1", - "us-east-2", - "us-gov-west-1", - "us-west-1", - "us-west-2", - ], - ), - aws_access_key=dict(default="", no_log=True, type="str"), - aws_secret_key=dict(default="", no_log=True, type="str"), - aws_credentials_profile=dict(default="", type="str"), - aws_assume_role_arn=dict(default="", type="str"), - aws_custom_metrics_namespaces=dict(type="str"), - azure_cloud=dict( - type="str", - default="azuremonitor", - choices=[ - "azuremonitor", - "chinaazuremonitor", - "govazuremonitor", - "germanyazuremonitor", - ], - ), - azure_tenant=dict(type="str"), - azure_client=dict(type="str"), - azure_secret=dict(type="str", no_log=True), - zabbix_user=dict(type="str"), - zabbix_password=dict(type="str", no_log=True), - additional_json_data=dict(type="dict", default={}, required=False), - additional_secure_json_data=dict(type="dict", default={}, required=False), - enforce_secure_data=dict(type="bool", default=False, required=False), + name=dict(required=True, type='str'), + uid=dict(type='str'), + ds_type=dict(choices=['graphite', + 'prometheus', + 'elasticsearch', + 'influxdb', + 'opentsdb', + 'mysql', + 'postgres', + 'cloudwatch', + 'alexanderzobnin-zabbix-datasource', + 'grafana-azure-monitor-datasource', + 'camptocamp-prometheus-alertmanager-datasource', + 'sni-thruk-datasource', + 'redis-datasource', + 'loki']), + ds_url=dict(type='str'), + access=dict(default='proxy', choices=['proxy', 'direct']), + database=dict(type='str', default=""), + user=dict(default='', type='str'), + password=dict(default='', no_log=True, type='str'), + basic_auth_user=dict(type='str'), + basic_auth_password=dict(type='str', no_log=True), + with_credentials=dict(default=False, type='bool'), + tls_client_cert=dict(type='str', no_log=True), + tls_client_key=dict(type='str', no_log=True), + tls_ca_cert=dict(type='str', no_log=True), + tls_skip_verify=dict(type='bool', default=False), + is_default=dict(default=False, type='bool'), + org_id=dict(default=1, type='int'), + org_name=dict(type='str'), + es_version=dict(type='str', default="7.10+", choices=["2", "5", "56", "60", + "70", "7.7+", "7.10+", + "8.0+"]), + max_concurrent_shard_requests=dict(type='int', default=256), + time_field=dict(default='@timestamp', type='str'), + time_interval=dict(type='str'), + interval=dict(type='str', choices=['', 'Hourly', 'Daily', 'Weekly', 'Monthly', 'Yearly'], default=''), + tsdb_version=dict(type='int', default=1, choices=[1, 2, 3]), + tsdb_resolution=dict(type='str', default='second', choices=['second', 'millisecond']), + sslmode=dict(default='disable', choices=['disable', 'require', 'verify-ca', 'verify-full']), + trends=dict(default=False, type='bool'), + aws_auth_type=dict(default='keys', choices=['keys', 'credentials', 'arn', 'default']), + aws_default_region=dict(default='us-east-1', choices=['ap-northeast-1', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-south-1', + 'ca-central-1', + 'cn-north-1', 'cn-northwest-1', + 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', + 'sa-east-1', + 'us-east-1', 'us-east-2', 'us-gov-west-1', 'us-west-1', 'us-west-2']), + aws_access_key=dict(default='', no_log=True, type='str'), + aws_secret_key=dict(default='', no_log=True, type='str'), + aws_credentials_profile=dict(default='', type='str'), + aws_assume_role_arn=dict(default='', type='str'), + aws_custom_metrics_namespaces=dict(type='str'), + azure_cloud=dict(type='str', default='azuremonitor', choices=['azuremonitor', 'chinaazuremonitor', 'govazuremonitor', 'germanyazuremonitor']), + azure_tenant=dict(type='str'), + azure_client=dict(type='str'), + azure_secret=dict(type='str', no_log=True), + zabbix_user=dict(type='str'), + zabbix_password=dict(type='str', no_log=True), + additional_json_data=dict(type='dict', default={}, required=False), + additional_secure_json_data=dict(type='dict', default={}, required=False), + enforce_secure_data=dict(type='bool', default=False, required=False) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, - required_together=[ - ["url_username", "url_password", "org_id"], - ["tls_client_cert", "tls_client_key"], - ], - mutually_exclusive=[ - ["url_username", "grafana_api_key"], - ["tls_ca_cert", "tls_skip_verify"], - ], + required_together=[['url_username', 'url_password', 'org_id'], ['tls_client_cert', 'tls_client_key']], + mutually_exclusive=[['url_username', 'grafana_api_key'], ['tls_ca_cert', 'tls_skip_verify'], ['org_id', 'org_name']], required_if=[ ["state", "present", ["ds_type", "ds_url"]], ["ds_type", "opentsdb", ["tsdb_version", "tsdb_resolution"]], From 146e5cbcfaf9c922842cf1fee799c4e50c05e498 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:28:06 +0100 Subject: [PATCH 02/11] fix: func call --- plugins/modules/grafana_datasource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 11c15a5d..6606c493 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -689,7 +689,7 @@ def __init__(self, module): else: self.headers["Authorization"] = basic_auth_header(module.params['url_username'], module.params['url_password']) if module.params['org_name']: - module.params['org_id'] = organization_by_name(module.params['org_name']) + module.params['org_id'] = self.organization_by_name(module.params['org_name']) self.switch_organization(module.params['org_id']) # }}} From e163f9352370ad709ab8e4ee13993fefa3f32c4a Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:33:07 +0100 Subject: [PATCH 03/11] docs: add org_name --- plugins/modules/grafana_datasource.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 6606c493..c3cdbc35 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -131,8 +131,16 @@ - Grafana organization ID in which the datasource should be created. - Not used when C(grafana_api_key) is set, because the C(grafana_api_key) only belong to one organization. + - Mutually exclusive with `org_name`. default: 1 type: int + org_name: + description: + - Grafana organization name in which the datasource should be created. + - Not used when C(grafana_api_key) is set, because the C(grafana_api_key) only + belong to one organization. + - Mutually exclusive with `org_id`. + type: str state: description: - Status of the datasource From 6106ba460a0f307acfca27623c73d2a29aa0276b Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:34:28 +0100 Subject: [PATCH 04/11] docs: add changelog fragment --- changelogs/fragments/332-datasource-by-org-name.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/332-datasource-by-org-name.yml diff --git a/changelogs/fragments/332-datasource-by-org-name.yml b/changelogs/fragments/332-datasource-by-org-name.yml new file mode 100644 index 00000000..0c8e265d --- /dev/null +++ b/changelogs/fragments/332-datasource-by-org-name.yml @@ -0,0 +1,4 @@ +--- + +minor_changes: + - Add parameter `org_name` to `grafana_datasource` From 409b58ba656374f03cbb92984c5307ca0298fe2c Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:36:03 +0100 Subject: [PATCH 05/11] chore: indention --- plugins/modules/grafana_datasource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index c3cdbc35..24899f21 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -738,7 +738,7 @@ def organization_by_name(self, org_name): organizations = self._send_request(url, headers=self.headers, method='GET') for org in organizations: if org['name'] == org_name: - return org['orgId'] + return org['orgId'] return self._module.fail_json(failed=True, msg="Current user isn't member of organization: %s" % org_name) From 7e66e05e1804e3509b62184e5130ae8d67710656 Mon Sep 17 00:00:00 2001 From: Moritz <15136847+Nemental@users.noreply.github.com> Date: Wed, 3 Jan 2024 16:36:31 +0100 Subject: [PATCH 06/11] typo Co-authored-by: Sebastian Gumprich --- plugins/modules/grafana_datasource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 24899f21..5638db6b 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -138,7 +138,7 @@ description: - Grafana organization name in which the datasource should be created. - Not used when C(grafana_api_key) is set, because the C(grafana_api_key) only - belong to one organization. + belongs to one organization. - Mutually exclusive with `org_id`. type: str state: From 48b7f4470ce83eefdaa53d89b7a978e5699b8372 Mon Sep 17 00:00:00 2001 From: Moritz <15136847+Nemental@users.noreply.github.com> Date: Wed, 3 Jan 2024 16:36:40 +0100 Subject: [PATCH 07/11] typo Co-authored-by: Sebastian Gumprich --- plugins/modules/grafana_datasource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 5638db6b..920a4542 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -130,7 +130,7 @@ description: - Grafana organization ID in which the datasource should be created. - Not used when C(grafana_api_key) is set, because the C(grafana_api_key) only - belong to one organization. + belongs to one organization. - Mutually exclusive with `org_name`. default: 1 type: int From ed1dd8ccdf08a81839aa4ff549d8e41bb8a1b14d Mon Sep 17 00:00:00 2001 From: Moritz <15136847+Nemental@users.noreply.github.com> Date: Wed, 3 Jan 2024 16:43:07 +0100 Subject: [PATCH 08/11] new var org_id for org switch Co-authored-by: Sebastian Gumprich --- plugins/modules/grafana_datasource.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 920a4542..68e4920c 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -696,9 +696,8 @@ def __init__(self, module): ) else: self.headers["Authorization"] = basic_auth_header(module.params['url_username'], module.params['url_password']) - if module.params['org_name']: - module.params['org_id'] = self.organization_by_name(module.params['org_name']) - self.switch_organization(module.params['org_id']) + org_id = self.organization_by_name(module.params['org_name']) if module.params['org_name'] else module.params['org_id'] + self.switch_organization(org_id) # }}} def _send_request(self, url, data=None, headers=None, method="GET"): From d51f67bbe16311f9047b8ee4e98a1d034d9b5f57 Mon Sep 17 00:00:00 2001 From: Moritz <15136847+Nemental@users.noreply.github.com> Date: Wed, 3 Jan 2024 16:54:36 +0100 Subject: [PATCH 09/11] improve user org list check list comprehension Co-authored-by: Sebastian Gumprich --- plugins/modules/grafana_datasource.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 68e4920c..ff193e95 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -735,9 +735,9 @@ def switch_organization(self, org_id): def organization_by_name(self, org_name): url = "/api/user/orgs" organizations = self._send_request(url, headers=self.headers, method='GET') - for org in organizations: - if org['name'] == org_name: - return org['orgId'] + orga = next((org for org in organizations if org['name'] == org_name)) + if orga: + return orga['orgId'] return self._module.fail_json(failed=True, msg="Current user isn't member of organization: %s" % org_name) From 3892d189b655971410204af0fec0fbae89213a7a Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 4 Jan 2024 09:07:20 +0100 Subject: [PATCH 10/11] chore: indent lines --- plugins/modules/grafana_datasource.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index ff193e95..9458c9b9 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -735,9 +735,9 @@ def switch_organization(self, org_id): def organization_by_name(self, org_name): url = "/api/user/orgs" organizations = self._send_request(url, headers=self.headers, method='GET') - orga = next((org for org in organizations if org['name'] == org_name)) - if orga: - return orga['orgId'] + orga = next((org for org in organizations if org['name'] == org_name)) + if orga: + return orga['orgId'] return self._module.fail_json(failed=True, msg="Current user isn't member of organization: %s" % org_name) From b21be5f9374ec541b7c622e5713172f7cae6e059 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 4 Jan 2024 10:37:24 +0100 Subject: [PATCH 11/11] style: formatting black --- plugins/modules/grafana_datasource.py | 202 +++++++++++++++++--------- 1 file changed, 130 insertions(+), 72 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 9458c9b9..1c0253b9 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -617,7 +617,6 @@ def get_datasource_payload(data): # datasource type related parameters if data["ds_type"] == "elasticsearch": - json_data["maxConcurrentShardRequests"] = data["max_concurrent_shard_requests"] json_data["timeField"] = data["time_field"] if data.get("interval"): @@ -695,8 +694,14 @@ def __init__(self, module): "Bearer %s" % module.params["grafana_api_key"] ) else: - self.headers["Authorization"] = basic_auth_header(module.params['url_username'], module.params['url_password']) - org_id = self.organization_by_name(module.params['org_name']) if module.params['org_name'] else module.params['org_id'] + self.headers["Authorization"] = basic_auth_header( + module.params["url_username"], module.params["url_password"] + ) + org_id = ( + self.organization_by_name(module.params["org_name"]) + if module.params["org_name"] + else module.params["org_id"] + ) self.switch_organization(org_id) # }}} @@ -734,12 +739,14 @@ def switch_organization(self, org_id): def organization_by_name(self, org_name): url = "/api/user/orgs" - organizations = self._send_request(url, headers=self.headers, method='GET') - orga = next((org for org in organizations if org['name'] == org_name)) + organizations = self._send_request(url, headers=self.headers, method="GET") + orga = next((org for org in organizations if org["name"] == org_name)) if orga: - return orga['orgId'] + return orga["orgId"] - return self._module.fail_json(failed=True, msg="Current user isn't member of organization: %s" % org_name) + return self._module.fail_json( + failed=True, msg="Current user isn't member of organization: %s" % org_name + ) def datasource_by_name(self, name): datasource_exists = False @@ -764,76 +771,127 @@ def setup_module_object(): argument_spec = base.grafana_argument_spec() argument_spec.update( - name=dict(required=True, type='str'), - uid=dict(type='str'), - ds_type=dict(choices=['graphite', - 'prometheus', - 'elasticsearch', - 'influxdb', - 'opentsdb', - 'mysql', - 'postgres', - 'cloudwatch', - 'alexanderzobnin-zabbix-datasource', - 'grafana-azure-monitor-datasource', - 'camptocamp-prometheus-alertmanager-datasource', - 'sni-thruk-datasource', - 'redis-datasource', - 'loki']), - ds_url=dict(type='str'), - access=dict(default='proxy', choices=['proxy', 'direct']), - database=dict(type='str', default=""), - user=dict(default='', type='str'), - password=dict(default='', no_log=True, type='str'), - basic_auth_user=dict(type='str'), - basic_auth_password=dict(type='str', no_log=True), - with_credentials=dict(default=False, type='bool'), - tls_client_cert=dict(type='str', no_log=True), - tls_client_key=dict(type='str', no_log=True), - tls_ca_cert=dict(type='str', no_log=True), - tls_skip_verify=dict(type='bool', default=False), - is_default=dict(default=False, type='bool'), - org_id=dict(default=1, type='int'), - org_name=dict(type='str'), - es_version=dict(type='str', default="7.10+", choices=["2", "5", "56", "60", - "70", "7.7+", "7.10+", - "8.0+"]), - max_concurrent_shard_requests=dict(type='int', default=256), - time_field=dict(default='@timestamp', type='str'), - time_interval=dict(type='str'), - interval=dict(type='str', choices=['', 'Hourly', 'Daily', 'Weekly', 'Monthly', 'Yearly'], default=''), - tsdb_version=dict(type='int', default=1, choices=[1, 2, 3]), - tsdb_resolution=dict(type='str', default='second', choices=['second', 'millisecond']), - sslmode=dict(default='disable', choices=['disable', 'require', 'verify-ca', 'verify-full']), - trends=dict(default=False, type='bool'), - aws_auth_type=dict(default='keys', choices=['keys', 'credentials', 'arn', 'default']), - aws_default_region=dict(default='us-east-1', choices=['ap-northeast-1', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-south-1', - 'ca-central-1', - 'cn-north-1', 'cn-northwest-1', - 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', - 'sa-east-1', - 'us-east-1', 'us-east-2', 'us-gov-west-1', 'us-west-1', 'us-west-2']), - aws_access_key=dict(default='', no_log=True, type='str'), - aws_secret_key=dict(default='', no_log=True, type='str'), - aws_credentials_profile=dict(default='', type='str'), - aws_assume_role_arn=dict(default='', type='str'), - aws_custom_metrics_namespaces=dict(type='str'), - azure_cloud=dict(type='str', default='azuremonitor', choices=['azuremonitor', 'chinaazuremonitor', 'govazuremonitor', 'germanyazuremonitor']), - azure_tenant=dict(type='str'), - azure_client=dict(type='str'), - azure_secret=dict(type='str', no_log=True), - zabbix_user=dict(type='str'), - zabbix_password=dict(type='str', no_log=True), - additional_json_data=dict(type='dict', default={}, required=False), - additional_secure_json_data=dict(type='dict', default={}, required=False), - enforce_secure_data=dict(type='bool', default=False, required=False) + name=dict(required=True, type="str"), + uid=dict(type="str"), + ds_type=dict( + choices=[ + "graphite", + "prometheus", + "elasticsearch", + "influxdb", + "opentsdb", + "mysql", + "postgres", + "cloudwatch", + "alexanderzobnin-zabbix-datasource", + "grafana-azure-monitor-datasource", + "camptocamp-prometheus-alertmanager-datasource", + "sni-thruk-datasource", + "redis-datasource", + "loki", + "tempo", + ] + ), + ds_url=dict(type="str"), + access=dict(default="proxy", choices=["proxy", "direct"]), + database=dict(type="str", default=""), + user=dict(default="", type="str"), + password=dict(default="", no_log=True, type="str"), + basic_auth_user=dict(type="str"), + basic_auth_password=dict(type="str", no_log=True), + with_credentials=dict(default=False, type="bool"), + tls_client_cert=dict(type="str", no_log=True), + tls_client_key=dict(type="str", no_log=True), + tls_ca_cert=dict(type="str", no_log=True), + tls_skip_verify=dict(type="bool", default=False), + is_default=dict(default=False, type="bool"), + org_id=dict(default=1, type="int"), + org_name=dict(type="str"), + es_version=dict( + type="str", + default="7.10+", + choices=["2", "5", "56", "60", "70", "7.7+", "7.10+", "8.0+"], + ), + max_concurrent_shard_requests=dict(type="int", default=256), + time_field=dict(default="@timestamp", type="str"), + time_interval=dict(type="str"), + interval=dict( + type="str", + choices=["", "Hourly", "Daily", "Weekly", "Monthly", "Yearly"], + default="", + ), + tsdb_version=dict(type="int", default=1, choices=[1, 2, 3]), + tsdb_resolution=dict( + type="str", default="second", choices=["second", "millisecond"] + ), + sslmode=dict( + default="disable", + choices=["disable", "require", "verify-ca", "verify-full"], + ), + trends=dict(default=False, type="bool"), + aws_auth_type=dict( + default="keys", choices=["keys", "credentials", "arn", "default"] + ), + aws_default_region=dict( + default="us-east-1", + choices=[ + "ap-northeast-1", + "ap-northeast-2", + "ap-southeast-1", + "ap-southeast-2", + "ap-south-1", + "ca-central-1", + "cn-north-1", + "cn-northwest-1", + "eu-central-1", + "eu-west-1", + "eu-west-2", + "eu-west-3", + "sa-east-1", + "us-east-1", + "us-east-2", + "us-gov-west-1", + "us-west-1", + "us-west-2", + ], + ), + aws_access_key=dict(default="", no_log=True, type="str"), + aws_secret_key=dict(default="", no_log=True, type="str"), + aws_credentials_profile=dict(default="", type="str"), + aws_assume_role_arn=dict(default="", type="str"), + aws_custom_metrics_namespaces=dict(type="str"), + azure_cloud=dict( + type="str", + default="azuremonitor", + choices=[ + "azuremonitor", + "chinaazuremonitor", + "govazuremonitor", + "germanyazuremonitor", + ], + ), + azure_tenant=dict(type="str"), + azure_client=dict(type="str"), + azure_secret=dict(type="str", no_log=True), + zabbix_user=dict(type="str"), + zabbix_password=dict(type="str", no_log=True), + additional_json_data=dict(type="dict", default={}, required=False), + additional_secure_json_data=dict(type="dict", default={}, required=False), + enforce_secure_data=dict(type="bool", default=False, required=False), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, - required_together=[['url_username', 'url_password', 'org_id'], ['tls_client_cert', 'tls_client_key']], - mutually_exclusive=[['url_username', 'grafana_api_key'], ['tls_ca_cert', 'tls_skip_verify'], ['org_id', 'org_name']], + required_together=[ + ["url_username", "url_password", "org_id"], + ["tls_client_cert", "tls_client_key"], + ], + mutually_exclusive=[ + ["url_username", "grafana_api_key"], + ["tls_ca_cert", "tls_skip_verify"], + ["org_id", "org_name"], + ], required_if=[ ["state", "present", ["ds_type", "ds_url"]], ["ds_type", "opentsdb", ["tsdb_version", "tsdb_resolution"]],