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 的位置就行了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章