airflow.providers.slack.transfers.sql_to_slack_webhook
¶
Module Contents¶
Classes¶
Executes an SQL statement in a given SQL connection and sends the results to Slack Incoming Webhook. |
- class airflow.providers.slack.transfers.sql_to_slack_webhook.SqlToSlackWebhookOperator(*, sql, sql_conn_id, slack_webhook_conn_id=None, sql_hook_params=None, slack_channel=None, slack_message, results_df_name='results_df', parameters=None, slack_conn_id=NOTSET, **kwargs)[source]¶
Bases:
airflow.providers.slack.transfers.base_sql_to_slack.BaseSqlToSlackOperator
Executes an SQL statement in a given SQL connection and sends the results to Slack Incoming Webhook.
The results of the query are rendered into the ‘slack_message’ parameter as a Pandas dataframe using a JINJA variable called ‘{{ results_df }}’. The ‘results_df’ variable name can be changed by specifying a different ‘results_df_name’ parameter. The Tabulate library is added to the JINJA environment as a filter to allow the dataframe to be rendered nicely. For example, set ‘slack_message’ to {{ results_df | tabulate(tablefmt=”pretty”, headers=”keys”) }} to send the results to Slack as an ascii rendered table.
See also
For more information on how to use this operator, take a look at the guide: SqlToSlackWebhookOperator
Note
You cannot override the default channel (chosen by the user who installed your app), Instead, these values will always inherit from the associated Slack App configuration (link). It is possible to change this values only in Legacy Slack Integration Incoming Webhook.
Warning
This hook intend to use Slack Incoming Webhook connection and might not work correctly with Slack API connection.
- Parameters
sql (str) – The SQL query to be executed (templated)
slack_message (str) – The templated Slack message to send with the data returned from the SQL connection. You can use the default JINJA variable {{ results_df }} to access the pandas dataframe containing the SQL results
sql_conn_id (str) – reference to a specific database.
sql_hook_params (dict | None) – Extra config params to be passed to the underlying hook. Should match the desired hook constructor params.
slack_webhook_conn_id (str | None) – Slack Incoming Webhook connection id that has Incoming Webhook token in the password field.
slack_channel (str | None) – The channel to send message.
results_df_name (str) – The name of the JINJA template’s dataframe variable, default is ‘results_df’
parameters (list | tuple | Mapping[str, Any] | None) – The parameters to pass to the SQL query