π©Getting started
Requirements
Python 3.8+
Python requests package (likely to be installed already)
Active Snowflake account (you may use a free trial account for testing)
Active Slack workspace for notifications
1) Install SnowKill
pip install snowkill2) Generate key pair for service account
Generate and securely store private and public keys for a service account: https://docs.snowflake.com/en/user-guide/key-pair-auth#generate-the-private-key
3) Create new administrator user in Snowflake
Replace <public_key> placeholder with contents of public key. Make sure to remove delimiters.
CREATE USER ADMIN_MONITOR
TYPE = SERVICE
RSA_PUBLIC_KEY = 'MIIBIjANBgkqh...'
DEFAULT_ROLE = 'ACCOUNTADMIN';
GRANT ROLE ACCOUNTADMIN TO USER ADMIN_MONITOR;Role ACCOUNTADMIN is currently required in order for SnowKill to have full access to all SQL queries executed on account. Also, it is required to execute global SHOW LOCKS IN ACCOUNT command.
3) Create table and warehouse for SnowKill log storage in Snowflake
We suggest to start with Snowflake storage for demonstration purposes, since it requires the least amount of additional setup.
You will be able to use an alternative storage option for real production environment, e.g. Postgres or Hybrid Table.
4) Create Slack application and obtain auth token
Go to https://api.slack.com/apps and login.
Press "Create New App" button, choose "From an app manifest".
Choose workspace, press "Next".
Choose "YAML" tab. Copy-paste settings below. Press "Next".
Press "Create".
Press "Install to Workspace" button, press "Allow".
Go to "Settings -> Install App" and copy the contents of Bot User OAuth Token field. You will need it to send notifications from Python script.
Here is a video-tutorial which might help you if you're new to Slack Apps: https://www.youtube.com/watch?v=q3SBz_eqOq0
Optionally, you may go to "Settings -> Basic Information", scroll down to "Display Information" section and upload this App Icon:
It will make notification messages look better.
5) Create a channel for notifications in Slack
The suggested channel name is: #snowflake-monitor
How to create a channel: https://slack.com/intl/en-gb/help/articles/201402297-Create-a-channel
6) Create a Python script with the following content
You may choose any script file name. For example: snowflake_monitor.py
7) Set config options using environment variables
Replace example config options with values relevant for your Snowflake and Slack accounts. Execute commands in terminal.
Snowflake credentials:
Snowsight base URL, copy-pasted from browser window. It usually consists of http://app.snowflake.com/, followed by organisation name and account name. But it might be different for old accounts and accounts with Private Link.

Snowflake table name to store logs:
Slack credentials:
8) Start a "bad" query in Snowflake and run python script
Here is a good example of "bad" query, which uses standard SNOWFLAKE_SAMPLE_DATA database, which is always available for newly created accounts.
After ~5 minutes, run python script a few times:
If everything works correctly, you should see a log message about query with cartesian join. You should also receive a notification in Slack channel.
Congratulations!
Now you are ready to learn more about specific conditions, filters, alternative storage and notifications options.
Also, you may now browse other complete examples on GitHub.
Last updated