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

相关推荐
chaodaibing2 天前
elasticsearch_exporter启动报错 failed to fetch and decode node stats
elasticsearch·prometheus
是陈教授呀3 天前
如何获取钉钉webhook
钉钉
陌殇殇殇4 天前
Prometheus监控MySQL主从数据库
运维·数据库·mysql·prometheus
福大大架构师每日一题4 天前
19.1 使用k8s的sdk编写一个项目获取pod和node信息
云原生·容器·kubernetes·prometheus
福大大架构师每日一题4 天前
19.3 打镜像部署到k8s中,prometheus配置采集并在grafana看图
kubernetes·grafana·prometheus
福大大架构师每日一题4 天前
21.2 k8s中etcd的tls双向认证原理解析
容器·kubernetes·prometheus·etcd
我的运维人生5 天前
基于Prometheus和Grafana的现代服务器监控体系构建
服务器·运维开发·grafana·prometheus·技术共享
BUG弄潮儿5 天前
k8s 部署 prometheus
容器·kubernetes·prometheus
东方巴黎~Sunsiny5 天前
java项目实现钉钉异常告警实时监控
java·开发语言·钉钉
是陈教授呀5 天前
钉钉如何请求webhook发送信息
钉钉