update_alert_policy() unexpected argument

Viewed 121

I'm building a cloud functions to update alert policies based on an external table I use as a reference.

I already have a cloud functions to create alert policies:

name = 'projects/my_project'
filter = "some_filters"
alert_policy = {"conditions":[{"conditionAbsent":{"duration": "1800s","filter": '{}'.format(filter)}, "displayName":"test_name"}], "displayName":"test_name", "combiner":"OR"}
policy = monitoring_v3.AlertPolicy.from_json(json.dumps(alert_policy))
client_alert.create_alert_policy(name=name, alert_policy=policy)

My initial plan was to reuse this code and replacing the create_alert_policy method by the update_alert_policy method. I have something like this:

name = 'projects/my_project/alertPolicies/1234555665'
filter = "some_filters"
alert_policy = {"conditions":[{"conditionAbsent":{"duration": "1800s","filter": '{}'.format(filter)}, "displayName":"test_name"}], "displayName":"test_name", "combiner":"OR"}
policy = monitoring_v3.AlertPolicy.from_json(json.dumps(alert_policy))
client_alert.update_alert_policy(name=name, alert_policy=policy)

I have the following error: update_alert_policy() got an unexpected keyword argument 'name'; what do I'm missing here?

1 Answers

update_alert_policy should be passed like this:

client_alert.update_alert_policy(alert_policy=policy) and the name should be passed directly in the json object.

Related