diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f5f60d67..8510ca7f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,13 @@ Grafana Collection Release Notes .. contents:: Topics +v1.6.0 +====== + +Minor Changes +------------- + +- community.grafana.grafana_datasource supports alertmanager. v1.5.3 ====== diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 1ec36958..8ec95a20 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -41,6 +41,7 @@ - camptocamp-prometheus-alertmanager-datasource - loki - redis-datasource + - alertmanager type: str ds_url: description: @@ -209,6 +210,14 @@ - Use trends or not for zabbix datasource type. type: bool default: False + alertmanager_implementation: + description: + - The implementation to set for the alertmanager datasource type. + choices: + - mimir + - cortex + - prometheus + type: str aws_auth_type: description: - Type for AWS authentication for CloudWatch datasource type (authType of grafana @@ -590,6 +599,9 @@ def get_datasource_payload(data): json_data['tlsSkipVerify'] = True # datasource type related parameters + if data['ds_type'] == 'alertmanager': + json_data['implementation'] = data['alertmanager_implementation'] + if data['ds_type'] == 'elasticsearch': json_data['maxConcurrentShardRequests'] = data['max_concurrent_shard_requests'] @@ -730,7 +742,8 @@ def setup_module_object(): 'camptocamp-prometheus-alertmanager-datasource', 'sni-thruk-datasource', 'redis-datasource', - 'loki']), + 'loki', + 'alertmanager']), ds_url=dict(type='str'), access=dict(default='proxy', choices=['proxy', 'direct']), database=dict(type='str', default=""), @@ -756,6 +769,7 @@ def setup_module_object(): 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'), + alertmanager_implementation=dict(choices=['mimir', 'cortex', 'prometheus']), 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', diff --git a/tests/integration/targets/grafana_datasource/tasks/alertmanager.yml b/tests/integration/targets/grafana_datasource/tasks/alertmanager.yml new file mode 100644 index 00000000..6e52c8e8 --- /dev/null +++ b/tests/integration/targets/grafana_datasource/tasks/alertmanager.yml @@ -0,0 +1,80 @@ +- name: Create alertmanager datasource + register: result + grafana_datasource: + name: datasource-alertmanager + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + org_id: '1' + ds_type: alertmanager + ds_url: alertmanager.company.com:9093 + alertmanager_implementation: prometheus + +- debug: + var: result + +- assert: + that: + - result.changed + - "result.msg == 'Datasource datasource-alertmanager created'" + +- name: Check alertmanager datasource creation idempotency + register: result + grafana_datasource: + name: datasource-alertmanager + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + org_id: '1' + ds_type: alertmanager + ds_url: alertmanager.company.com:9093 + alertmanager_implementation: prometheus + +- debug: + var: result + +- assert: + that: + - not result.changed + - result.datasource.basicAuth == false + - result.datasource.isDefault == false + - result.datasource.jsonData.sslmode == 'verify-full' + - result.datasource.jsonData.tlsAuth == false + - result.datasource.jsonData.tlsAuthWithCACert == false + - result.datasource.name == 'datasource-alertmanager' + - result.datasource.orgId == 1 + - result.datasource.type == 'alertmanager' + - result.datasource.url == 'alertmanager.company.com:9093' + - result.datasource.withCredentials == false + +- name: Delete alertmanager datasource + register: result + grafana_datasource: + name: datasource-alertmanager + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + state: absent + +- debug: + var: result + +- assert: + that: + - result.changed + +- name: Delete alertmanager datasource + register: result + grafana_datasource: + name: datasource-alertmanager + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + state: absent + +- debug: + var: result + +- assert: + that: + - not result.changed