prometheus-altermanager之钉钉webhook

一、下载插件

1 下载钉钉插件 prometheus-webhook-dingtalk

二进制下载地址: https://github.com/timonwong/prometheus-webhook-dingtalk/releases

bash 复制代码
curl -o prometheus-webhook-dingtalk.tgz -L https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v2.1.0/prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

二、部署

将二进制包解压后,放到合适的位置。

这里放在的 /usr/local/ 下,命名为 prometheus-webhook-dingtalk

bash 复制代码
tar -xf prometheus-webhook-dingtalk.tgz
mv prometheus-webhook-dingtalk-2.1.0.linux-amd64  /usr/local/prometheus-webhook-dingtalk

三、配置 systemd

命令行启动项说明

配置项 含义
--web.listen-address=:8060 程序监听端口,默认 8060
--web.enable-lifecycle 支持通过发送 HTTP 请求,热更新配置文件
--config.file=config.yml 指定配置文件路径
--log.level=info 日志级别 [debug, info, warn, error]
--log.format=logfmt 日志输出格式 [logfmt, json]
--web.enable-ui 可以使用 http://ip:8060/ui 打开测试模版的web界面
--version 输出版本信息

webhook-dingtalk.service

bash 复制代码
[Unit]
Description=The prometheus webhook dingtalk
After=network-online.target
Wants=network-online.target

[Service]
WorkingDirectory=/usr/local/prometheus-webhook-dingtalk
ExecStart=/usr/local/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk --config.file=config.yml --web.enable-lifecycle  --web.enable-ui

KillSignal=SIGQUIT

Restart=always

RestartPreventExitStatus=1 6 SIGABRT

TimeoutStopSec=5
KillMode=process
PrivateTmp=true
LimitNOFILE=1048576
LimitNPROC=1048576

[Install]
WantedBy=multi-user.target

config.yml 是相对于 WorkingDirectory 指定的目录

四、配置文件

在部署包里有个示例文件 config.example.yml

yaml 复制代码
## 请求超时时间
# timeout: 5s

## 为了从头开始编写模板,请取消对以下行的注释
#no_builtin_template: true

## 自定义模版文件路径
#templates:
#  - contrib/templates/legacy/template.tmpl

## 您也可以使用 `default_message` 覆盖默认模板
## The following example to use the 'legacy' template from v0.3.0
#default_message:
#  title: '{{ template "legacy.title" . }}'
#  text: '{{ template "legacy.content" . }}'

## Targets, 以前被称为 "profiles"
targets:
  webhook1:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
    # 钉钉机器人安全设置方式:加签
    secret: SEC000000000000000000000
  webhook2:
    # 这个没有使用 secret 进行安全认证,就需要下钉钉机器人那里设置自定义关键词或者IP地址(段)认证方式。
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
  webhook_legacy:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
    # 自定义的模版内容
    message:
      # Use legacy template
      title: '{{ template "legacy.title" . }}'
      text: '{{ template "legacy.content" . }}'
  webhook_mention_all:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
    # @ 所有人
    mention:
      all: true
  webhook_mention_users:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
    # @ '156xxxx8827' 和 '189xxxx8325'
    mention:
      mobiles: ['156xxxx8827', '189xxxx8325']

secret 是钉钉自定义机器人的加密方式的一种。

具体参考钉钉官方文档

在 alertmanager 中配置

yaml 复制代码
receivers:
  - name: 'web.hook'
    webhook_configs:
      - url: 'http://钉钉插件的IP:端口/dingtalk/webhook1/send'

webhook1 是钉钉插件配置文件中 targets 定义的。

相关推荐
星哥说事4 小时前
告警通知方式:邮件、短信、Slack、钉钉等告警通知方式的配置
数据库·钉钉
颹蕭蕭6 小时前
钉钉占用C盘空间太大怎么办?
钉钉·c盘
学Linux的语莫1 天前
prometheus、grafana的docker搭建
docker·容器·prometheus
为什么不问问神奇的海螺呢丶1 天前
服务器巡检报告-基于categraf 采集数据-存入Prometheus-写入mysql后生成报告
服务器·mysql·prometheus
切糕师学AI1 天前
钉钉Webhook机器人如何发送群消息?
机器人·自动化·钉钉
一枚正在学习的小白1 天前
prometheus监控mysql服务
linux·运维·mysql·prometheus
chen_note2 天前
监控——普罗米修斯
grafana·prometheus
闲人编程2 天前
Prometheus监控指标集成指南
prometheus·监控·promql·仪表盘··cncf·codecapsule
木子欢儿3 天前
Prometheus Blackbox域名SSL证书监控并设置AlertManager告警
网络·网络协议·ssl·prometheus
wxjlkh4 天前
docker 搭建 grafana+prometheus 监控主机资源之node_exporter
docker·grafana·prometheus