首页 > 其他分享 >使用Jiralert实现AlertManager告警对接Jira

使用Jiralert实现AlertManager告警对接Jira

时间:2023-01-04 10:45:34浏览次数:61  
标签:Jira AlertManager template Issue Jiralert reopen jiralert issue

简介

Alertmanager 处理由客户端应用程序(如 Prometheus server)发送的警报。它负责去重(deduplicating),分组(grouping),并将它们路由(routing)到正确的接收器(receiver)集成,如电子邮件,微信,或钉钉。它还负责处理警报的静默/屏蔽(silencing)、定时发送/不发送(Mute)和抑制(inhibition)问题。

AlertManager 作为 开源的为 Prometheus 而设计的告警应用, 已经具备了告警应用各类丰富、灵活、可定制的功能:

Jiralert

用于JIRA的Prometheus Alertmanager Webhook Receiver

JIRAlert实现了Alertmanager的webhook HTTP API,并连接到一个或多个JIRA实例以创建高度可配置的JIRA Issues。每个不同的 Groupkey 创建一个Issue--由Alertmanager的路由配置部分的group_by参数定义--但在警报解决时不会关闭(默认参数, 可调整)。我们的期望是,人们会查看这个issue。,采取任何必要的行动,然后关闭它。如果没有人的互动是必要的,那么它可能首先就不应该报警。然而,这种行为可以通过设置auto_resolve部分进行修改,它将以所需的状态解决jira issue。

如果一个相应的JIRA issue。已经存在,但被解决了,它将被重新打开(reopened)。在解决的状态和重开的状态之间必须存在一个JIRA transition--如reopen_state--否则重开将失败。可以选择定义一个 "won't fix" 的决议(resolution)--由wont_fix_resolution定义:有此决议的JIRA问题将不会被JIRAlert重新打开。

安装 Jiralert

Jiralert 的安装比较简单, 主要由 Deployment、Secret(Jiralert 的配置)和 Service 组成。典型示例如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jiralert
spec:
  selector:
    matchLabels:
      app: jiralert
  template:
    metadata:
      labels:
        app: jiralert
    spec:
      containers:
      - name: jiralert
        image: quay.io/jiralert/jiralert-linux-amd64:latest
        imagePullPolicy: IfNotPresent
        args:
        - "--config=/jiralert-config/jiralert.yml"
        - "--log.level=debug"
        - "--listen-address=:9097"
        readinessProbe:
          tcpSocket:
            port: 9097
          initialDelaySeconds: 15
          periodSeconds: 15
          timeoutSeconds: 5
        livenessProbe:
          tcpSocket:
            port: 9097
          initialDelaySeconds: 15
          periodSeconds: 15
          timeoutSeconds: 5
        ports:
        - containerPort: 9091
          name: metrics
        volumeMounts:
        - mountPath: /jiralert-config
          name: jiralert-config
          readOnly: true
      volumes:
      - name: jiralert-config
        secret:
          secretName: jiralert-config
---
apiVersion: v1
kind: Secret
type: Opaque
metadata:
  name: jiralert-config
