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 定义的。

相关推荐
成为你的宁宁8 小时前
【基于 Docker-compose 部署 Prometheus 监控系统实战教程 】
docker·容器·prometheus
成为你的宁宁9 小时前
【Prometheus+Grafana 监控平台二进制安装配置(图文实操详解)】
grafana·prometheus
蜀道山老天师11 小时前
实操|Prometheus Pushgateway 部署、推送与数据管理全流程
运维·服务器·云原生·prometheus
蜀道山老天师1 天前
Docker Compose实战案例:一键部署WordPress+Prometheus监控平台
运维·docker·容器·prometheus
川石课堂软件测试1 天前
接口测试常见面试题及答案
python·网络协议·mysql·华为·单元测试·prometheus·harmonyos
切糕师学AI1 天前
钉钉API双轨制升级:平台演进的两难抉择与技术哲学
架构·钉钉
蜀道山老天师3 天前
从零搭建 Prometheus 监控 MySQL:含二进制安装、授权、exporter 配置全流程
运维·数据库·mysql·adb·云原生·prometheus
令狐少侠20113 天前
创建钉钉企业内应用,钉钉AI助手操作钉钉文档
ai·钉钉
蜀道山老天师3 天前
Prometheus监控Hadoop集群(实操完整版,含避坑指南)
大数据·linux·运维·hadoop·云原生·prometheus
虎头金猫4 天前
Beszel 轻量服务器监控:多台服务器状态统一看,搭起来比 Prometheus 省事太多
linux·运维·服务器·分布式·kafka·开源·prometheus