Tools for sending messages to a Slack channel via the Slack API. Created for my personal use.
Description: This is an example script for using slacksenderutils to send notification messages to Slack via webhooks. Send arbitrary messages as your bot user, send expected downtime, or server up notifications.
Description: This contains a wrapper class for building json payloads to send messages to Slack as well as a few basica utility functions.
Before this will work, you will need to do the following…
- Get a Slack webhook url. (More info at: https://api.slack.com/incoming-webhooks)
- Rename slack_config_example.py –> slack_config.py
- Add the following information to slack_config.py
- Your Slack webhook url
- Slack webhook url to send messages to yourself
- The default username you want to send messages as
- Slack channel to send messages to by default
- Slack channel to send messages to when you are developing/testing/debugging
- Verify that .gitignore lists *config.py as an ignored file and that slack_config.py will not be pushed to git. This should already be set up properly for you.
Required arguments:
-m, --message '<message>'
Message to send to the channel.
'up'
will send a pre-formatted message stating the server is back up. Default color: (good/green)'down <number> <time unit>'
(ex.'down 20 min') will send a pre-formatted message that the server will be going down for maintenance for that amount of time. Default color: (warn/yellow)- Any other message will be sent as-is. Default color: (info/gray)
Optional arguments:
-h, --help
Show help message and exit
-c, --color <color>
Color for message. Color Options: gray/info (default), green/good, yellow/warn, red/danger, purple
-d, --debug
Enable debug mode. Send message to test channel and show json output in console.
--dry
Enable dryrun mode. Message will not be sent.
-r, --room <room>
Slack channel room to send the message to.
-_t, --title <title>
Set a message title.