ToB企服应用市场:ToB评测及商务社交产业平台

标题: 使用Jiralert实现AlertManager告警对接Jira [打印本页]

作者: 伤心客    时间: 2023-1-4 13:17
标题: 使用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 组成。典型示例如下:
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4.   name: jiralert
  5. spec:
  6.   selector:
  7.     matchLabels:
  8.       app: jiralert
  9.   template:
  10.     metadata:
  11.       labels:
  12.         app: jiralert
  13.     spec:
  14.       containers:
  15.       - name: jiralert
  16.         image: quay.io/jiralert/jiralert-linux-amd64:latest
  17.         imagePullPolicy: IfNotPresent
  18.         args:
  19.         - "--config=/jiralert-config/jiralert.yml"
  20.         - "--log.level=debug"
  21.         - "--listen-address=:9097"
  22.         readinessProbe:
  23.           tcpSocket:
  24.             port: 9097
  25.           initialDelaySeconds: 15
  26.           periodSeconds: 15
  27.           timeoutSeconds: 5
  28.         livenessProbe:
  29.           tcpSocket:
  30.             port: 9097
  31.           initialDelaySeconds: 15
  32.           periodSeconds: 15
  33.           timeoutSeconds: 5
  34.         ports:
  35.         - containerPort: 9091
  36.           name: metrics
  37.         volumeMounts:
  38.         - mountPath: /jiralert-config
  39.           name: jiralert-config
  40.           readOnly: true
  41.       volumes:
  42.       - name: jiralert-config
  43.         secret:
  44.           secretName: jiralert-config
  45. ---
  46. apiVersion: v1
  47. kind: Secret
  48. type: Opaque
  49. metadata:
  50.   name: jiralert-config
  51. stringData:
  52.   jiralert.tmpl: |-
  53.     {{ define "jira.summary" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join "," }}{{ end }}
  54.    
  55.     {{ define "jira.description" }}{{ range .Alerts.Firing }}Labels:
  56.     {{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
  57.     {{ end }}
  58.    
  59.     Annotations:
  60.     {{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
  61.     {{ end }}
  62.    
  63.     Source: {{ .GeneratorURL }}
  64.     {{ end }}
  65.    
  66.     CommonLabels:
  67.     {{ range .CommonLabels.SortedPairs }} - {{ .Name }} = {{ .Value}}
  68.     {{ end }}
  69.    
  70.     GroupLabels:
  71.     {{ range .GroupLabels.SortedPairs }} - {{ .Name }} = {{ .Value}}
  72.     {{ end }}
  73.     {{ end }}
  74.   jiralert.yml: |-
  75.     # Global defaults, applied to all receivers where not explicitly overridden. Optional.
  76.     template: jiralert.tmpl
  77.     defaults:
  78.       # API access fields.
  79.       api_url: https://jira.example.com
  80.       user: foo
  81.       password: bar
  82.       # The type of JIRA issue to create. Required.
  83.       issue_type: Bug
  84.       # Issue priority. Optional.
  85.       priority: Major
  86.       # Go template invocation for generating the summary. Required.
  87.       summary: '{{ template "jira.summary" . }}'
  88.       # Go template invocation for generating the description. Optional.
  89.       description: '{{ template "jira.description" . }}'
  90.       # State to transition into when reopening a closed issue. Required.
  91.       reopen_state: "REOPENED"
  92.       # Do not reopen issues with this resolution. Optional.
  93.       wont_fix_resolution: "Won't Fix"
  94.       # Amount of time after being closed that an issue should be reopened, after which, a new issue is created.
  95.       # Optional (default: always reopen)
  96.       # reopen_duration: 30d
  97.    
  98.     # Receiver definitions. At least one must be defined.
  99.     # Receiver names must match the Alertmanager receiver names. Required.
  100.     receivers:
  101.     - name: 'jiralert'
  102.       project: 'YOUR-JIRA-PROJECT'
  103. ---
  104. apiVersion: v1
  105. kind: Service
  106. metadata:
  107.   name: jiralert
  108. spec:
  109.   selector:
  110.     app: jiralert
  111.   ports:
  112.   - port: 9097
  113.     targetPort: 9097               
复制代码
相应 AlertManager 的配置:
  1. ...
  2. receivers:
  3. - name: jiralert
  4.   webhook_configs:
  5.   - send_resolved: true
  6.     url: http://jiralert:9097/alert
  7. routes:
  8. - receiver: jiralert
  9.   matchers:
  10.   - severity = critical
  11.   continue: true
  12. ...
复制代码

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4