使用Jiralert实现AlertManager告警对接Jira

news2024/9/25 15:26:58

简介

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

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

  • Prometheus AlertManager 系列文章

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
...

📝 说明:

  • 官方 jiralert 镜像地址: https://quay.io/repository/jiralert/jiralert-linux-amd64?tab=tags
    • 官方 jiralert latest 镜像: <quay.io/jiralert/jiralert-linux-amd64:latest>
  • jiralert.tmpl 类似 AlertManager 的 Template, 发送到 Jira 的 Issue 会以此为模板
  • jiralert.yml Jiralert 的配置文件
    • defaults 基础版配置
    • receivers 可以设置多个 receiver, 届时 AlertManager 要发到哪个 Jira 的receiver就需要与这个 jiralert 的receiver 同名. (比如上面的例子, 都是jiralert)

Jiralert 配置

经过生产实践的 Jiralert 完整配置如下:

# Global defaults, applied to all receivers where not explicitly overridden. Optional.
template: jiralert.tmpl
defaults:
  # API access fields.
  api_url: https://example.atlassian.net
  user: <your-account-email>
  password: '<your-account-api-token>'
  # The type of JIRA issue to create. Required.
  issue_type: Support
  # Issue priority. Optional.
  priority: High
  # 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: "Back to in progress"
  # Do not reopen issues with this resolution. Optional.
  wont_fix_resolution: "Won't Do"
  # 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-project-code>
  add_group_labels: true
  auto_resolve:
    state: 'Resolve this issue'

📝详细说明如下:

  1. api_url: Jira 的地址, 如果用的是 Jira 的 SaaS 服务, 就是https://<tenant>.atlassian.net
  2. 认证:
    1. 对于公有云版的 Jira, 只能用 userpassword, 其中:
      1. user 填写你的账号邮箱地址;
      2. password 需要先在 API Token | Atlassian account 申请 API Token. (🐾注意: 登录用的密码是无法认证通过的)
    2. 对于其他版本, 也可以填写使用 personal_access_token 进行认证. 其值为: user@example.com:api_token_string 的 base64 编码后字符串. 具体说明见: Basic auth for REST APIs (atlassian.com)
  3. issue_type: 根据您的 Jira Issue Type 来填写, 可能是: Alert Support Bug New Feature 等等或其他
  4. priority 根据您的 Issue priority 来填写, 可能是: Critical High Medium Low 等等或其他
  5. reopen_state: Jira 的问题已经关闭, 要重新打开, 需要的 transition, 如: Back to in progress. (🐾注意: 这里需要填写的是您自定义的 transition, 而非 status)
  6. wont_fix_resolution: 带有这个 resolution (解决方案)的问题就不会重新打开. 如: Won't Do Won't Fix, 需要根据自己的 resolution 定义内容来填写.
  7. reopen_duration: 多久时间之内的问题会重新打开, 默认是 always reopen, 可以设置为如: 30d, 表示这个问题如果30天以前有同样的问题, 新开一个 Issue, 而不是重新打开老的 Issue.
  8. receivers: 可以定义多个 receivers, 指向不同 project
  9. project: Jira 的 Project ID, 是 Project 详细名字的首字母大写. 如 Project 是 For Example, 这里就填写 FE
  10. add_group_labels: 是否要将 AlertManager 的 Group Labels 加到 Jira 的 Labels. (🐾注意: Jira Labels 的 Value 是不能有空格的, 所以如果你的 AlertManager 的 Group Label 的Value如果有空格, 不要开启此项功能)
  11. auto_resolve: 最新 1.2 版本新增的功能, 当告警恢复了, 可以自动 resolve 对应的 Jira Issue.
    1. state: 'Resolve this issue' 这里也是要填写您预定义的 Jira 解决该问题的 transition 而非 status, 如'Resolve this issue'.

其他疑难情况

如果你碰到各种诡异的日志, 原因大部分都是因为没有正确认证登录导致的, 典型的比如这个报错:

The value 'XXX' does not exist for the field 'project'.

事实上就是因为没有正确认证登录导致的.

具体可以参考这里: Solved: REST error "The value 'XXX' does not exist for the... (atlassian.com)

还有一类报错, 提示您无法 transition an issue, 这往往是因为以下几种原因:

  1. Jiralert 中reopen_stateauto_resolvestate 没有填写正确的 transition
  2. 您用的账号没有相应的权限
  3. 该 Issue 现在所处的状态(比如 Closed)不允许再进行 transition

