Skip to content

mee7ya/airflow-providers-mattermost

Repository files navigation

Apache Airflow Mattermost Provider

GitHub branch check runs Read the Docs (version) PyPI - Version

The package is Apache Airflow provider for integrating with Mattermost using webhooks

Features

  • Hook
  • Operator
  • Notifier

Hook

Provides custom connection type and sends messages via webhook

connection

Operator

To send messages within DAGs, supports templating

from airflow.decorators import dag

from airflow_providers_mattermost.operators import MattermostOperator


@dag(
    dag_id='mattermost_dag'
)
def mattermost():
    send_message_to_mattermost = MattermostOperator(
        task_id='send_message_to_mattermost',
        conn_id='mattermost',
        channel='off-topic',
        message='Hello from {{ dag.dag_id }} in Airflow!',
        username='Airflow',
    )

    send_message_to_mattermost


mattermost()

Notifier

Can be used with on_*_callbacks to notify about Task/DAG status

from airflow.decorators import dag

from airflow_providers_mattermost.notifiers import MattermostNotifier
from airflow_providers_mattermost.operators import MattermostOperator


@dag(
    dag_id='mattermost_dag',
    on_success_callback=MattermostNotifier(
        conn_id='mattermost',
        channel='off-topic',
        message='Dag ID: {{ dag.dag_id }} , Run ID: {{ run_id }} has completed',
        username='Airflow',
    ),
    on_failure_callback=MattermostNotifier(
        conn_id='mattermost',
        channel='off-topic',
        message='Dag ID: {{ dag.dag_id }} , Run ID: {{ run_id }} has failed',
        username='Airflow',
    ),
)
def mattermost():
    send_message_to_mattermost = MattermostOperator(
        task_id='send_message_to_mattermost',
        conn_id='mattermost',
        channel='off-topic',
        message='Hello from {{ dag.dag_id }} in Airflow!',
        username='Airflow',
    )

    send_message_to_mattermost


mattermost()