Easily construct and send formatted emails and Slack alerts.
Project description
Easily construct and send formatted emails and Slack alerts.
Install
pip install alert_msgs
If using Slack as an alert destination, you will need to set up a Slack App and get a bot token configured with OAuth permissions.
- Go to Slack Apps. Click Create New App -> From Scratch (give it a name, select your workspace)
- Navigate to the OAuth & Permissions on the left sidebar and scroll down to the Bot Token Scopes section. Add
chat:write
andfile:write
OAuth scopes. - Scroll up to the top of the OAuth & Permissions page and click Install App to Workspace.
- Copy the Bot User OAuth Token from the OAuth & Permissions page. This is the value that should be used for the
bot_token
parameter of Slack config. - In Slack, go to your channel and click the down arrow next to your channel name at the top. Click Integrations -> Add apps -> select the app you just made.
Usage
send_alert is the high-level/easiest way to send alerts.
Alerts are composed of one or more messages, where each message is composed of one or more components.
Alerts can be sent to one or more Slack and/or Email destinations. See destinations for configuration.
Examples
from alert_msgs import Email, Slack, ContentType, FontSize, Map, Text, Table, send_alert, send_slack_message, send_email
from uuid import uuid4
import random
components = [
Text(
"Important things have happened.",
size=FontSize.LARGE,
color=ContentType.IMPORTANT,
),
Map({"Field1": "Value1", "Field2": "Value2", "Field3": "Value3"}),
Table(
rows=[
{
"Process": "thing-1",
"Status": 0,
"Finished": True,
},
{
"Process": "thing-2",
"Status": 1,
"Finished": False,
}
],
caption="Process Status",
),
]
send_to = [
Email(sender_addr="me@gmail.com", password="myemailpass", receiver_addr=["someone@gmail.com","someone2@gmail.com"]),
Slack(bot_token="xoxb-34248928439763-6634233945735-KbePKXfstIRv6YN2tW5UF8tS", channel="my-channel")
]
send_alert(components, subject="Test Alert", send_to=send_to)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file alert_msgs-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: alert_msgs-0.6.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 806ff1818c719905e01c21cffb5cfdfa25eeeffbdb3b4b1808d0c053212dabbd |
|
MD5 | 934852007eb18a8f74e426ec5d4893c7 |
|
BLAKE2b-256 | 2c86bde98b03a54597ca8074087878a5f96a5893baf18eac6a109d852dd599f2 |