Skip to content

Commit 626d7f0

Browse files
authored
Merge pull request #14 from GabrielSalla/isolate-slack-plugin
Isolate Slack plugin
2 parents 772dcdd + 537b5ea commit 626d7f0

File tree

17 files changed

+37
-25
lines changed

17 files changed

+37
-25
lines changed

configs.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ time_zone: America/Sao_Paulo
6161
controller_process_schedule: "* * * * *"
6262
# How many monitors can be processed at the same time by the Controller
6363
controller_concurrency: 5
64-
# Enable or disable the Slack websocket
65-
# The websocket is used to receive the mentions and button presses from notification messages
66-
slack_websocket_enabled: true
6764

6865
# Executor settings
6966
# How many tasks can be executed at the same time by each Executor

docs/monitor.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ from monitor_utils import (
4343
IssueOptions,
4444
MonitorOptions,
4545
PriorityLevels,
46-
SlackNotification,
4746
)
4847
```
4948

docs/plugin_slack.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Slack Plugin
22
The Slack plugin offers an interface to interact with Sentinela through Slack. It allows users to receive notifications from Sentinela in a Slack channel while also providing useful commands from notification buttons or Slack messages mentioning the Sentinela bot.
33

4+
## Environment variables
5+
The following environment variables are used by the Slack plugin:
6+
- `SLACK_TOKEN`: Used to send messages to Slack. Example: `xoxb-1234567890-1234567890123-12345678901234567890abcdef`
7+
- `SLACK_WEBSOCKET_ENABLED`: Used to enable the websocket to receive events from Slack. Possible values are `true` or `false`.
8+
- `SLACK_APP_TOKEN` Used to start the websocket, to receive the events from interactions with the Sentinela Slack app. Example: `xapp-1234567890-1234567890123-12345678901234567890abcdef`
9+
410
## Slack commands
511
Sentinela provides two main ways to interact through Slack:
612
1. **Buttons** in notifications sent to a Slack channel.

docs/usage.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ THe monitors path is also defined in the `configs.yaml` file. By default, it's s
99
For the secrets, the application expects them to be set as environment variables.
1010
- `DATABASE_APPLICATION`: The database DSN that will be used to connect to the application database. This database will not be accessible through the databases interface for the monitors.
1111
- Every variable that starts with `DATABASE`, besides the application database, will have a connection pool instantiated, that can be used in the monitors to query data from them.
12-
- `SLACK_TOKEN` and `SLACK_APP_TOKEN` will be used as the token to send messages to Slack and to start the websocket, to receive the events from interactions with the Sentinela Slack app.
1312
- `AWS_ENDPOINT_URL`: The AWS endpoint to be used for local testing, without the need of a real SQS queue. When using the `motoserver` container as an AWS mock, it should be `http://motoserver:5000`. Don't set this environment variable when using a real SQS queue.
1413
- `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN`: The service credentials to access the AWS SQS queue.
1514

15+
> [!IMPORTANT]
16+
> Check the documentation for the plugins that are being used to see if they have environment variables of their own.
17+
1618
## Development execution
1719
Development execution should be used when developing or testing the platform features. It's not intended to be used to develop monitors as it might set variables that might interfere with the monitors execution.
1820

resources/kubernetes_template/config_map.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ data:
6363
controller_process_schedule: "* * * * *"
6464
# How many monitors can be processed at the same time by the Controller
6565
controller_concurrency: 5
66-
# Enable or disable the Slack websocket
67-
# The websocket is used to receive the mentions and button presses from notification messages
68-
slack_websocket_enabled: true
6966
7067
# Executor settings
7168
# How many tasks can be executed at the same time by each Executor

resources/kubernetes_template/controller.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
value: C07NCL94SDT
2929
- name: SAMPLE_SLACK_MENTION
3030
value: U07NFGGMB98
31+
- name: SLACK_WEBSOCKET_ENABLED
32+
value: "true"
3133
- name: DATABASE_APPLICATION
3234
valueFrom:
3335
secretKeyRef:

resources/kubernetes_template/executor.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
value: C07NCL94SDT
2929
- name: SAMPLE_SLACK_MENTION
3030
value: U07NFGGMB98
31+
- name: SLACK_WEBSOCKET_ENABLED
32+
value: "true"
3133
- name: DATABASE_APPLICATION
3234
valueFrom:
3335
secretKeyRef:

src/components/controller/controller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,4 @@ async def run():
169169
sleep_time = time_until_next_trigger(controller_process_schedule)
170170
await app.sleep(sleep_time)
171171

172-
# Wait for Slack websocket and all tasks to finish
173172
_logger.info("Finishing")

src/configs/configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Configs:
2828

2929
controller_process_schedule: str
3030
controller_concurrency: int
31-
slack_websocket_enabled: bool
3231

3332
executor_concurrency: int
3433
executor_sleep: int

src/plugins/slack/notifications/slack_notification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import os
34
from dataclasses import dataclass
45
from functools import partial
56
from typing import Any, Coroutine
@@ -163,7 +164,7 @@ async def _build_notification_buttons(
163164
"""Build the buttons that will be shown in the notification message"""
164165
buttons: list[slack.MessageButton] = []
165166

166-
if not configs.slack_websocket_enabled:
167+
if os.environ.get("SLACK_WEBSOCKET_ENABLED", "false") == "false":
167168
return buttons
168169

169170
if alert.status == AlertStatus.solved:

0 commit comments

Comments
 (0)