使用Jiralert实现AlertManager告警对接Jira
简介
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
...
说明:
- 官方 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.ymlJiralert 的配置文件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'
详细说明如下:
api_url: Jira 的地址, 如果用的是 Jira 的 SaaS 服务, 就是https://<tenant>.atlassian.net- 认证:
- 对于公有云版的 Jira, 只能用
user和password, 其中:user填写你的账号邮箱地址;password需要先在 API Token | Atlassian account 申请 API Token. (注意: 登录用的密码是无法认证通过的)
- 对于其他版本, 也可以填写使用
personal_access_token进行认证. 其值为:user@example.com:api_token_string的 base64 编码后字符串. 具体说明见: Basic auth for REST APIs (atlassian.com)
- 对于公有云版的 Jira, 只能用
issue_type: 根据您的 Jira Issue Type 来填写, 可能是:AlertSupportBugNew Feature等等或其他priority根据您的 Issue priority 来填写, 可能是:CriticalHighMediumLow等等或其他reopen_state: Jira 的问题已经关闭, 要重新打开, 需要的 transition, 如:Back to in progress. (注意: 这里需要填写的是您自定义的 transition, 而非 status)wont_fix_resolution: 带有这个 resolution (解决方案)的问题就不会重新打开. 如:Won't DoWon't Fix, 需要根据自己的 resolution 定义内容来填写.reopen_duration: 多久时间之内的问题会重新打开, 默认是always reopen, 可以设置为如:30d, 表示这个问题如果30天以前有同样的问题, 新开一个 Issue, 而不是重新打开老的 Issue.receivers: 可以定义多个 receivers, 指向不同projectproject: Jira 的 Project ID, 是 Project 详细名字的首字母大写. 如 Project 是For Example, 这里就填写FEadd_group_labels: 是否要将 AlertManager 的 Group Labels 加到 Jira 的 Labels. (注意: Jira Labels 的 Value 是不能有空格的, 所以如果你的 AlertManager 的 Group Label 的Value如果有空格, 不要开启此项功能)auto_resolve: 最新 1.2 版本新增的功能, 当告警恢复了, 可以自动 resolve 对应的 Jira Issue.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, 这往往是因为以下几种原因:
- Jiralert 中
reopen_state或auto_resolve的state没有填写正确的transition - 您用的账号没有相应的权限
- 该 Issue 现在所处的状态(比如
Closed)不允许再进行transition
具体可以参考这里: I can't transition an issue in my Jira project - W... - Atlassian Community
最终效果
如下图:

