首页 > 其他分享 >prometheus发送告警信息

prometheus发送告警信息

时间:2024-01-31 19:56:48浏览次数:31  
标签:发送 dingtalk webhook yml 告警信息 prometheus template com email

配置邮件示例

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
           - 192.168.19.55:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
   - "rules/node_rules.yml"
  # - "second_rules.yml"
prometheus.yml
groups:
- name: node-rules
  rules:
  - alert: node-up
    expr: up == 0
    for: 15s
    labels:
      severity: 1
      team: node
    annotations:
      summary: "{{$labels.instance}}Instance has been down for more than 5 minutes"
node_rules.yml
global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.163.com:25'
  smtp_from: '[email protected]'
  smtp_auth_username: '[email protected]'
  smtp_auth_password: '1111111'
  smtp_require_tls: false
templates:
  - '/root/prom/alertmanager-0.26.0.linux-amd64/email.tmpl'
route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 1h
  receiver: 'email'
receivers:
  - name: 'email'
    email_configs:
      - to: '[email protected]'
        html: '{{ template "email.to.html" . }}'
        send_resolved: true
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname']
alertmanager.yml
{{ define "email.to.html" }}
{{ if gt (len .Alerts.Firing) 0 }}{{ range .Alerts }}
@告警: <br>
告警程序: prometheus_alert <br>
告警级别: {{ .Labels.severity }} 级<br>
告警类型: {{ .Labels.alertname }} <br>
故障主机: {{ .Labels.instance }} <br>
告警主题: {{ .Annotations.summary }} <br>
告警详情: {{ .Annotations.description }} <br>
触发时间: {{ .StartsAt }} <br>
{{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}{{ range .Alerts }}
@恢复: <br>
告警主机: {{ .Labels.instance }} <br>
告警主题: {{ .Annotations.summary }} <br>
恢复时间: {{ .EndsAt }} <br>
{{ end }}
{{ end }}
{{ end }}
email.tmpl

   

     up指标用来监控主机是否宕机下线

     告警规则的rule的数据  就是这里的查询语句查询出来的结果

     

      

 配置钉钉消息告警

global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.163.com:25'
  smtp_from: '[email protected]'
  smtp_auth_username: '[email protected]'
  smtp_auth_password: 'TCTJGF'
  smtp_require_tls: false
templates:
  - '/root/prom/alertmanager-0.26.0.linux-amd64/email.tmpl'
route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 1h
  receiver: 'dingding.webhook1'
  routes:
    - receiver: 'dingding.webhook1'
      continue: true  #发送完钉钉消息后继续发送邮件
    - receiver: 'email'

receivers:
  - name: 'email'
    email_configs:
      - to: '[email protected],[email protected],[email protected],[email protected]'
        html: '{{ template "email.to.html" . }}'
        send_resolved: true
  - name: 'dingding.webhook1'
    webhook_configs:
    - url: 'http://192.168.19.55:8060/dingtalk/webhook1/send'
      send_resolved: true

inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname']
alertmanager.yml
## Request timeout
# timeout: 5s

## Uncomment following line in order to write template from scratch (be careful!)
#no_builtin_template: true

## Customizable templates path
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=7f7fe25
    # secret for signature
    secret: 4ee16602f4108eb793475803cfa26a1be5210ccf1
 # 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']
prometheus-webhook-dingtalk.yml

   

    需单独安装  prometheus-webhook-dingtalk-2.1.0.linux-amd64组件

内网代理钉钉消息

     内网中只有一台机器可以联网

     监控的主机无法连接外部的机器

     给prometheus-webhook-dingtalk进程设置代理地址环境变量   不能设置成系统变量,因为这样会影响系统上所有的https请求

     

     添加进程环境变量

      //在程序启动的时候注入多个环境变量
      export https_proxy=http://ct:[email protected]:3128 && export http_proxy=http://cta:[email protected]:3128 && ./prometheus-webhook-dingtalk --config.file=config.yml

     

     

     

      1.把代理地址做为环境变量注入到指定的进程中

         //在程序启动的时候注入一个环境变量
         export https_proxy=http://aaaaa:[email protected]:3128 && ./prometheus-webhook-dingtalk --config.file=config.yml

        //在程序启动的时候注入多个环境变量
        export https_proxy=http://ct:[email protected]:3128 && export http_proxy=http://cta:[email protected]:3128 && ./prometheus-webhook-dingtalk --config.file=config.yml

       2.查看进程的环境变量

          ps -ef | grep webhook

          cat /proc/5663/environ | tr '\0' '\n'

          cat /proc/5663/comm

          

标签:发送,dingtalk,webhook,yml,告警信息,prometheus,template,com,email
From: https://www.cnblogs.com/yxh168/p/17997030

相关文章

  • 初始安装 Prometheus 监控k8s组件 target 状态显示失败的处理办法
    当我们使用Kubeadm完成Kubernetes的搭建时,默认控制面的组件的metrics端点会监听在本机127.0.0.1接口上,这会导致Prometheus/kube-Prometheus-stack开局配置无法从自动发现的端点拉取到指标。方法有如下两种:在使用kubeadm初始安装集群时,更新相关配置在Kubernete......
  • Prometheus+Grafana+Jmeter监控服务器资源及中间件(Prometheus & node_exporter &mysq
    一、Prometheus&node_exporter&Grafana的原理Prometheus:Prometheus是一个开源的系统监控和报警工具包,它负责定时从各种数据源(如NodeExporter)中获取指标数据,并将其存储在自己的时间序列数据库中。Prometheus支持灵活的查询和报警功能,用户可以方便地对这些指标数据进行查询......
  • Prometheus结合Consul采集多个MySQL实例的监控指标
    本文主要介绍如何利用Prometheus官网提供的mysqld_exporter进行多MySQL实例的监控指标采集建议安装最新版的mysqld_exporter,因为从’2022-09-01’之后才支持多实例功能的。具体的官网说明详见 Supportforscrapingmultiplemysqldhosts(#651)[1]ok,开始今天的教程~1、下载安......
  • 前端密码安全发送至服务器端
    用户登录时,密码应该通过安全的方式发送到服务器,然后服务器进行验证,并且不应该将密码直接包含在JWT中。以下是一些常见的方法来确保密码传输的安全性:使用HTTPS:确保登录请求通过HTTPS协议进行传输,这样可以加密通信并防止中间人攻击。哈希密码:在客户端将密码哈希化之后再发送......
  • 07.搭建prometheus
    yaml文件内容及权限:global:scrape_interval:15s#定义抓取指标的时间间隔evaluation_interval:15s#定义评估规则的时间间隔scrape_configs:-job_name:'prometheus'#设置监控任务的名称static_configs:#定义静态目标配置-targets:['localhost:9......
  • prometheus+alertmanager告警消息对接企业微信、飞书、钉钉
    前言  很多公司都在使用prometheus作为监控,并使用alertmanager发送告警消息,然而有的公司内部通讯软件使用的是企业微信,或者是飞书,或者是钉钉,那么如何让监控告警消息发送到这些通讯软件呢。  本文主要通过讲解自己开发的工具alertmanager-webhook来实现该功能,该工具已经支持......
  • prometheus 配置文件汇总
    prometheusprometheus.yaml#myglobalconfigglobal:scrape_interval:15s#Setthescrapeintervaltoevery15seconds.Defaultisevery1minute.evaluation_interval:15s#Evaluaterulesevery15seconds.Thedefaultisevery1minute.#scrape_......
  • C#邮件发送
    C#基于SMTP的邮件发送准备工作注册邮箱首先我们需要注册一个作为发送邮件的邮箱,这一步可以直接进入网易邮箱官网进行注册,注册地址:https://mail.163.com/这里我们可以选择【快速注册】和【普通注册】,如图1-1所示,这里我选择的普通注册;图1-1登录邮箱注册完成之后,我们登录邮......
  • Prometheus 主机监控管理模板
    systemd管理node_exporterhttps://prometheus.io/download/#node_exporterwgethttps://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz~]#tar-xfnode_exporter-1.7.0.linux-amd64.tar.gznode_exporter-1.7.......
  • .net core 注册邮件服务实现发送邮件
    参考文档:https://blog.csdn.net/sD7O95O/article/details/124007107安装nuget包Install-PackageNETCore.MailKit-Version2.0.3 配置配置appsetting.json我使用的是qq邮箱"EmailOptions":{"SenderName":"系统邮件",//发送者名称,可在代码中重新替换"Fr......