Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问接口的webhook提取,构建规则是所有平台通用的吗? #124

Open
4 tasks
rebron1900 opened this issue Dec 18, 2023 · 4 comments
Open
4 tasks
Labels
bug Something isn't working

Comments

@rebron1900
Copy link

例行检查

  • 我已确认目前没有类似 issue
  • 我已确认我已升级到最新版本
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述
经过我的测试,目前在构建规则中只有 contentdescription 两个字段可以识别,其他的都不行,即便能成功提交也接收不到数据,请问这个有具体规范吗?

artalk样本数据:

{
  "notify_subject": "",
  "notify_body": "@测试用户:\n\n测试内容\n\nhttps://127.0.0.1/index.html?atk_comment=1057",
  "comment": {
    "id": 1057,
    "content": "测试内容",
    "user_id": 226,
    "nick": "测试用户",
    "email_encrypted": "654236c1e78i4c09a17c4869c9d43910",
    "link": "https://qwqaq.com",
    "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36",
    "date": "2022-05-23 17:00:23",
    "is_collapsed": false,
    "is_pending": false,
    "is_pinned": false,
    "is_allow_reply": false,
    "rid": 0,
    "badge_name": "",
    "badge_color": "",
    "visible": true,
    "vote_up": 0,
    "vote_down": 0,
    "page_key": "/index.html",
    "page_url": "https://127.0.0.1/index.html",
    "site_name": "ArtalkDocs"
  },
  "parent_comment": null
}

我的提取规则

{
  "site_name":"comment.site_name",
  "content": "comment.content",
  "nick": "comment.nick",
  "url": "comment.page_url",
  "notify_body": "notify_subject"
}

构建规则

{
  "content": "### 【$site_name】\n\n评论人:$nick\n\n评论:$content\n\n原文链接:[$url]($url)"
}

复现步骤

预期结果

相关截图
如果没有的话,请删除此节。

@rebron1900 rebron1900 added the bug Something isn't working label Dec 18, 2023
@songquanpeng
Copy link
Owner

得看一下实现了,时间太久我有点忘记了

@rebron1900
Copy link
Author

得看一下实现了,时间太久我有点忘记了

期待答复😁

@AiTian1211
Copy link

样本数据:
{
"receiver": "webhook",
"status": "firing",
"alerts": [
{
"status": "firing",
"labels": {
"alertname": "ServicePortUnavailable",
"group": "elasticsearch",
"instance": "192.168.10.55:9200",
"job": "blackbox_exporter_tcp",
"severity": "warning",
"team": "elk"
},
"annotations": {
"description": "elasticsearch 192.168.10.55:9200 service port is unavailable",
"summary": "service port unavailable",
"value": "192.168.10.55:9200"
},
"startsAt": "2023-07-08T09:16:01.979669601Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "/graph?g0.expr=probe_success%7Binstance%3D~%22%28%5C%5Cd%2B.%29%7B4%7D%5C%5Cd%2B%22%7D+%3D%3D+0&g0.tab=1",
"fingerprint": "1e43318d4e7834f1"
}
],
"groupLabels": {
"alertname": "ServicePortUnavailable"
},
"commonLabels": {
"alertname": "ServicePortUnavailable",
"group": "elasticsearch",
"instance": "192.168.10.55:9200",
"job": "blackbox_exporter_tcp",
"severity": "warning",
"team": "elk"
},
"commonAnnotations": {
"description": "elasticsearch 192.168.10.55:9200 service port is unavailable",
"summary": "service port unavailable",
"value": "192.168.10.55:9200"
},
"truncatedAlerts": 0
}

提取规则:
{
"title": "${alerts[0].labels.alertname}",
"description": "${alerts[0].annotations.summary}",
"content": {
"告警等级": "${alerts[0].labels.severity}",
"告警类型": "${alerts[0].labels.alertname}",
"告警主机": "${alerts[0].labels.instance}",
"告警详情": "${alerts[0].annotations.description}",
"告警时间": "${alerts[0].startsAt}",
"恢复时间": "${alerts[0].endsAt}"
},
"url": "${alerts[0].generatorURL}"
}
构建规则
{
"title": "${title}",
"description": "告警简述:${description}",
"content": "详情:\n告警等级:${content.告警等级}\n告警类型:${content.告警类型}\n告警主机:${content.告警主机}\n告警详情:${content.告警详情}\n告警时间:${content.告警时间}\n恢复时间:${content.恢复时间}",
"url": "告警链接:${url}"
}

使用的是飞书群机器人通道:
https://xxxxx/webhook/043ecff64e724wec9b1d4f4d56862c7f

报错:
{
"message": "Webhook 提取规则解析失败",
"success": false
}
能帮看看哪个地方不对吗?

@nian8
Copy link

nian8 commented Dec 19, 2024

提取规则 中 只能是 map{string, string} 格式并且 value 用于提取请求体中的数据,源码中是通过 gjson 包处理,
获取 alerts[0].labels.alertname 需要的 正确格式是 alerts.0.labels.alertname

构建规则 只以$ 开头,不需要 {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants