2727
2828# [START monitoring_alert_list_policies]
2929def list_alert_policies (project_name ):
30+ """List alert policies in a project.
31+
32+ Arguments:
33+ project_name (str): The Google Cloud Project to use. The project name
34+ must be in the format - 'projects/<PROJECT_NAME>'.
35+ """
36+
3037 client = monitoring_v3 .AlertPolicyServiceClient ()
3138 policies = client .list_alert_policies (name = project_name )
3239 print (
@@ -44,6 +51,13 @@ def list_alert_policies(project_name):
4451
4552# [START monitoring_alert_list_channels]
4653def list_notification_channels (project_name ):
54+ """List alert notification channels in a project.
55+
56+ Arguments:
57+ project_name (str): The Google Cloud Project to use. The project name
58+ must be in the format - 'projects/<PROJECT_NAME>'.
59+ """
60+
4761 client = monitoring_v3 .NotificationChannelServiceClient ()
4862 channels = client .list_notification_channels (name = project_name )
4963 print (
@@ -62,7 +76,8 @@ def enable_alert_policies(project_name, enable, filter_=None):
6276 """Enable or disable alert policies in a project.
6377
6478 Arguments:
65- project_name (str)
79+ project_name (str): The Google Cloud Project to use. The project name
80+ must be in the format - 'projects/<PROJECT_NAME>'.
6681 enable (bool): Enable or disable the policies.
6782 filter_ (str, optional): Only enable/disable alert policies that match
6883 this filter_. See
@@ -95,6 +110,17 @@ def enable_alert_policies(project_name, enable, filter_=None):
95110
96111# [START monitoring_alert_replace_channels]
97112def replace_notification_channels (project_name , alert_policy_id , channel_ids ):
113+ """Replace notification channel of an alert.
114+
115+ Arguments:
116+ project_name (str): The Google Cloud Project to use. The project name
117+ must be in the format - 'projects/<PROJECT_NAME>'.
118+ alert_policy_id (str): The ID of the alert policy whose notification
119+ channels are to be replaced.
120+ channel_ids (str): ID of notification channel to be added as channel
121+ for the given alert policy.
122+ """
123+
98124 _ , project_id = project_name .split ("/" )
99125 alert_client = monitoring_v3 .AlertPolicyServiceClient ()
100126 channel_client = monitoring_v3 .NotificationChannelServiceClient ()
@@ -119,6 +145,17 @@ def replace_notification_channels(project_name, alert_policy_id, channel_ids):
119145
120146# [START monitoring_alert_delete_channel]
121147def delete_notification_channels (project_name , channel_ids , force = None ):
148+ """Delete alert notification channels.
149+
150+ Arguments:
151+ project_name (str): The Google Cloud Project to use. The project name
152+ must be in the format - 'projects/<PROJECT_NAME>'.
153+ channel_ids list(str): List of IDs of notification channels to delete.
154+ force (bool): If true, the notification channels are deleted regardless
155+ of its in use by alert policies. If false, channels that are still
156+ referenced by an existing alerting policy will fail to be deleted.
157+ """
158+
122159 channel_client = monitoring_v3 .NotificationChannelServiceClient ()
123160 for channel_id in channel_ids :
124161 channel_name = "{}/notificationChannels/{}" .format (project_name , channel_id )
@@ -136,6 +173,15 @@ def delete_notification_channels(project_name, channel_ids, force=None):
136173
137174# [START monitoring_alert_backup_policies]
138175def backup (project_name , backup_filename ):
176+ """Backup alert policies from a project to a local file.
177+
178+ Arguments:
179+ project_name (str): The Google Cloud Project to use. The project name
180+ must be in the format - 'projects/<PROJECT_NAME>'
181+ backup_filename (str): Name of the file (along with its path) to which
182+ the alert policies will be written as backup.
183+ """
184+
139185 alert_client = monitoring_v3 .AlertPolicyServiceClient ()
140186 channel_client = monitoring_v3 .NotificationChannelServiceClient ()
141187 record = {
0 commit comments