Code for managing Cleanup of Stale Channels
Switch branches/tags
Nothing to show
Clone or download
royrapoport Merge pull request #176 from royrapoport/master
do not warn or archive channels whose name contains the string 'rands'
Latest commit 6545731 Mar 25, 2018
Permalink
Failed to load latest commit information.
bin Make scripts POSIX and decrease coverage threshold to account for new… Oct 12, 2017
tests Update method for filtering out empty list elements for Python 3 Dec 16, 2017
utils Try not to pollute the namespace with extra configs Aug 31, 2017
.gitignore change token pattern to *_token.txt Dec 28, 2015
.travis.yml DRY install and test between Dockerfile and .travis.yml. Oct 12, 2017
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT.md with a link to the Rands Leadership Slack CoC Jun 22, 2017
Dockerfile Not alpine :( Dec 11, 2017
LICENSE Initial commit Dec 27, 2015
Procfile Adding Heroku scheduling Dec 29, 2015
README.md Filter out empty list items from array environment variables Dec 14, 2017
announcer.py Merge branch 'master' into singleton-config Sep 13, 2017
archiver.py Archive then warn Sep 6, 2017
build-requirements.txt WIP on adding vulture Aug 31, 2017
closure.txt mention that unarchiving a channel will not keep it around sans messa… Oct 25, 2016
config.py Update method for filtering out empty list elements for Python 3 Dec 16, 2017
configuration.yaml do not warn or archive channels whose name contains the string 'rands' Mar 25, 2018
destalinator.py Channel ignore regex patterns now match anywhere in the channel name … Dec 11, 2017
docker-deploy.sh Add Docker build steps to the Travis build Aug 12, 2017
executor.py Prefer accessing config directly over using local vars if they are us… Aug 31, 2017
flagger.md ordering of tokens for deleting a rule was incorrect in docs Mar 19, 2017
flagger.py Merge branch 'master' into singleton-config Sep 13, 2017
requirements.txt Add Sentry exception handling Jun 26, 2017
scheduler.py Avoid scheduling if RUN_ONCE is set, to workaround upstream timezone bug Oct 11, 2017
slackbot.py Fix unicode encoding of Slack message posts Jun 7, 2017
slacker.py Merge branch 'master' into reuse-retry-on-other-gets Sep 13, 2017
warner.py Archive then warn Sep 6, 2017
warning.txt added a bit about unarchiving and tried to make archiving less scary. Dec 30, 2015

README.md

destalinator

Code for managing Cleanup of Stale Channels

Build Status

Coverage Status

Making it work in your environment

You'll need to install a few libraries: pip install -r requirements.txt

You'll also need to change configuration.yaml appropriately. warner.py and archiver.py should then work from the command line. Productionized automated deployments and running on a schedule are left unspecified because every production environment is unique.

That said, if you're running on Heroku, you can create a single clock process that runs python scheduler.py.

Development

We recommend using virtualenv to manage your development environment.

pip install virtualenv
virtualenv env
source env/bin/activate

In addition to requirements.txt, there's also build-requirements.txt for development environments. ./bin/install will install both.

Docker

Build a local docker image:

docker build . -t destalinator

You can also use the prebuilt Docker image at randsleadershipslack/destalinator.

Checking code coverage locally

docker run -it -p 8080:80 destalinator sh -c "coverage html --skip-covered && python -m http.server 80"

open http://localhost:8080/htmlcov/

Components

Warner

The Warner notifies channels that have been inactive for a period of time.

Archiver

The archiver archives channels that have been inactive for a period of time.

Announcer

The Announcer will notify a channel of all new channels created within a period of time.

Flagger

The Flagger uses a ruleset defined in a specific channel to perform actions such as notifying channels of messages that have received a certain number of reactions.

Setup

Inside configuration.yaml

slack_name

You'll want to change this to the name of your Slack

warn_threshold and archive_threshold

Tune these two variables to decide how long after inactivity a channel should be warned for inactivity and then subsequently archived.

general_message_channel, announce_channel, control_channel, and log_channel

These channels need to be manually created by you in your Slack.

Environment variables

All configs in configuration.yaml are overrideable through environment variables with the same name prefixed by DESTALINATOR_ (e.g. activated -> DESTALINATOR_ACTIVATED). Set array environment variables (e.g. DESTALINATOR_IGNORE_CHANNELS) by comma delimiting items. If you only have one value for an array type environment variable add a training comma to denote the variable as a list.

DESTALINATOR_SB_TOKEN (Required)

  1. Make sure the Slackbot app is installed for your Slack
  2. Add a Slackbot integration, and copy the token parameter from the URL provided

DESTALINATOR_API_TOKEN (Required)

The best way to get an API_TOKEN is to create a new Slack App.

Once you create and name your app on your team, go to "OAuth & Permissions" to give it the following permission scopes:

  • channels:history
  • channels:read
  • channels:write
  • chat:write:bot
  • chat:write:user
  • emoji:read
  • users:read

After saving, you can copy the OAuth Access Token value from the top of the same screen. It probably starts with xox.

DESTALINATOR_ACTIVATED (Required)

Destalinator can be chatty and make potentially big changes to a Slack team (by warning or archiving a large amount of channels), especially when first installed.

To minimize the risk of making a mistake, Destalinator will run in a dry-run mode unless the DESTALINATOR_ACTIVATED environment variable exists. Set it to true and Destalinator is "active." If you want to remain in dry-run mode, ensure this variable is unset/does not exist.

DESTALINATOR_LOG_LEVEL (Optional; Default: WARNING)

Tune your preferred log level for server logs or local debugging. Does not affect the ENV var specified by output_debug_env_varname.

DESTALINATOR_LOG_TO_CHANNEL (Optional)

If you would like to log to a Slack channel as well as the default log destination, you can set true here. The channel will then be pulled from log_channel in configuration.yaml.

DESTALINATOR_EARLIEST_ARCHIVE_DATE (Optional)

If you don't want to start archiving channels until a certain date right after introducing destalinator to your team, you can set an ISO-8601 date here (YYYY-mm-dd).

DESTALINATOR_FLAGGER_DISABLED (Optional)

Disable the Flagger by setting DESTALINATOR_FLAGGER_DISABLED to true

DESTALINATOR_SCHEDULE_HOUR (Optional)

When should the destalinator run? Defaults to 4. Which time that means depends on your operating system time zone. Good luck!

SENTRY_DSN (Optional)

Note: No DESTALINATOR_ prefix! The Sentry plugin uses this environment variable on its own.

If you would like to configure exception handling & tracking with Sentry, set up a Sentry account and configure this environment variable with the appropriate DSN value.

If you're on Heroku, you can provision this with:

heroku addons:create sentry:f1

Code of Conduct

As part of the Rands Leadership Slack community, the Rands Leadership Slack Code of Conduct applies to this project.