使用 Datadog API 执行 Python 脚本时缺少 SNI 警告

使用 Datadog API 执行 Python 脚本时缺少 SNI 警告

我是新手,完全被这个问题难住了。我尝试了很多不同的解决方案,但还没能找到一个有效的,你能帮我吗?:)

我在 VirtualBox 上使用 Vagrant 创建了一个 Ubuntu 12.04 VM,并在其上安装了 Datadog 代理。然后,我创建了一个 Datadog API 脚本来创建带有不同图表的时间板。我尝试执行 python 脚本,但每次都会收到警告,并且没有结果。正如您在此处看到的:https://docs.datadoghq.com/api/?lang=python#create-a-timeboard 我应该能够在我的 Datadog 仪表板中看到时间板,但它没有出现。

这是我在 /home/datadog 中创建的脚本:

#!/usr/bin/env python

from datadog import initialize, api

options = {
    'api_key': 'MYAPIKEY',
    'app_key': 'MYAPPKEY'
}

initialize(**options)

title = "Visualizing Data for Barbosa"
description = "Timeboard using Datadog's API"
graphs = [

{
    "definition": {
        "events": [],
        "requests": [
            {"q": "my_metric{host:precise64}"}
        ],
        "viz": "timeseries"
    },
    "title": "My metric scoped over my host"
},

{
    "definition": {
        "events": [],
        "requests": [
            {"q": "anomalies(avg:mysql.performance.cpu_time{host:precise64}, 'robust', 2)"}
        ],
        "viz": "timeseries"
    },
    "title": "Anomalies on MySQL for CPU time"

},

{
    "definition": {
        "events": [],
        "requests": [
            {"q": "avg:ùy_metric{host:precise64}.rollup(sum, 3600)"}
    ],
        "viz": "timeseries"
    },
    "title": "Rollup for My metric over the past hour"

}]

read_only = True
api.Timeboard.create(title=title,
                     description=description,
                     graphs=graphs,
                     read_only=read_only)

当我使用执行脚本时,/home/datadog$ ./timeboard.py我得到以下信息:

/usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:339: 
SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name 
Indication) extension to TLS is not available on this platform. This may 
cause the server to present an incorrect TLS certificate, which can cause 
validation failures. You can upgrade to a newer version of Python to solve 
this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-
usage.html#ssl-warnings.
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:137: 
InsecurePlatformWarning: A true SSLContext object is not available. This 
prevents urllib3 from configuring SSL appropriately and may cause certain 
SSL connections to fail. You can upgrade to a newer version of Python to 
solve this. For more information, see 
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings.
InsecurePlatformWarning

我尝试升级 Python,但是当使用 Python 3 执行代码时,它不再识别 Datadog Python 包(https://github.com/DataDog/datadogpy) 我不知道如何将其从 Python 2.7 移出,或者删除 Python 2.7 是否会导致我的代码/脚本出现严重问题。我是个初学者,如果这让您感到困惑,请见谅!

我也尝试过https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings但不幸的是,导入命令也不起作用,是否有特定的软件/包需要安装才能使其工作?

我做错了什么?谢谢!

答案1

答案是通过直接在 python 脚本中添加 import... 来删除警告,如stackoverflow.com 上的这个答案

相关内容