You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/02/15 03:04:05 UTC

[GitHub] [airflow] jithin97 commented on a change in pull request #7322: [AIRFLOW-6593] Add GCP Stackdriver Alerting Hooks and Operators

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_r379713189
 
 

 ##########
 File path: airflow/providers/google/cloud/hooks/stackdriver.py
 ##########
 @@ -0,0 +1,653 @@
+#
+# 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.
+
+"""
+This module contains GCP Stackdriver operators.
+"""
+
+import json
+
+from google.api_core.exceptions import InvalidArgument
+from google.api_core.gapic_v1.method import DEFAULT
+from google.cloud import monitoring_v3
+from google.protobuf.json_format import MessageToDict, MessageToJson, Parse
+from googleapiclient.errors import HttpError
+
+from airflow import AirflowException
+from airflow.providers.google.cloud.hooks.base import CloudBaseHook
+
+
+class StackdriverHook(CloudBaseHook):
+    """
+    Stackdriver Hook for connecting with GCP Stackdriver
+    """
+
+    def __init__(self, gcp_conn_id='google_cloud_default', delegate_to=None):
+        super().__init__(gcp_conn_id, delegate_to)
+        self._policy_client = None
+        self._channel_client = None
+
+    def _get_policy_client(self):
+        if not self._policy_client:
+            self._policy_client = monitoring_v3.AlertPolicyServiceClient()
+        return self._policy_client
+
+    def _get_channel_client(self):
+        if not self._channel_client:
+            self._channel_client = monitoring_v3.NotificationChannelServiceClient()
+        return self._channel_client
+
+    @CloudBaseHook.fallback_to_default_project_id
+    def list_alert_policies(
+        self,
+        project_id=None,
+        format_=None,
+        filter_=None,
+        order_by=None,
+        page_size=None,
+        retry=DEFAULT,
+        timeout=DEFAULT,
+        metadata=None
 
 Review comment:
   how about 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:
users@infra.apache.org


With regards,
Apache Git Services