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 }}
  • 相关阅读:
    图的深度优先搜索(递归和非递归c++实现)
    第十届蓝桥杯大赛软件类省赛 迷宫问题题解
    第十届蓝桥杯大赛软件类省赛研究生组 试题D:最短路
    第十届蓝桥杯大赛软件类省赛研究生组 试题H:修改数组
    Redis设计与实现书中勘误-sdstrim函数解释错误
    Clion 引入libevent Undefined symbols for architecture x86_64: "
    RabbitMQ Linux 下 安装
    kafka基本使用
    2种方法改变String 值
    Maven学习笔记-1
  • 原文地址:https://www.cnblogs.com/fat-girl-spring/p/13600473.html
Copyright © 2011-2022 走看看