Flask backend application for RedAlert: simple incident management in Slack
1.5K
RedAlert is a basic Slack bot to helps in incident management by using Slack channels. It's nowhere as complete as Netflix' "Dispatch" incident manager, nor does it aims to be.
RedAlert is inspired by the work described by ManoMano SRE team in this blog post. Unfortunatly, ManoMano's bot (FireFighter) is closed source for now (I've asked its author who confirmed it).
This project aims to provide an open source alternative.
The Slack App is not yet packaged for Slack easy installation. For now, you will have to create the App yourself.
Add a new App in you Slack administration page (api.slack.com/apps).

Once the App is created, you will see something like this.

Click on the "Slash Commands" menu to add a new Slash Command. It will allow us to communicate with the future Python App that we will deploy in the next chapter and send commands to it.
/incident is a suggestion but you can put anything (/redalert, etc). What really matters is that the Request URL parameters has to point to https://[your-redalert-webserver]/incident URL.

Once this is done, enable "Interactivity" in the main App page. This will allow us to open up dialogs, when you type /incident open for example.
Once again, the URL pattern is important there. The URL has to point to your python webserver and has to finish by "/dialog".

This step is optionnal but having a nice looking App is always better in my opinion. You can customize the App by adding a Icon and some description.
![]()
![]()
The last thing we have to do is to configure authorizations for your app/slack bot. This is done in the OAuth & Permissions menu.
The following permissions are the very least permissions that you have to give to the bot to make it work.
/incident commands/incident list commandNote: if you want to use redalert in private channels or group conversations, you will have to add more permissions.

Now the App is finished from the Slack Administration App page point of view. You can now deploy it in your Slack workspace.
Note: should you change the permissions, you will have to redeploy it.


The very last step it to get the Slack Bot Token which will be required by our Python webapp to authenticate in your Slack workspace.

On Ubuntu 18.04
apt install python3-pip
pip3 install flask slackclient
Get the sources
git clone https://github.com/zwindler/redalert && cd redalert
Export SLACK_BOT_TOKEN variable (with the value found in the Slack Apps page) and run redalert.py
export SLACK_BOT_TOKEN=xoxb-xxxx-xxxx-xxxx
./redalert.py
As an alternative, you can also run or build yourself the Docker image of the redalert flask app
Inside redalert repository, simply run docker build
docker build -t redalert .
docker run -it -e SLACK_BOT_TOKEN=xoxb-your-own-slack-bot-token redalert
docker run -it -e SLACK_BOT_TOKEN=xoxb-your-own-slack-bot-token zwindler/redalert
redalert comes with some small level of customisation, including for now only the various incident severity levels (more features coming soon, see features chapter).
To customize it, you can either :
config.py configuration file coming with the repo by modifying itdocker run -it -e SLACK_BOT_TOKEN=xoxb-your-own-slack-bot-token -v custom_config.py:/home/redalert/custom_config.py zwindler/redalert
The config.py file is a standard Flask configuration file. It allows multiple configurations, including a default one for all your environments and a system of overrides described here.
For now, the only configurable part are :
The severity levels can be configured through the SEVERITY_LEVELS variable. You can modify the config.py file like this for example:
class Config(object):
# Alternative Star Trek(tm) inspired alert levels
SEVERITY_LEVELS = [
{
"label": "Red Alert",
"value": "redalert"
},
{
"label": "Yellow Alert",
"value": "yellowalert"
},
{
"label": "Captain Announcement",
"value": "announcement"
}
]
Note: you cannot use "always" as a value for the severity levels
Depending on the severity of the incident, you can decide to always add some individual (through their slack user ID).
The "always" code means that no matter the severity, this contact will always be included in the incident, in addition to the IDs added afterward in the various severities.
The following labels (sev1, sev2, ...) have to correspond to actual severity levels, as configured in the INCLUDE_IN_INCIDENT variable.
The values are user comma separated user lists like in this example:
class Config(object):
INCLUDE_IN_INCIDENT = {
"always" : ["U010PPYMH33"],
"sev1" : ["U0105K7EFNX", "U0xxxxxxxx"],
"sev2" : ["U0105K7EFNX"],
"sev3" : [],
"sev4" : [],
"sev5" : []
}
Note: the UserIDs HAVE TO exist in your Slack workspace or the webapp will crash.
Content type
Image
Digest
Size
47.8 MB
Last updated
almost 6 years ago
docker pull zwindler/redalert