使用 Cloud Function 和 Python 创建警报策略 - 位置参数错误
create alert policy with Cloud Function and Python - positional arguments error
我想使用监视 v3 API 创建新的警报策略。我正在关注这个 documentation
我有这个云功能:
from google.cloud import monitoring_v3
import json
client = monitoring_v3.AlertPolicyServiceClient()
alert_policy = {
"displayName": "This is a test",
"combiner": "OR",
"conditions": [
{
"displayName": "This is a test",
"conditionAbsent": {
"duration": "3900s",
filter: "resource.type = \"l7_lb_rule\" AND metric.type = \"logging.googleapis.com/user/metric_name_here\""
}
}
],
}
name = 'projects/my-project'
client.create_alert_policy(name, alert_policy)
当运行测试函数时我有日志错误TypeError: create_alert_policy() takes from 1 to 2 positional arguments but 3 were given
我在这里缺少什么?
您收到此错误是因为在 google-cloud-monitoring 的 2.0 版本中进行了更改,其中必需的参数是位置参数。请参阅 google cloud monitoring 2.0 change log 以供参考。为了适应变化,你应该明确地定义create_alert_policy()
中的参数。
client.create_alert_policy(name=name, alert_policy=alert_policy)
我想使用监视 v3 API 创建新的警报策略。我正在关注这个 documentation
我有这个云功能:
from google.cloud import monitoring_v3
import json
client = monitoring_v3.AlertPolicyServiceClient()
alert_policy = {
"displayName": "This is a test",
"combiner": "OR",
"conditions": [
{
"displayName": "This is a test",
"conditionAbsent": {
"duration": "3900s",
filter: "resource.type = \"l7_lb_rule\" AND metric.type = \"logging.googleapis.com/user/metric_name_here\""
}
}
],
}
name = 'projects/my-project'
client.create_alert_policy(name, alert_policy)
当运行测试函数时我有日志错误TypeError: create_alert_policy() takes from 1 to 2 positional arguments but 3 were given
我在这里缺少什么?
您收到此错误是因为在 google-cloud-monitoring 的 2.0 版本中进行了更改,其中必需的参数是位置参数。请参阅 google cloud monitoring 2.0 change log 以供参考。为了适应变化,你应该明确地定义create_alert_policy()
中的参数。
client.create_alert_policy(name=name, alert_policy=alert_policy)