diff --git a/README.md b/README.md index 6d23f1b9..b6f8cfe2 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Click on the name of a plugin or module to view that content's documentation: - [grafana_plugin](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_plugin_module.html) - [grafana_team](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_team_module.html) - [grafana_user](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_user_module.html) + - [grafana_silence](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_silence_module.html) ## Supported Grafana versions diff --git a/changelogs/fragments/358-role-grafana-silence.yml b/changelogs/fragments/358-role-grafana-silence.yml new file mode 100644 index 00000000..a72161f0 --- /dev/null +++ b/changelogs/fragments/358-role-grafana-silence.yml @@ -0,0 +1,2 @@ +minor_changes: + - Add role components for `grafana_silence` module \ No newline at end of file diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index b1e1cf20..4046e336 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -45,4 +45,15 @@ path: test_dashboard.json overwrite: true + grafana_silences: + - comment: molecule test + created_by: ansible + ends_at: "2030-01-01T00:00:00.000Z" + matchers: + - isEqual: true + isRegex: false + name: environment + value: test + starts_at: "2029-12-31T23:23:59.000Z" + roles: [{role: community.grafana.grafana}] diff --git a/plugins/modules/grafana_silence.py b/plugins/modules/grafana_silence.py index 151b3659..35f54a3d 100644 --- a/plugins/modules/grafana_silence.py +++ b/plugins/modules/grafana_silence.py @@ -78,90 +78,90 @@ --- - name: Create a silence community.grafana.grafana_silence: - grafana_url: "https://grafana.example.com" - grafana_api_key: "{{ some_api_token_value }}" - comment: "a testcomment" - created_by: "me" - starts_at: "2029-07-29T08:45:45.000Z" - ends_at: "2029-07-29T08:55:45.000Z" - matchers: - - isEqual: true - isRegex: true - name: environment - value: test - state: present + grafana_url: "https://grafana.example.com" + grafana_api_key: "{{ some_api_token_value }}" + comment: "a testcomment" + created_by: "me" + starts_at: "2029-07-29T08:45:45.000Z" + ends_at: "2029-07-29T08:55:45.000Z" + matchers: + - isEqual: true + isRegex: true + name: environment + value: test + state: present - name: Delete a silence community.grafana.grafana_silence: - grafana_url: "https://grafana.example.com" - grafana_api_key: "{{ some_api_token_value }}" - comment: "a testcomment" - created_by: "me" - starts_at: "2029-07-29T08:45:45.000Z" - ends_at: "2029-07-29T08:55:45.000Z" - matchers: - - isEqual: true - isRegex: true - name: environment - value: test - state: absent + grafana_url: "https://grafana.example.com" + grafana_api_key: "{{ some_api_token_value }}" + comment: "a testcomment" + created_by: "me" + starts_at: "2029-07-29T08:45:45.000Z" + ends_at: "2029-07-29T08:55:45.000Z" + matchers: + - isEqual: true + isRegex: true + name: environment + value: test + state: absent """ RETURN = """ --- silence: - description: Information about the silence - returned: On success - type: complex - contains: - id: - description: The id of the silence - returned: success - type: str - sample: - - ec27df6b-ac3c-412f-ae0b-6e3e1f41c9c3 - comment: - description: The comment of the silence - returned: success - type: str - sample: - - this is a test - createdBy: - description: The author of the silence - returned: success - type: str - sample: - - me - startsAt: - description: The begin timestamp of the silence - returned: success - type: str - sample: - - "2029-07-29T08:45:45.000Z" - endsAt: - description: The end timestamp of the silence - returned: success - type: str - sample: - - "2029-07-29T08:55:45.000Z" - matchers: - description: The matchers of the silence - returned: success - type: list - sample: - - [{"isEqual": true, "isRegex": true, "name": "environment", "value": "test"}] - status: - description: The status of the silence - returned: success - type: dict - sample: - - {"state": "pending"} - updatedAt: - description: The timestamp of the last update for the silence - returned: success - type: str - sample: - - "2023-07-27T13:27:33.042Z" + description: Information about the silence + returned: On success + type: complex + contains: + id: + description: The id of the silence + returned: success + type: str + sample: + - ec27df6b-ac3c-412f-ae0b-6e3e1f41c9c3 + comment: + description: The comment of the silence + returned: success + type: str + sample: + - this is a test + createdBy: + description: The author of the silence + returned: success + type: str + sample: + - me + startsAt: + description: The begin timestamp of the silence + returned: success + type: str + sample: + - "2029-07-29T08:45:45.000Z" + endsAt: + description: The end timestamp of the silence + returned: success + type: str + sample: + - "2029-07-29T08:55:45.000Z" + matchers: + description: The matchers of the silence + returned: success + type: list + sample: + - [{"isEqual": true, "isRegex": true, "name": "environment", "value": "test"}] + status: + description: The status of the silence + returned: success + type: dict + sample: + - {"state": "pending"} + updatedAt: + description: The timestamp of the last update for the silence + returned: success + type: str + sample: + - "2023-07-27T13:27:33.042Z" """ import json diff --git a/roles/grafana/README.md b/roles/grafana/README.md index f46434ed..f76e687f 100644 --- a/roles/grafana/README.md +++ b/roles/grafana/README.md @@ -163,6 +163,13 @@ Configure Grafana organizations, dashboards, folders, datasources, teams and use | webhook_password | no | | webhook_url | no | | webhook_username | no | +| [**grafana_silence**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_silence_module.html) | +| comment | yes | +| created_by | yes | +| ends_at | yes | +| matchers | yes | +| starts_at | yes | +| state | no | ## Example Playbook diff --git a/roles/grafana/defaults/main.yml b/roles/grafana/defaults/main.yml index 6a84370d..9756a133 100644 --- a/roles/grafana/defaults/main.yml +++ b/roles/grafana/defaults/main.yml @@ -7,3 +7,4 @@ grafana_datasources: [] grafana_folders: [] grafana_dashboards: [] grafana_notification_channels: [] +grafana_silences: [] diff --git a/roles/grafana/meta/main.yml b/roles/grafana/meta/main.yml index 47d4af5b..b5df4219 100644 --- a/roles/grafana/meta/main.yml +++ b/roles/grafana/meta/main.yml @@ -2,7 +2,7 @@ galaxy_info: role_name: grafana author: community - description: Configure Grafana organizations, dashboards, folders, datasources, teams and users + description: Configure Grafana organizations, dashboards, folders, datasources, silences, teams and users license: GPLv3 min_ansible_version: "2.14" galaxy_tags: [grafana, monitoring] diff --git a/roles/grafana/tasks/main.yml b/roles/grafana/tasks/main.yml index 82bbc633..1665a856 100644 --- a/roles/grafana/tasks/main.yml +++ b/roles/grafana/tasks/main.yml @@ -201,3 +201,15 @@ loop: "{{ grafana_dashboards }}" loop_control: {loop_var: dashboard} tags: [dashboard, molecule-idempotence-notest] + + - name: Manage silence + community.grafana.grafana_silence: + comment: "{{ silence.comment }}" + created_by: "{{ silence.created_by }}" + starts_at: "{{ silence.starts_at }}" + ends_at: "{{ silence.ends_at }}" + matchers: "{{ silence.matchers }}" + state: "{{ silence.state | default(omit) }}" + loop: "{{ grafana_silences }}" + loop_control: {loop_var: silence} + tags: silence