stringData:
  jiralert.tmpl: |-
    {{ define "jira.summary" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join "," }}{{ end }}
    
    {{ define "jira.description" }}{{ range .Alerts.Firing }}Labels:
    {{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
    {{ end }}
    
    Annotations:
    {{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
    {{ end }}
    
    Source: {{ .GeneratorURL }}
    {{ end }}
    
    CommonLabels:
    {{ range .CommonLabels.SortedPairs }} - {{ .Name }} = {{ .Value}}
    {{ end }}
    
    GroupLabels:
    {{ range .GroupLabels.SortedPairs }} - {{ .Name }} = {{ .Value}}
    {{ end }}
    {{ end }}
  jiralert.yml: |-
    # Global defaults, applied to all receivers where not explicitly overridden. Optional.
    template: jiralert.tmpl
    defaults:
      # API access fields.
      api_url: https://jira.example.com
      user: foo
      password: bar
      # The type of JIRA issue to create. Required.
      issue_type: Bug
      # Issue priority. Optional.
      priority: Major
      # Go template invocation for generating the summary. Required.
      summary: '{{ template "jira.summary" . }}'
      # Go template invocation for generating the description. Optional.
      description: '{{ template "jira.description" . }}'
      # State to transition into when reopening a closed issue. Required.
      reopen_state: "REOPENED"
      # Do not reopen issues with this resolution. Optional.
      wont_fix_resolution: "Won't Fix"
      # Amount of time after being closed that an issue should be reopened, after which, a new issue is created.
      # Optional (default: always reopen)
      # reopen_duration: 30d
    
    # Receiver definitions. At least one must be defined.
    # Receiver names must match the Alertmanager receiver names. Required.
    receivers:
    - name: 'jiralert'
      project: 'YOUR-JIRA-PROJECT'
---
apiVersion: v1
kind: Service
metadata:
  name: jiralert
spec:
  selector:
    app: jiralert
  ports:
  - port: 9097
    targetPort: 9097                

相应 AlertManager 的配置:

...
receivers:
- name: jiralert
  webhook_configs:
  - send_resolved: true
    url: http://jiralert:9097/alert
routes:
- receiver: jiralert
  matchers:
  - severity = critical
  continue: true
...

标签:Jira,AlertManager,template,Issue,Jiralert,reopen,jiralert,issue
From: https://www.cnblogs.com/east4ming/p/17024209.html

相关文章

  • JIRA系统使用总结
    每天JIRA会备份两次在这个目录/var/atlassian/application-data/jira/exportJIRA系统遇到损坏,可能是索引目录损坏可以重构索引 索引路径/var/atlassian/application-data......
  • 《Jira实战》作者王杰-使用Jira打造精益敏捷的交付能力
    关于文章作者:王杰,现就职于科大讯飞,担任集团测试序列专家、测试总监、业务高级经理。中国科学技术大学工商管理硕士,精通DevOps,在上游质量内建和研测效能提升上有丰富的实战经......
  • Alertmanager 告警处理前准备(node_exporter下线告警规则)3
    一.告警规则告警规则是通过YAML格式进行定义,在Prometheusserver中使用PromQL配置实际告警解发条件,Prometheus会根据告警规则及配置周期进行周期性计算,若满足触发条......
  • Alertmanager 关联Prometheus(2)
    一.与Alertmanager关联Prometheus把产生的告警发送给Alertmanager进行告警处理时,需要在Prometheus使用的配置文件中添加关联Alertmanager组件的对应配置内容。......
  • Alertmanager 告警介绍和部署(1)
    一.概述告警是整个监控系统中重要的组成部分,在Prometheus监控体系中,指标的采集存储与告警是分开的。告警规则是在Prometheusserver端定义的,告警规则被触发后,才会将信......
  • 安装confluence7.19.4、jira9.4破解并使用Nginx代理
    背景略安装jira准备两个目录,一个是jira的安装目录,一个是jira的home目录,数据都存在home目录/data/jira/data/jira_home下载,解压wgethttps://product-downl......
  • Prometheus+Grafana+alertmanager+ 邮件 +钉钉告警
    Prometheus+Grafana+alertmanager+邮件+钉钉告警本文模拟生产环境一ansible部署ansbile部署在线安装yuminstallansible-y离线安装#离线环境,提前在有网络的服......
  • 【云原生】Prometheus AlertManager讲解与实战操作
    目录一、概述二、AlertManager架构三、AlertManager部署1)下载2)配置3)启动服务4)与Prometheus集成四、在Prometheus中设置告警规则五、AlertManager告警通道配置一、概述......
  • JIRA API 集成经验总结
    JIRA集成总结由于工作需要,系统需要集成JIRAAPI去自动创建ticket,期间几乎没有遇到太多坑,可能和JIRAAPIdocument规范有关吧,不得不说,JIRAAPIdocument是我见过......
  • 搭建Prometheus+Grafana+AlertManager监控报警系统之CentOS 7安装node exporter
    简介在Prometheus的架构设计中,PrometheusServer并不直接服务监控特定的目标,其主要任务负责数据的收集,存储并且对外提供数据查询支持。因此为了能够能够监控到某些东西,如......