jithin97 commented on a change in pull request #7322: [AIRFLOW-6593] Add GCP 
Stackdriver Alerting Hooks and Operators
URL: https://github.com/apache/airflow/pull/7322#discussion_r379713197
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/stackdriver.py
 ##########
 @@ -0,0 +1,743 @@
+#
+# 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.
+
+from google.api_core.gapic_v1.method import DEFAULT
+
+from airflow.models import BaseOperator
+from airflow.providers.google.cloud.hooks.stackdriver import StackdriverHook
+from airflow.utils.decorators import apply_defaults
+
+
+class StackdriverListAlertPoliciesOperator(BaseOperator):
+    """
+    Fetches all the Alert Policies identified by the filter passed as
+    filter_ parameter. The desired return type can be specified by the
+    format_ parameter, the supported formats are "dict", "json" and None
+    which returns python dictionary, stringified JSON and protobuf
+    respectively.
+    :param format_: (Optional) Desired output format of the result. The
+        supported formats are "dict", "json" and None which returns
+        python dictionary, stringified JSON and protobuf respectively.
+    :type format_: str
+    :param filter_:  If provided, this field specifies the criteria that
+        must be met by alert policies to be included in the response.
+        For more details, see `sorting and filtering
+        <https://cloud.google.com/monitoring/api/v3/sorting-and-filtering>`__.
+    :type filter_: str
+    :param order_by: A comma-separated list of fields by which to sort the 
result.
+        Supports the same set of field references as the ``filter`` field. 
Entries
+        can be prefixed with a minus sign to sort by the field in descending 
order.
+        For more details, see `sorting and filtering
+        <https://cloud.google.com/monitoring/api/v3/sorting-and-filtering>`__.
+    :type order_by: str
+    :param page_size: The maximum number of resources contained in the
+        underlying API response. If page streaming is performed per-
+        resource, this parameter does not affect the return value. If page
+        streaming is performed per-page, this determines the maximum number
+        of resources in a page.
+    :type page_size: int
+    :param retry: A retry object used to retry requests. If ``None`` is
+        specified, requests will be retried using a default configuration.
+    :type retry: str
+    :param timeout: The amount of time, in seconds, to wait
+        for the request to complete. Note that if ``retry`` is
+        specified, the timeout applies to each individual attempt.
+    :type timeout: float
+    :param metadata: Additional metadata that is provided to the method.
+    :type metadata: str
+    :param gcp_conn_id: (Optional) The connection ID used to connect to Google
+        Cloud Platform.
+    :type gcp_conn_id: str
+    :param project_id: The project to fetch alerts from.
+    :type project_id: str
+    :param delegate_to: (Optional) The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = ('filter_',)
+    ui_color = "#e5ffcc"
+
+    # pylint: disable=too-many-arguments
+    @apply_defaults
+    def __init__(
+        self,
+        format_=None,
+        filter_=None,
+        order_by=None,
+        page_size=None,
+        retry=DEFAULT,
+        timeout=DEFAULT,
+        metadata=None,
+        gcp_conn_id='google_cloud_default',
+        project_id=None,
+        delegate_to=None,
+        *args, **kwargs
+    ):
+        super().__init__(*args, **kwargs)
+        self.format_ = format_
+        self.filter_ = filter_
+        self.order_by = order_by
+        self.page_size = page_size
+        self.retry = retry
+        self.timeout = timeout
+        self.metadata = metadata
+        self.gcp_conn_id = gcp_conn_id
+        self.project_id = project_id
+        self.delegate_to = delegate_to
+        self.hook = None
+
+    def execute(self, context):
+        if self.hook is None:
+            self.hook = StackdriverHook(gcp_conn_id=self.gcp_conn_id, 
delegate_to=self.delegate_to)
+
+        return self.hook.list_alert_policies(
 
 Review comment:
   please check 
https://github.com/apache/airflow/pull/7322/commits/86898011b3a31e03830d56af567193a6e6d54a2c

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to