Giter Club home page Giter Club logo

Comments (12)

dellnoantechnp avatar dellnoantechnp commented on May 28, 2024 2

@dellnoantechnp 是最新的分支代码吗?

用新版本容器镜像 feiyu563/prometheus-alert:master 测试通过。🎉🎉

这个版本完全可以打一个 v4.9.1 的镜像 tag,如果按照 Github 上 Release 的4.9版本去 dockerhub 找容器,不管tag 是 v4.9 还是 latest 都是有问题的版本,容易造成误导。


....
            [ag-demo]
            wxurl=wxurl1,wxurl2
            ddurl=ddurl1,ddurl1,
            fsurl=fsurl1
            email=email1,
            phone=phone1,phone2
            groupid=groupid1
        
            [ag-alert]
            ddurl=ddurl
.....

ps: 如果使用 alertgroup 告警组方式进行接口调用,配置文件如上,那么在接口调用这里应该使用 ag-alert 中的 alert 名称。
例如 curl -v 'http://xxxx:8080/prometheusalert?type=dd&tpl=prometheus-dd&alertgroup=alert'

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

仅自定义模板有问题,默认模板正常。

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

我测试了一下,自定义模板传过来的 ddurl 上没有 secret 参数,所以程序判断为空了。

看下自定义钉钉模板传过来的 secret 参数为什么消失了?

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

原因是这里: https://github.com/feiyu563/PrometheusAlert/blob/a1d5d6ac17d9bdb4b0b5a3f117104f703d0baedf/controllers/prometheusalert.go#L126C3-L126C3

image

ddurl=xxx&secret=xxx 在 beego 的 input.Get() 是两个参数了,所以并不能取到 &secret=xxx 的值。

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

临时解决方法有,这两个方法对传递多个钉钉地址、有加签和不加签名都不会有影响。

1,使用告警组来配置地址,在参数上使用 alertgroup=告警组 这种方式
2,或者,将 & 符号替换为 %26 编码,如 ddurl=xxx%26secret=xxx 让程序判断它们是一起的来处理它。

# 1 使用方法
http://xxx:8080/prometheusalert?type=dd&tpl=prometheus-dd&alertgroup=告警组&at=xxx

# 2 使用方法
http://xxx:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=xxx%26secret=xxx

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

所以在自定义模板的参数中,需要对 ddurl 和 secret 分别取值,然后组装成一个字符串,再将值给 ddurl。

ddurl := beego.Input().Get("ddurl")
secret := beego.Input().Get("secret")
if len(secret) != 0 {
    ddurl = ddurl + "&secret=" secret
}

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

但是这样又有一个问题,在自定义模板 URL 参数的 ddurl 里面有多个地址,有的加签,有的不加签名。上面的处理又会有问题。

上面的示例只适合单个地址,处理多个地址还是有问题,因此暂时不提修改代码,仅更新文档。

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

建议先使用上面的临时方法。

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

@feiyu563 看作者有啥好的想法没有。

from prometheusalert.

MagicStarTrace avatar MagicStarTrace commented on May 28, 2024

临时解决方法有,这两个方法对传递多个钉钉地址、有加签和不加签名都不会有影响。

1,使用告警组来配置地址,在参数上使用 alertgroup=告警组 这种方式 2,或者,将 & 符号替换为 %26 编码,如 ddurl=xxx%26secret=xxx 让程序判断它们是一起的来处理它。

# 1 使用方法
http://xxx:8080/prometheusalert?type=dd&tpl=prometheus-dd&alertgroup=告警组&at=xxx

# 2 使用方法
http://xxx:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=xxx%26secret=xxx

webhook_configs“:

目前这样可以了,不过这操作有点* 太鬼畜了

同时,谢谢你!

from prometheusalert.

dellnoantechnp avatar dellnoantechnp commented on May 28, 2024

在 url 中指定 alertgroup 发送不成功:

curl -v 'http://10.103.41.159:8080/prometheusalert?type=dd&tpl=prometheus-dd&alertgroup=ag-alert' -H 'Content-type: application/json' -X POST -d '{"receiver":"sms","status":"firing","alerts":[{"status":"firing","labels":{"alertname":"ProbeFailure","instance":"https://server.example.org","job":"http_checks","monitor":"master","severity":"critical"},"annotations":{"description":"Instance https://server.example.org has been down for over 5m. Job: http_checks","summary":"BlackBox Probe Failure: https://server.example.org"},"startsAt":"2023-02-06T13:08:45.828Z","endsAt":"0001-01-01T00:00:00Z","generatorURL":"http://prometheus.example.org:9090/graph?g0.expr=probe_success+%3D%3D+0\\u0026g0.tab=1ArgoCD","fingerprint":"1a30ba71cca2921f"}],"groupLabels":{"alertname":"ProbeFailure"},"commonLabels":{"alertname":"ProbeFailure","instance":"https://server.example.org","job":"http_checks","monitor":"master","severity":"critical"},"commonAnnotations":{"description":"Instance https://server.example.org has been down for over 5m. Job: http_checks","summary":"BlackBox Probe Failure: https://server.example.org"},"externalURL":"http://prometheus.example.org:9093","version":"4","groupKey":"{}/{severity=\"critical\"}:{alertname=\"ProbeFailure\"}","truncatedAlerts":0}'

返回:

{\"errcode\":310000,\"errmsg\":\"description:机器人发送签名不匹配;solution:请确认签名和生成签名的时间戳必须都放在调用的网址中,请确认机器人的密钥加密和填写正确

使用第二种方式,替换 &%26 字符:

curl -v 'http://10.103.41.159:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token=9e67xxxxxx%26secret=SECxxxxxxxxx' -H 'Content-type: application/json' -X POST -d '{"receiver":"sms","status":"firing","alerts":[{"status":"firing","labels":{"alertname":"ProbeFailure","instance":"https://server.example.org","job":"http_checks","monitor":"master","severity":"critical"},"annotations":{"description":"Instance https://server.example.org has been down for over 5m. Job: http_checks","summary":"BlackBox Probe Failure: https://server.example.org"},"startsAt":"2024-02-22T13:48:45.828Z","endsAt":"0001-01-01T00:00:00Z","generatorURL":"http://prometheus.example.org:9090/graph?g0.expr=probe_success+%3D%3D+0\\u0026g0.tab=1ArgoCD","fingerprint":"1a30ba71cca2921f"}],"groupLabels":{"alertname":"ProbeFailure"},"commonLabels":{"alertname":"ProbeFailure","instance":"https://server.example.org","job":"http_checks","monitor":"master","severity":"critical"},"commonAnnotations":{"description":"Instance https://server.example.org has been down for over 5m. Job: http_checks","summary":"BlackBox Probe Failure: https://server.example.org"},"externalURL":"http://prometheus.example.org:9093","version":"4","groupKey":"{}/{severity=\"critical\"}:{alertname=\"ProbeFailure\"}","truncatedAlerts":0}'

返回:

{\"errcode\":310000,\"errmsg\":\"description:机器人发送签名不匹配;solution:请确认签名和生成签名的时间戳必须都放在调用的网址中,请确认机器人的密钥加密和填写正确;link:请参考本接口对应文档获得具体要求 .....

from prometheusalert.

Zhang21 avatar Zhang21 commented on May 28, 2024

@dellnoantechnp 是最新的分支代码吗?

from prometheusalert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.