The package is Apache Airflow provider for integrating with Mattermost using webhooks
- Hook
- Operator
- Notifier
Provides custom connection type and sends messages via webhook
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()
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()