具体可以参考这里: I can't transition an issue in my Jira project - W... - Atlassian Community

最终效果

如下图:

Jiralert 效果

可以创建 Issue, 更新 Summary, 更新 Description, 更新 Resolution, 更新 Status; 同样问题再次出现, reopen 之前的 Issue...

🎉🎉🎉

📚️ 参考文档

  • jiralert manifests for kubernetes (github.com)
  • jiralert/examples at master · prometheus-community/jiralert (github.com)
  • jiralert images | Quay

三人行, 必有我师; 知识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/140333.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MMYOLO 自定义数据集从标注到部署保姆级教程

theme: juejin 来自社区 PeterH0323 投稿 AI 已经被应用到各行各业&#xff0c;现如今任何人都可以轻松基于开源框架快速搭建符合自身需求的 AI 应用。本文将基于 MMYOLO 开源框架&#xff0c;基于生活中收集的猫猫数据集&#xff0c;教你如何从零开始训练一个可部署检测模型…

TiCDC 源码阅读(二)TiKV CDC 模块介绍

内容概要 TiCDC 是一款 TiDB 增量数据同步工具&#xff0c;通过拉取上游 TiKV 的数据变更日志&#xff0c;TiCDC 可以将数据解析为有序的行级变更数据输出到下游。 本文是 TiCDC 源码解读的第二篇&#xff0c;将于大家介绍 TiCDC 的重要组成部分&#xff0c;TiKV 中的 CDC 模…

【C++】命名空间(namespace) 以及理解using namespace std

命名空间1.命名空间使用的背景1.背景2.命名空间的定义&#xff08;namespace&#xff09;2.1正常的定义2.2 命名空间可以嵌套定义2.3允许命名空间相同3.域作用限定符&#xff08;&#xff1a;&#xff1a;&#xff09;和命名空间的使用3.1域作用限定符&#xff08;&#xff1a;…

【nodejs】模块化

一、概念 1、模块化 编程领域中的模块化&#xff0c;就是遵守固定的规则&#xff0c;把一个大文件拆成独立并相互依赖的多个小模块 把代码进行模块化拆分的好处&#xff1a; 1、提高代码的复用性 2、提高代码的可维护性 3、可以实现按需加载 2、模块化规范 对代码进行模块化…

《CSS新世界》读书笔记

前言 本文为《CSS新世界》的读书笔记。推荐去读原著。 《CSS新世界》微信读书APP链接&#xff1a;CSS新世界-张鑫旭-微信读书 (qq.com) 1. 尺寸属性值&#xff1a;fit-content 描述 fit-content 不是一个属性&#xff0c;它是 css 尺寸系列属性的一个新属性值。可用在 wid…

lammps教程:旋转模型的技巧

大家好&#xff0c;我是小马老师。 本文介绍lammps翻转模型的方法。 在进行分子动力学模拟时&#xff0c;可能需要特定的面位于设定的方向。 如Al2O3的力学性能模拟中&#xff0c;需要分别对A、B、C面进行压痕或者摩擦模拟。 按照研究界面垂直z轴&#xff0c;并且面法线沿着z轴…

转转测试环境治理的高效能实践

文章目录1. 背景及需求1.1 系统架构的发展1.2 测试环境的需求2. 传统的测试环境解决方案-物理隔离3. 转转测试环境V1-改进的物理隔离3.1 稳定环境3.2 动态环境3.3 优缺点3.3.1 优点3.3.2 缺点4. 转转测试环境V2-基于自动IP标签的流量路由5. 转转测试环境V3-基于手动标签的流量路…

大数据挖掘-伤寒论和金匮要略(COVID-19用药启示录,1.4万字收藏)

来自Toby老师&#xff0c;大数据挖掘-伤寒论和金匮要略 大家好&#xff0c;我是Toby老师&#xff0c;三年来新冠病毒肆虐全球&#xff0c;带来一些列症状&#xff0c;例如发热&#xff0c;恶寒&#xff0c;咳嗽&#xff0c;咽喉痛&#xff0c;腹泻&#xff0c;心脑血管疾病等…

C语言_动态内存管理

目录 1. 为什么存在动态内存管理 2. 动态内存函数介绍 2.1 开辟内存块函数_malloc 2.2 动态内存释放和回收函数_free 2.3 开辟空间初始化元素为0的函数_calloc 2.4 调整动态内存开辟大小的函数_realloc 3. 常见的动态内存错误 3.1 对NULL进行解引用操作 3.2 对动态开辟…

aloam学习笔记(二)

学习aloam框架中前端对于点云部分的预处理和点面特征提取。 这些功能在scanRegistration.cpp部分实现&#xff0c;所以也是对于这个源码的学习。 一、main函数 从main函数开始分析。 首先整个完整的main函数内容&#xff1a; int main(int argc, char **argv) {ros::init(…

RSA、MD5加密解密算法全套解析安装教程

第一部分介绍加密解密算法&#xff0c; 第二部分介绍我小组成功应用的RSA、MD5两种加密解密算法&#xff0c;以及心得体会。 1、加密解密算法介绍 应用的开发中安全很重要&#xff0c;所以信息加密技术显得尤为重要。我们需要对应用中的多项数据进行加密处理&#xff0c;从而来…

(人工智能的数学基础)第一章特征向量与矩阵分析——第三节:特征向量与特征值

参考 3Blue1Brown系列&#xff1a;特征向量和特征值第十章 线性代数之 特征向量与特征值】3Blue1Brown知乎&#xff1a;线性代数的本质10 特征向量和特征值 文章目录一&#xff1a;特征向量与特征值概念引入二&#xff1a;特征向量与特征值概念求解三&#xff1a;特征向量与特…

谷粒学院——第七章、课程分类管理

EasyExcel 介绍 简介 Excel导入导出的应用场景 1、数据导入:减轻录入工作量 2、数据导出:统计信息归档 3、数据传输:异构系统之间数据传输 EasyExcel的特点 Java 领域解析、生成 Excel 比较有名的框架有 Apache poi、jxl 等。但他们都存在一个严重的问题就是非常的耗内存。…

Python数据分析三剑客之Pandas

写在前面的话&#xff1a; 开始之前请确保已经配置好python环境&#xff0c;并安装好第三方库pandas和numpy。 1. pandas库介绍 什么是pandas&#xff1f;pandas是提供高性能易用数据类型和数据分析工具的第三方库。简单讲&#xff0c;pandas主要作用有两个&#xff1a;提供了…

电子学会2020年6月青少年软件编程(图形化)等级考试试卷(二级)答案解析

目录 一、单选题&#xff08;共25题&#xff0c;每题2分&#xff0c;共50分&#xff09; 二、判断题&#xff08;共10题&#xff0c;每题2分&#xff0c;共20分&#xff09; 三、编程题&#xff08;共3题&#xff0c;共30分&#xff09; 青少年软件编程&#xff08;Scratch&…

谷粒学院——第八章、课程管理

一、课程添加功能 概览 课程添加的步骤 课程相关表的关系 后端实现 1、代码生成器 只修改表名即可&#xff0c;依次填入&#xff1a;“edu_course”, “edu_course_description”, “edu_chapter”, “edu_video” 生成完成后&#xff0c; 删除EduCourseDescriptionContr…

力扣 1801. 积压订单中的订单总数

题目 给你一个二维整数数组 orders &#xff0c;其中每个 orders[i] [pricei, amounti, orderTypei] 表示有 amounti 笔类型为 orderTypei 、价格为 pricei 的订单。 订单类型 orderTypei 可以分为两种&#xff1a; 0 表示这是一批采购订单 buy 1 表示这是一批销售订单 sel…

学习疑惑:用什么方法进行产品原型设计

对于在互联网行业的各位来讲&#xff0c;应该很清楚原型设计在应用开发中的重要性。它所起到的不仅是沟通的作用&#xff0c;更有体现之效。通过内容和结构展示&#xff0c;以及粗略布局&#xff0c;能够说明用户将如何与产品进行交互&#xff0c;体现开发者及UI设计师的idea&a…

pytorch拼接函数:torch.stack()和torch.cat()详解

在pytorch中&#xff0c;常见的拼接函数主要是两个&#xff0c;分别是&#xff1a;stack()和cat()。 torch.stack()函数的意义&#xff1a;使用stack可以保留两个信息&#xff1a;[1. 序列] 和 [2. 张量矩阵] 信息&#xff0c;属于【扩张再拼接】的函数。 形象的理解&#xff…

谷粒学院——第十二章、Banner轮播图

Banner微服务 配置 Nginx 修改文件&#xff1a;nginx.conf 修改完后&#xff0c;重启 nginx nginx -s reload创建项目和初始化 1、新建模块 service_cms 2、配置文件和启动类 创建配置文件&#xff1a;application.properties # 服务端口 server.port8004# 服务名 spr…