Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding ansible role for silences #358

Merged
merged 10 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/358-role-grafana-silence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Add role components for `grafana_silence` module
11 changes: 11 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
152 changes: 76 additions & 76 deletions plugins/modules/grafana_silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions roles/grafana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions roles/grafana/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ grafana_datasources: []
grafana_folders: []
grafana_dashboards: []
grafana_notification_channels: []
grafana_silences: []
2 changes: 1 addition & 1 deletion roles/grafana/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions roles/grafana/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading