prometheus 是对alertmanager 告警的一个扩展,支持钉钉,微信,邮件告警和自建告警模板
最新版将告警方式的添加集成到配置文件中,方便添加与修改
下面就讲一下安装最新版本prometheus-webhookdingtalk 安装与踩到的坑
git clone https://github.com/timonwong/prometheus-webhook-dingtalk.git
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
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
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
cd prometheus-webhook-dingtalk.git
make build
等待即可
启动项
./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 的位置就行了