How nhatode/code works
Project Overview
• This is a Python-based notification system aimed at sending Microsoft Teams alerts when an Apache Airflow DAG fails. It also integrates with ServiceNow to enrich notifications with ticket information.
• The project is modular and configurable – it separates concerns into configuration, models representing data (Airflow failures and ServiceNow tickets), and notifiers (including a Teams notifier and a notification manager).
Main Components
a. Entry Point:
• main.py: The application’s main runner which orchestrates the notification process.
b. Configuration:
• config.py: Holds all the necessary settings (Teams webhook URL, message templates, and notification settings).
c. Data Models:
• airflow_failure.py: Defines how an Airflow DAG failure is represented.
• servicenow_ticket.py: Represents ServiceNow ticket information that may be attached to the failure notification.
d. Notifiers:
• teams_notifier.py: Responsible for sending alerts to Microsoft Teams.
• notification_manager.py: Likely acts as a coordinator that gathers information from the data models, applies the configuration, and then invokes the appropriate notifier.
e. External Dependencies/Services:
• Apache Airflow: The system which triggers the alerts on DAG failures.
• Microsoft Teams: The external service that receives the notifications.
• ServiceNow: Provides ticket details (or a reference) associated with each failure event.
Determining Relationships and Interactions
• The main.py acts as the orchestrator, loading the configuration and initializing the notification flow.
• When a DAG fails in Airflow, the failure event is captured and represented using the airflow_failure model.
• If available, additional context via ServiceNow ticket information is fetched and wrapped with the servicenow_ticket model.
• The notification_manager collects this data, applies the message template from the config, and forwards the information to the teams_notifier.
• The teams_notifier then formats and sends the alert through the configured Teams webhook.
Architectural Patterns and Design Principles
• Modular and Object-Oriented Design: The clear separation between models, configuration, and notifier modules shows that the system is designed to be extensible.
• Separation of Concerns: Each module handles a distinct part of the workflow (configuration reading, data modeling, notification logic).
• Configurability: The use of a centralized configuration file (config.py) that can be adjusted without modifying the core logic.