prometheus-webhook-dingtalk 最新版安装( 告警方式集成配置文件)

prometheus-webhook-dingtalk, version 1.4.0 安装记录

prometheus 是对alertmanager 告警的一个扩展,支持钉钉,微信,邮件告警和自建告警模板
最新版将告警方式的添加集成到配置文件中,方便添加与修改
下面就讲一下安装最新版本prometheus-webhookdingtalk 安装与踩到的坑

1.获取 prometheus-webhook-dingtalk 安装包
git clone https://github.com/timonwong/prometheus-webhook-dingtalk.git
2.解决依赖
(1)yarn
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum install yarn
(2)go 环境依赖
wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
tar zxf go1.14.2.linux-amd64.tar.gz -C /usr/local/
echo "export PATH=$PATH:/usr/local/go/bin" >>~/.bashrc
source ~/.bashrc
(3)node.js 版本

node.js 要求版本大于等于8

wget https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz
下载node.js 新版本
tar xf node-v12.16.1-linux-x64.tar.xz -C /usr/local/
mv /usr/bin/node /usr/bin/node_bakv6.17.1
ln -s /usr/local/node-v12.16.1-linux-x64/bin/node /usr/bin/node
3.进行编译安装
cd prometheus-webhook-dingtalk.git
make build

等待即可

4.配置 & 启动

启动项

 ./prometheus-webhook-dingtalk --help
usage: prometheus-webhook-dingtalk [<flags>]

Flags:
  -h, --help                  Show context-sensitive help (also try --help-long and --help-man).
      --web.listen-address=":8060"  
                              The address to listen on for web interface.
      --web.enable-ui         Enable Web UI mounted on /ui path
      --web.enable-lifecycle  Enable reload via HTTP request.
      --config.file="config.yml"  
                              Path to the configuration file.
      --log.level=info        Only log messages with the given severity or above. One of: [debug, info, warn, error]
      --log.format=logfmt     Output format of log messages. One of: [logfmt, json]
      --version               Show application version.

配置文件

## Request timeout
# timeout: 5s

## Customizable templates path
此处进行告警模板的指定,不要时使用 --template.file= 进行指定,否则会报错,只会识别tempaltefile 而不去识别指定dingdingwebhook的 配置文件
# templates:       
#   - contrib/templates/legacy/template.tmpl

## You can also override default template using `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, previously was known as "profiles"
targets:
  webhook1:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
    # secret for signature
    secret: SEC000000000000000000000
  webhook2:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
  webhook_legacy:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
    # Customize template content
    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
    mention:
      mobiles: ['156xxxx8827', '189xxxx8325']

踩坑备注

进行告警模板的指定时,不要按照老版本通过 --template.file= 进行指定,会报错,
只会识别tempaltefile 而不去识别指定dingdingwebhook的 配置文件

新版本将 tempaltefile 指定集成到了 配置文件中,只需要在配置文件中指定template file 的位置就行了

Prometheus-webhook-dingtalk是一个用于将Prometheus监控数据发送到钉钉的插件,它通常通过配置文件来进行设置。配置文件包含以下几个关键部分: 1. **webhook-url**: 钉钉 webhook 的 URL 地址,这是接收告警信息的地方。 2. **group-id**: 可选的,指定接收告警通知的工作群组ID,如果没有指定,会默认发送给个人。 3. **access-token**: 钉钉应用的访问令牌,用于身份验证。 4. **template**: 模板选项,定义如何格式化发送的告警消息,包括标题、内容等,可以自定义模板字符串。 5. **relabelings**: 可能还包括一些重命名规则(relabel rules),对Prometheus metrics进行处理,例如修改标签名或值。 6. **labels-to-exclude**: 可能会排除某些标签不发送到钉钉,以控制发送的具体信息。 7. **global-labels**: 全局标签,会在所有发送的消息中添加,提供额外上下文。 ```yaml # 示例配置 prometheus_url: http://localhost:9090 webhook-url: https://oapi.dingtalk.com/robot/send?access_token=<your_access_token> group-id: 123456 template: "【${instance}】监控告警:[${alertname}] ${labels.message}\n详情:[${link}]" relabelings: - source_labels: [__address__] target_label: instance labels_to_exclude: ["__name__"] global_labels: team: "DevOps Team" ``` 要使用这个插件,需要先创建一个Prometheus的Exporter,并确保它的metrics能够被正确地收集,然后将上述配置添加到`prometheus-webhook-dingtalk`的配置文件中。安装并运行该插件后,Prometheus会定期触发webhook,将告警信息推送到钉钉。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值