zoukankan      html  css  js  c++  java
  • Prometheus微信告警

    前提:创建企业微信,创建应用

    然后配置altermanager.yaml

    global:
    resolve_timeout: 5m
    wechat_api_corp_id: 'xxx'
    wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
    wechat_api_secret: 'xxxx'
    templates:
    - '/server/alertmanager/template/wechat.tmpl'
    route:
    group_by: ['alertname']
    group_wait: 10s
    group_interval: 10s
    repeat_interval: 1h
    receiver:
    - name: 'wechat'
    wechat_configs:
    - send_resolved: true
    to_party: '2'
    agent_id: 100000
    corp_id: 'xxx'
    api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
    api_secret: 'xxxx'
    inhibit_rules:
    - source_match:
    severity: 'critical'
    target_match:
    severity: 'warning'
    equal: ['alertname', 'dev', 'instance']

    自定义模板

    {{ define "wechat.default.message" }}
    {{- if gt (len .Alerts.Firing) 0 -}}
    {{- range $index, $alert := .Alerts -}}
    {{- if eq $index 0 }}
    ==========异常告警==========
    告警类型: {{ $alert.Labels.alertname }}
    告警级别: {{ $alert.Labels.severity }}
    告警详情: {{ $alert.Annotations.message }}{{ $alert.Annotations.description}};{{$alert.Annotations.summary}}
    故障时间: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
    {{- if gt (len $alert.Labels.instance) 0 }}
    实例信息: {{ $alert.Labels.instance }}
    {{- end }}
    {{- if gt (len $alert.Labels.namespace) 0 }}
    命名空间: {{ $alert.Labels.namespace }}
    {{- end }}
    {{- if gt (len $alert.Labels.node) 0 }}
    节点信息: {{ $alert.Labels.node }}
    {{- end }}
    {{- if gt (len $alert.Labels.pod) 0 }}
    实例名称: {{ $alert.Labels.pod }}
    {{- end }}
    ============END============
    {{- end }}
    {{- end }}
    {{- end }}
    {{- if gt (len .Alerts.Resolved) 0 -}}
    {{- range $index, $alert := .Alerts -}}
    {{- if eq $index 0 }}
    ==========异常恢复==========
    告警类型: {{ $alert.Labels.alertname }}
    告警级别: {{ $alert.Labels.severity }}
    告警详情: {{ $alert.Annotations.message }}{{ $alert.Annotations.description}};{{$alert.Annotations.summary}}
    故障时间: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
    恢复时间: {{ ($alert.EndsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
    {{- if gt (len $alert.Labels.instance) 0 }}
    实例信息: {{ $alert.Labels.instance }}
    {{- end }}
    {{- if gt (len $alert.Labels.namespace) 0 }}
    命名空间: {{ $alert.Labels.namespace }}
    {{- end }}
    {{- if gt (len $alert.Labels.node) 0 }}
    节点信息: {{ $alert.Labels.node }}
    {{- end }}
    {{- if gt (len $alert.Labels.pod) 0 }}
    实例名称: {{ $alert.Labels.pod }}
    {{- end }}
    ============END============
    {{- end }}
    {{- end }}
    {{- end }}
    {{- end }}
  • 相关阅读:
    域控制器的常规卸载,Active Directory系列之十三
    理解域信任关系,Active Directory系列之十六
    什么是站点,Active Directory系列之十一
    域控制器的强制卸载,Active Directory系列之十四
    详解操作主机角色,Active Directory系列之九
    【转】MapControl和PageLayoutControl的同步
    AE的一些接口小记
    【转】centos linux 上flv/swf视频服务器架设
    lnmp配置超精简免费flv流媒体服务器笔记
    Flash game 遊戲修改 Cheat Engine 5.4 使用教學
  • 原文地址:https://www.cnblogs.com/fat-girl-spring/p/13600473.html
Copyright © 2011-2022 走看看