【问题标题】:Datasource Authentication via Routes for Grafana Datasource Plugin通过 Grafana 数据源插件的路由进行数据源身份验证
【发布时间】:2018-12-04 17:50:51
【问题描述】:

我正在尝试为 Grafana 编写一个自定义数据源插件,该插件将请求 Azure AD 身份验证令牌并将它们与查询一起发送到我的数据库,该数据库将接受令牌并返回对查询的响应。

我注意到,用于 Grafana 的 Azure Monitor 插件通过要求用户输入其客户端 ID、客户端密码和租户 ID 并通过其plugin.json 文件的路由部分使用它来执行相同的操作。{} p>

我已经按照这个方法但是我得到一个错误:

502 网关错误。

我的文件托管在here

进行 HTTP 调用的 datasource.js 的基本部分是

query(options) {

    const csl = document.getElementById("csl").value;
    var queries = _.filter(options.targets, item => {
        return item.hide !== true;
      }).map(item => {
        return {
          refId: item.refId,
          intervalMs: options.intervalMs,
          maxDataPoints: options.maxDataPoints,
          format: item.format,
        };
      });
    if (queries.length <= 0) {
      return this.$q.when({data: []});
    }
    return this.backendSrv.datasourceRequest({
        url: `api/datasources/proxy/${this.id}/kusto/query`,
        method: 'POST',
        headers: this.headers,
        data: {
            db: this.database,
            csl: csl,
            from: options.range.from,
            to: options.range.to,
            queries: queries,
        }
    });
}

其中 kusto 是我的 plugin.json 中定义的路由路径。

是什么导致了这个错误?我的 datasource.js 或 plugin.json 有错误吗?错误发生在客户端还是服务器端?

【问题讨论】:

    标签: javascript grafana grafana-api


    【解决方案1】:

    第一件事是现在有一个Kusto (now renamed to Azure Data Explorer) Datasource for Grafana。所以不确定你是否需要你的插件了。

    您的错误原因是您在 plugin.json 文件中的路由与您正在进行的调用不匹配。您正在使 ping request 是 HTTP GET 但路由匹配 POST 请求。

    Grafana 中的错误处理在这里肯定会更好 - 在日志中,您会看到一条错误消息:

    http: proxy error: unsupported protocol scheme ""

    由于在插件路由中找不到匹配项,URL 字段被设置为空字符串。然后,当 Grafana 中的数据源代理尝试创建要发送到 Azure 的 url 时,由于没有指定协议(http 或 https)而失败。

    插件路由和身份验证文档:http://docs.grafana.org/plugins/developing/auth-for-datasources/

    【讨论】:

    • 我在问这个问题几天后就知道了。实际上,我们当时在 Grafana 社区网站上进行了交流。
    猜你喜欢
    • 2021-07-30
    • 2015-08-09
    • 2021-11-12
    • 2016-09-14
    • 1970-01-01
    • 2018-11-06
    • 2014-02-04
    • 1970-01-01
    • 2018-04-01
    相关资源
    最近更新 更多