27
27
28
28
# [START monitoring_alert_list_policies]
29
29
def 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
+
30
37
client = monitoring_v3 .AlertPolicyServiceClient ()
31
38
policies = client .list_alert_policies (name = project_name )
32
39
print (
@@ -44,6 +51,13 @@ def list_alert_policies(project_name):
44
51
45
52
# [START monitoring_alert_list_channels]
46
53
def 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
+
47
61
client = monitoring_v3 .NotificationChannelServiceClient ()
48
62
channels = client .list_notification_channels (name = project_name )
49
63
print (
@@ -62,7 +76,8 @@ def enable_alert_policies(project_name, enable, filter_=None):
62
76
"""Enable or disable alert policies in a project.
63
77
64
78
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>'.
66
81
enable (bool): Enable or disable the policies.
67
82
filter_ (str, optional): Only enable/disable alert policies that match
68
83
this filter_. See
@@ -95,6 +110,17 @@ def enable_alert_policies(project_name, enable, filter_=None):
95
110
96
111
# [START monitoring_alert_replace_channels]
97
112
def 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
+
98
124
_ , project_id = project_name .split ("/" )
99
125
alert_client = monitoring_v3 .AlertPolicyServiceClient ()
100
126
channel_client = monitoring_v3 .NotificationChannelServiceClient ()
@@ -119,6 +145,17 @@ def replace_notification_channels(project_name, alert_policy_id, channel_ids):
119
145
120
146
# [START monitoring_alert_delete_channel]
121
147
def 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
+
122
159
channel_client = monitoring_v3 .NotificationChannelServiceClient ()
123
160
for channel_id in channel_ids :
124
161
channel_name = "{}/notificationChannels/{}" .format (project_name , channel_id )
@@ -136,6 +173,15 @@ def delete_notification_channels(project_name, channel_ids, force=None):
136
173
137
174
# [START monitoring_alert_backup_policies]
138
175
def 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
+
139
185
alert_client = monitoring_v3 .AlertPolicyServiceClient ()
140
186
channel_client = monitoring_v3 .NotificationChannelServiceClient ()
141
187
record = {
0 commit comments