class_docstr: Stackdriver Hook for connecting with Google Cloud Stackdriver.
docstr: Create a new notification or updates an existing notification channel.
  
  Channel is identified by the name field in the alerts parameter.
  
  :param channels: A JSON string or file that specifies all the alerts that needs
      to be either created or updated. For more details, see
      https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.notificationChannels.
      (templated)
  :param project_id: The project in which notification channels needs to be created/updated.
  :param retry: A retry object used to retry requests. If ``None`` is
      specified, requests will be retried using a default configuration.
  :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.
  :param metadata: Additional metadata that is provided to the method.
docstr_tok: ["Create","a","new","notification","or","updates","an","existing","notification","channel",".","Channel","is","identified","by","the","name","field","in","the","alerts","parameter",".",":","param","channels",":","A","JSON","string","or","file","that","specifies","all","the","alerts","that","needs","to","be","either","created","or","updated",".","For","more","details",",","see","https",":","\/\/cloud.google.com\/monitoring\/api\/ref_v3\/rest\/v3\/projects.notificationChannels",".","(","templated",")",":","param","project_id",":","The","project","in","which","notification","channels","needs","to","be","created\/updated",".",":","param","retry",":","A","retry","object","used","to","retry","requests",".","If","``","None","``","is","specified",",","requests","will","be","retried","using","a","default","configuration",".",":","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",".",":","param","metadata",":","Additional","metadata","that","is","provided","to","the","method","."]
code: def upsert_channel(
      self,
      channels: str,
      project_id: str,
      retry: Retry | _MethodDefault = DEFAULT,
      timeout: float | None = None,
      metadata: Sequence[tuple[str, str]] = (),
  ) -> dict:
      """
      Create a new notification or updates an existing notification channel.
  
      Channel is identified by the name field in the alerts parameter.
  
      :param channels: A JSON string or file that specifies all the alerts that needs
          to be either created or updated. For more details, see
          https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.notificationChannels.
          (templated)
      :param project_id: The project in which notification channels needs to be created/updated.
      :param retry: A retry object used to retry requests. If ``None`` is
          specified, requests will be retried using a default configuration.
      :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.
      :param metadata: Additional metadata that is provided to the method.
      """
      channel_client = self._get_channel_client()
  
      record = json.loads(channels)
      existing_channels = [
          channel["name"]
          for channel in self.list_notification_channels(
              project_id=project_id, format_="dict"
          )
      ]
      channels_list = []
      channel_name_map = {}
  
      for channel in record["channels"]:
          channels_list.append(NotificationChannel(**channel))
  
      for channel in channels_list:
          channel.verification_status = (
              monitoring_v3.NotificationChannel.VerificationStatus.VERIFICATION_STATUS_UNSPECIFIED
          )
  
          if channel.name in existing_channels:
              channel_client.update_notification_channel(
                  request={"notification_channel": channel},
                  retry=retry,
                  timeout=timeout,
                  metadata=metadata,
              )
          else:
              old_name = channel.name
              channel.name = None
              new_channel = channel_client.create_notification_channel(
                  request={
                      "name": f"projects/{project_id}",
                      "notification_channel": channel,
                  },
                  retry=retry,
                  timeout=timeout,
                  metadata=metadata,
              )
              channel_name_map[old_name] = new_channel.name
  
      return channel_name_map
  
imports: from __future__ import annotations
  import contextlib
  import json
  from typing import TYPE_CHECKING, Any, Sequence
  from google.api_core.exceptions import InvalidArgument
  from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
  from google.cloud import monitoring_v3
  from google.cloud.monitoring_v3 import AlertPolicy, NotificationChannel
  from google.protobuf.field_mask_pb2 import FieldMask
  from googleapiclient.errors import HttpError
  from airflow.exceptions import AirflowException
  from airflow.providers.google.common.hooks.base_google import PROVIDE_PROJECT_ID, GoogleBaseHook
label_desc: Use image node_id 14 for calling the StackdriverHook obj's underlying member method code with example usage: obj.upsert_channel(channels, project_id, retry, timeout, metadata) and returns: channel_name_map