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

Adding support for slack #49

Merged
merged 16 commits into from
Feb 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ spec:
- get
- list
- watch
- apiGroups:
- slack.stakater.com
resources:
- channels
verbs:
- get
- list
- watch
- apiGroups:
- hive.openshift.io
resources:
Expand Down
3 changes: 3 additions & 0 deletions charts/grafana-oncall/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ rules:
- apiGroups: ["hive.openshift.io"]
resources: ["clusterdeployments"]
verbs: ["get", "list", "watch"]
- apiGroups: ["slack.stakater.com"]
resources: ["channels"]
verbs: ["get", "list", "watch"]
- apiGroups: ["hive.openshift.io"]
resources: ["syncsets"]
verbs: ["*"]
Expand Down
3 changes: 3 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ rules:
- apiGroups: ["hive.openshift.io"]
resources: ["syncsets"]
verbs: ["*"]
- apiGroups: ["slack.stakater.com"]
resources: ["channels"]
verbs: ["create", "get", "list", "patch", "update", "watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["*"]
Expand Down
21 changes: 21 additions & 0 deletions roles/grafana_cloud_operator/tasks/grafana_oncall_hub_spoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@

- name: Integration creation
block:
- name: Fetch Slack Channel from clusterdeployment namespace
kubernetes.core.k8s_info:
api_version: slack.stakater.com/v1alpha1
kind: Channel
namespace: "{{ item.namespace }}"
register: slack_channel_info
loop: "{{ create_integration_for }}"
loop_control:
label: "{{ item.namespace }}"

- name: Extract Channel id from slack channel
ansible.builtin.set_fact:
slack_channel_ids: "{{ slack_channel_ids | default([]) + [{'name': item.metadata.name, 'slack_id': item.status.id}] }}"
loop: "{{ slack_channel_info.results | map(attribute='resources') | flatten }}"
loop_control:
label: "{{ item.metadata.name }}"

- name: Create a new integration in Grafana OnCall integration for each ClusterDeployment that does not have one
ansible.builtin.uri:
url: "{{ grafana_cloud_operator_grafana_cloud_integrations_api_url }}"
Expand All @@ -48,6 +65,10 @@
body:
type: "alertmanager"
name: "{{ item.name }}"
default_route:
slack:
channel_id: "{{ slack_channel_ids[0].slack_id }}"
enabled: true
status_code: [200, 201]
register: grafana_integration_response
loop: "{{ create_integration_for }}"
Expand Down
Loading