zoukankan      html  css  js  c++  java
  • alertmanager 通过企业微信告警&自定义告警模板

    准备工作

      注册企业微信很简单也没有审核, 百度一下即可。

    创建部门

      创建部门需要记录部门ID

    1. 选择通讯录,添加部门。

     

     2. 查看部门ID

    创建应用

    1. 选择应用管理, 自建 -> 创建应用。

     

     

     3. 查看 AgentID & Secret

     

     4. 企业微信查看 Secret

     

    查看企业ID

      选择我的企业拉倒底部可以查看

    alertmanager 配置

    配置文件

    templates:
      - './template/alertmanager-wechat.tmpl'
    route:                                      # 路由组
      group_by: ['alertname', 'app']                   # 
      group_wait: 30s
      group_interval: 40s
      repeat_interval: 1m
      receiver: wechat                 # 默认组
    
    
      
    receivers:                            
    - name: 'wechat'
      wechat_configs:
      - send_resolved: true
        message: '{{ template "wechat.default.message" . }}'
        to_party: '2'                                                  # 企业微信中,创建的接收告警的部门【告警机器人】的部门ID
        agent_id: '10qqq04'                                            # 企业微信中,创建的应用的 Agent ID
        api_secret: 'x-HmLE-Q3ubZcWRwwwwwwwwwwwvYvKJMACDI35IvFc0'      # 企业微信中,应用的Secret
        corp_id: 'ww31e8e1d84f2dcdae'                                  # 企业微信中,企业ID

    模板文件

    [root@ops alertmanager]# cat template/alertmanager-wechat.tmpl 
    {{ define "wechat.default.message" }}
    {{- if gt (len .Alerts.Firing) 0 -}}
    {{- range $index, $alert := .Alerts -}}
    
    =========  监控告警 =========
    告警程序:     Alertmanager
    告警类型:    {{ $alert.Labels.alertname }}
    告警级别:    {{ $alert.Labels.severity }} 级
    告警状态:    {{ .Status }}
    故障主机:    {{ $alert.Labels.instance }} {{ $alert.Labels.device }}
    告警主题:    {{ .Annotations.summary }}
    告警详情:    {{ $alert.Annotations.message }}{{ $alert.Annotations.description}}
    主机标签:    {{ range .Labels.SortedPairs  }}  [{{ .Name }}: {{ .Value  | html }} ] {{- end }} 
    故障时间:    {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
    ========= = end =  =========
    {{- end }}
    {{- end }}
    
    {{- if gt (len .Alerts.Resolved) 0 -}}
    {{- range $index, $alert := .Alerts -}}
    
    ========= 告警恢复 =========
    告警程序:     Alertmanager
    告警主题:    {{ $alert.Annotations.summary }}
    告警主机:    {{ .Labels.instance }}
    告警类型:    {{ .Labels.alertname }}
    告警级别:    {{ $alert.Labels.severity }} 级
    告警状态:    {{   .Status }}
    告警详情:    {{ $alert.Annotations.message }}{{ $alert.Annotations.description}}
    故障时间:    {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
    恢复时间:    {{ ($alert.EndsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
    ========= = end =  =========
    {{- end }}
    {{- end }}
    {{- end }}

    效果演示

    告警触发

    告警恢复

  • 相关阅读:
    子类构造函数是否会默认调用父类的无参构造函数
    使用多线程
    进程和多线程的概念及线程的优点
    Java API文档
    InputStream
    【颗粒归仓】--Zookeeper基本概念
    【颗粒归仓】--Struts2
    【颗粒归仓】--spring IoC容器
    【颗粒归仓】--Java泛型
    【多线程】--线程同步
  • 原文地址:https://www.cnblogs.com/yanshicheng/p/15550328.html
Copyright © 2011-2022 走看看