diff --git a/airflow/providers/datadog/hooks/datadog.py b/airflow/providers/datadog/hooks/datadog.py index 14f2b664d015a..670a81594ec8e 100644 --- a/airflow/providers/datadog/hooks/datadog.py +++ b/airflow/providers/datadog/hooks/datadog.py @@ -39,6 +39,11 @@ class DatadogHook(BaseHook, LoggingMixin): :param datadog_conn_id: The connection to datadog, containing metadata for api keys. """ + conn_name_attr = "datadog_conn_id" + default_conn_name = "datadog_default" + conn_type = "datadog" + hook_name = "Datadog" + def __init__(self, datadog_conn_id: str = "datadog_default") -> None: super().__init__() conn = self.get_connection(datadog_conn_id) @@ -72,7 +77,7 @@ def send_metric( interval: int | None = None, ) -> dict[str, Any]: """ - Sends a single datapoint metric to DataDog + Sends a single datapoint metric to Datadog :param metric_name: The name of the metric :param datapoint: A single integer or float related to the metric @@ -152,3 +157,25 @@ def post_event( self.validate_response(response) return response + + @staticmethod + def get_connection_form_widgets() -> dict[str, Any]: + """Returns connection widgets to add to connection form""" + from flask_appbuilder.fieldwidgets import BS3TextFieldWidget + from flask_babel import lazy_gettext + from wtforms import StringField + + return { + "api_host": StringField(lazy_gettext("API endpoint"), widget=BS3TextFieldWidget()), + "api_key": StringField(lazy_gettext("API key"), widget=BS3TextFieldWidget()), + "app_key": StringField(lazy_gettext("Application key"), widget=BS3TextFieldWidget()), + "source_type_name": StringField(lazy_gettext("Source type name"), widget=BS3TextFieldWidget()), + } + + @staticmethod + def get_ui_field_behaviour() -> dict[str, Any]: + """Returns custom field behaviour""" + return { + "hidden_fields": ["schema", "login", "password", "port", "extra"], + "relabeling": {"host": "Events host name"}, + } diff --git a/airflow/providers/datadog/provider.yaml b/airflow/providers/datadog/provider.yaml index 3bd1734a53aae..f933708d035b6 100644 --- a/airflow/providers/datadog/provider.yaml +++ b/airflow/providers/datadog/provider.yaml @@ -51,3 +51,7 @@ hooks: - integration-name: Datadog python-modules: - airflow.providers.datadog.hooks.datadog + +connection-types: + - hook-class-name: airflow.providers.datadog.hooks.datadog.DatadogHook + connection-type: datadog diff --git a/docs/apache-airflow-providers-datadog/connections/datadog.rst b/docs/apache-airflow-providers-datadog/connections/datadog.rst new file mode 100644 index 0000000000000..dccc1caf68f03 --- /dev/null +++ b/docs/apache-airflow-providers-datadog/connections/datadog.rst @@ -0,0 +1,46 @@ + .. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + .. http://www.apache.org/licenses/LICENSE-2.0 + + .. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +.. _howto/connection:kubernetes: + +Datadog Connection +============================= + +The Datadog Connection type enables integrations with the Datadog API client. + + +Default Connection IDs +---------------------- + +Hooks and sensors related to Datadog use ``datadog_default`` by default. + +Configuring the Connection +-------------------------- +Host + Host name to associate with the sent events. + +Extra + Specify the extra parameters (as a JSON dictionary) that can be used in Datadog + connection. + + ``api_host``: Datadog `API endpoint `__ + + ``api_key``: Datadog `API key `__ + + ``app_key``: Datadog `application key `__ + + ``source_type_name``: Datadog `source type name `__ (defaults to my_apps). diff --git a/docs/apache-airflow-providers-datadog/index.rst b/docs/apache-airflow-providers-datadog/index.rst index 9581b5b587691..72aa448133a1d 100644 --- a/docs/apache-airflow-providers-datadog/index.rst +++ b/docs/apache-airflow-providers-datadog/index.rst @@ -22,6 +22,12 @@ Content ------- +.. toctree:: + :maxdepth: 1 + :caption: Guides + + Connection types + .. toctree:: :maxdepth: 1 :caption: References