【问题标题】:create alert policy with Cloud Function and Python - positional arguments error使用 Cloud Function 和 Python 创建警报策略 - 位置参数错误
【发布时间】:2021-08-18 00:25:49
【问题描述】:

我想使用监控 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

我在这里缺少什么?

【问题讨论】:

    标签: python google-cloud-platform google-cloud-functions google-cloud-monitoring


    【解决方案1】:

    您收到此错误是因为 2.0 版 google-cloud-monitoring 中所需参数是位置参数的更改。请参阅google cloud monitoring 2.0 change log 以供参考。为了适应变化,你应该明确定义create_alert_policy()中的参数。

    client.create_alert_policy(name=name, alert_policy=alert_policy)
    

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      相关资源
      最近更新 更多