0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AirflowからSlackWehookを使ってSlack投稿する

Posted at

背景

シンプルにAirflowのDAGでSlack投稿したい

方法

SlackWebhookOperatorを使って実装


import airflow
from datetime import timedelta
from airflow import DAG
from airflow.contrib.operators.slack_webhook_operator import SlackWebhookOperator

default_args = {
    "owner": "airflow",
    "start_date": airflow.utils.dates.days_ago(1),
    "retries": 3,
    "retry_delay": timedelta(minutes=5)
}

dag = DAG("slack_dag", default_args=default_args, catchup=False, schedule_interval="@daily")

slack = SlackWebhookOperator(
    task_id='slack_test',
    webhook_token="https://hooks.slack.com/services/xxxxxx",
    channel="your_channel",
    message="message",
    icon_url="https://some-image/xxx",
    attachments= [{
        "title": "title",
        "text": "text",
        "color": "good"
        }],
    username="airflow_slack",
    dag=dag
)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?