update_alert_policy() 意外参数

update_alert_policy() unexpected argument

我正在构建一个云功能来根据外部更新警报策略table我用作参考。

我已经有一个云功能来创建警报策略:

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)

我最初的计划是重用这段代码并用 update_alert_policy 方法替换 create_alert_policy 方法。我有这样的东西:

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)

我有以下错误:update_alert_policy() got an unexpected keyword argument 'name';我在这里缺少什么?

update_alert_policy 应该这样传递:

client_alert.update_alert_policy(alert_policy=policy) 名称应直接在 json 对象中传递。