可以创建 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 编写.
使用Jiralert实现AlertManager告警对接Jira的更多相关文章
- 图文详解Prometheus监控+Grafana+Alertmanager告警安装使用
一:前言 一个服务上线了后,你想知道这个服务是否可用,需要监控.假如线上出故障了,你要先于顾客感知错误,你需要监控.还有对数据库,服务器的监控,等等各层面的监控. 近年来,微服务架构的流行,服务数越来 ...
- Prometheus学习笔记(6)Alertmanager告警
目录 一.Alertmanager简介 二.Alertmanager部署 三.Alertmanager配置 四.自定义告警规则和发送 五.自定义告警模板 一.Alertmanager简介 Promet ...
- Prometheus+alertmanager告警配置-2
prometheus 告警 prometheus 通过alertmanager进行告警 实现监控告警的步骤: 在prometheus中定义告警规则rule_files alertmanager配置告警 ...
- Docker+Prometheus+Alertmanager+Webhook钉钉告警
Docker+Prometheus+Alertmanager+Webhook钉钉告警 1.环境部署 1.1 二进制部署 1.2 docker部署 1.2.1 webhook 1.2.2 alertma ...
- Prometheus 监控报警系统 AlertManager 之邮件告警
转载自:https://cloud.tencent.com/developer/article/1486483 文章目录1.Prometheus & AlertManager 介绍2.环境.软 ...
- Istio on ACK集成生态(2): 扩展AlertManager集成钉钉助力可观测性监控能力
阿里云容器服务Kubernetes(简称ACK)支持一键部署Istio,可以参考文档在ACK上部署使用Isito.Istio on ACK提供了丰富的监控能力,为网格中的服务收集遥测数据,其中Mixe ...
- Jira与Confluence集成、授权信息查看和问题汇总
上一篇文章详细阐述了jira和confluence的安装部署和相关配置的操作记录,也介绍了两者之间其中一种集成方式:下面介绍另外的集成方式. 安装部署jira和confluence的顺序是,先安装ji ...
- Jira/Confluence的备份、恢复和迁移
之前的文章已经分别详细介绍了Jira.Confluence的安装及二者账号对接的操作方法,下面简单说下二者的备份.恢复和迁移: 一.Jira.Confluence的备份.恢复1)Confluence的 ...
- 基于Prometheus和Grafana的监控平台 - 运维告警
通过前面几篇文章我们搭建好了监控环境并且监控了服务器.数据库.应用,运维人员可以实时了解当前被监控对象的运行情况,但是他们不可能时时坐在电脑边上盯着DashBoard,这就需要一个告警功能,当服务器或 ...
- Prometheus(五):Prometheus+Alertmanager 配置企业微信报警
此处默认已安装Prometheus服务,服务地址:192.168.56.200 一.设置企业微信 1.1.企业微信注册(已有企业微信账号请跳过) 企业微信注册地址:https://work.weix ...
随机推荐
- 16.MongoDB系列之分片管理
1. 查看当前状态 1.1 查看配置信息 mongos> use config // 查看分片 mongos> db.shards.find() { "_id" : & ...
- 20220728 - DP训练 #1
20220728 - DP训练 #1 时间记录 \(8:00-9:00\) T1 尝试做 \(T1\),可惜并未做出,没有想到是资源分配 设置三维状态,初值一直不知道怎么设置 并且对于距离有一部分不会 ...
- .NET周报【10月第3期 2022-10-25】
国内文章 聊一聊被 .NET程序员 遗忘的 COM 组件 https://www.cnblogs.com/huangxincheng/p/16799234.html 将Windows编程中经典的COM ...
- 【pytest官方文档】解读- 开发可pip安装的第三方插件
在上一篇的 hooks 函数分享中,开发了一个本地插件示例,其实已经算是在编写插件了.今天继续跟着官方文档学习更多知识点. 一个插件包含一个或多个钩子函数,pytest 正是通过调用各种钩子组成的插件 ...
- G1 垃圾收集器深入剖析(图文超详解)
G1(Garbage First)垃圾收集器是目前垃圾回收技术最前沿的成果之一. G1 同 CMS 垃圾回收器一样,关注最小时延的垃圾回收器,适合大尺寸堆内存的垃圾收集.但是,G1 最大的特点是引入分 ...
- 试试将.NET7编译为WASM并在Docker上运行
之前有听到说Docker支持Wasmtime了,刚好.NET7也支持WASM,就带大家来了解一下这个东西,顺便试试它怎么样. 因为WASM(WebAssembly) 一开始是一个给浏览器的技术,比起J ...
- Go语言核心36讲17
在前面的文章中,我们已经提到过很多次"指针"了,你应该已经比较熟悉了.不过,我们那时大多指的是指针类型及其对应的指针值,今天我们讲的则是更为深入的内容. 让我们先来复习一下. ty ...
- YeserCMS
这道题直接让我们查网站根目录的flag,我首先想到的是一句话木马,但是奈何找不到上传的接口啊,只好作罢, 在下载发现有个cmseasy的标识,明显是要提示我们这里是easycms,百度easycms的 ...
- C++期末考试题库
哈尔滨商业大学计算机专业C++期末考试题库 下载:题库 示例: 一.单选题:1.能作为 C ++程序的基本单位是( C )A .字符 B .语句 C .函数 D .源程序文件2.程序中主函数的名字为( ...
- Centos安装Nodejs简单方式
Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时.本文主要讲的是如何在Linux即Centos上安装Nodejs的简单方式,有比设置环境变量更加简单的方式,那就是设 ...