章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • linux

  • windows

  • 中间件

  • 网络

  • 安全

  • 存储

  • 防火墙

  • 数据库

  • 系统

  • docker

  • other

  • 监控

    • zabbix

    • prometheus

      • prometheus监控、告警与存储
      • 使用docker-compose搭建promethes+grafana监控系统
      • prometheus添加钉钉消息告警
        • alertmanager实现某个时间段静默某些告警项
        • prometheus设置表达式触发告警
        • 监控MySQL运行状态:MySQLD Exporter
        • alertmanager设置定时静默告警脚本
        • 构建高大上的黑盒监控平台
        • prometheus使用一个redis_exporter监控所有redis实例
        • alertmanager-webhook与API
    • 运维
    • 监控
    • prometheus
    章工运维
    2023-01-10
    目录

    prometheus添加钉钉消息告警

    # 安装prometheus-webhook-dingtalk插件

    #下载
    wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v1.4.0/prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
    #解压
    tar -zxf prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
    # 移动到安装目录
    mv prometheus-webhook-dingtalk-1.4.0.linux-amd64 /opt/apps/dingding/prometheus-webhook-dingtalk
    # 进入目录
    cd /opt/apps/dingding/prometheus-webhook-dingtalk
    
    1
    2
    3
    4
    5
    6
    7
    8

    # 创建启动服务文件

    #prometheus-webhook-dingtalk.service
    [Unit]
    Description=prometheus-webhook-dingtalk
    After=network-online.target
    
    [Service]
    Restart=on-failure
    ExecStart=/opt/apps/dingding/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk --config.file=/opt/apps/dingding/prometheus-webhook-dingtalk/config.yml
    
    [Install]
    WantedBy=default.target
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    将prometheus-webhook-dingtalk.service文件移动到/usr/lib/systemd/system下

    #生效系统文件
    systemctl daemon-reload
    # 启动
    systemctl start prometheus-webhook-dingtalk.service
    # 停止
    systemctl stop prometheus-webhook-dingtalk.service 
    
    1
    2
    3
    4
    5
    6

    配置文件config.yml

    ## Request timeout
    # timeout: 5s
    
    ## Customizable templates path
    templates:
      - /opt/apps/dingding/prometheus-webhook-dingtalk/contrib/templates/default.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:
      webhook:
        url: https://oapi.dingtalk.com/robot/send?access_token=xxx
        message:
          title: '{{ template "default.title" . }}'
          text: '{{ template "default.content" . }}'
      webhook1:
        url: https://oapi.dingtalk.com/robot/send?access_token=xxx
        message:
          title: '{{ template "default.title" . }}'
          text: '{{ template "default.content" . }}'
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25

    告警模板default.tmpl

    {{ define "__subject" }}
    [{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}]
    {{ end }}
    
    {{ define "__alert_list" }}{{ range . }}
    ---
    **告警名称**: {{ index .Annotations "summary" }}
    
    **告警级别**: {{ .Labels.severity }}
    
    **告警主机**: {{ .Labels.instance }}
    
    **告警信息**: {{ index .Annotations "description" }}
    
    **维护团队**: {{ .Labels.team | upper }}
    
    **告警时间**: {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}
    
    {{ end }}{{ end }}
    
    {{ define "__resolved_list" }}{{ range . }}
    ---
    **告警名称**: {{ index .Annotations "summary" }}
    
    **告警级别**: {{ .Labels.severity }}
    
    **告警主机**: {{ .Labels.instance }}
    
    **告警信息**: {{ index .Annotations "description" }}
    
    **维护团队**: {{ .Labels.team | upper }}
    
    **告警时间**: {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}
    
    **恢复时间**: {{ dateInZone "2006.01.02 15:04:05" (.EndsAt) "Asia/Shanghai" }}
    
    {{ end }}{{ end }}
    
    
    {{ define "default.title" }}
    {{ template "__subject" . }}
    {{ end }}
    
    {{ define "default.content" }}
    ![警报 图标](https://oss-test-v1.1quant.com/monitor/logo.png)
    
    {{ if gt (len .Alerts.Firing) 0 }}
    
    **====侦测到{{ .Alerts.Firing | len  }}个故障====**
    {{ template "__alert_list" .Alerts.Firing }}
    ---
    {{ end }}
    
    {{ if gt (len .Alerts.Resolved) 0 }}
    **====恢复{{ .Alerts.Resolved | len  }}个故障====**
    {{ template "__resolved_list" .Alerts.Resolved }}
    {{ end }}
    {{ end }}
    
    
    {{ define "ding.link.title" }}{{ template "default.title" . }}{{ end }}
    {{ define "ding.link.content" }}{{ template "default.content" . }}{{ end }}
    {{ template "default.title" . }}
    {{ template "default.content" . }}
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    微信 支付宝
    上次更新: 2023/06/09, 19:14:23

    ← 使用docker-compose搭建promethes+grafana监控系统 alertmanager实现某个时间段静默某些告警项→

    最近更新
    01
    shell脚本模块集合
    05-13
    02
    生活小技巧(认知版)
    04-29
    03
    生活小技巧(防骗版)
    04-29
    更多文章>
    Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式