I am using Prometheus Alertmanager integration with Jiralert go tool to create tasks out of alerts in Jira.
Everything works as expected aside from the fact that I don’t know how to inherit severity from the current alert. I am hard-coding a value at this point. I have tried to get the value from .Labels (which is get successfully during template, but not if I call it from config yaml.
# Content of jiralert.yaml
# Global defaults, applied to all receivers where not explicitly overridden. Optional.
defaults:
# API access fields.
api_url: https://test.atlassian.net
user: 'as@test.com'
password: 'randompassword'
# The type of JIRA issue to create. Required.
issue_type: Alert
# Issue priority. Optional.
#priority: Low
# 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: "To Do"
# 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: 0h
# Receiver definitions. At least one must be defined.
receivers:
# Non-prod cluster for testing
- name: 'prometheus-test-non-production'
# JIRA project to create the issue in. Required.
summary: '{{ template "jira.testenv.summary" . }}'
description: '{{ template "jira.testenv.description" . }}'
project: AS
# Copy all Prometheus labels into separate JIRA labels. Optional (default: false).
add_group_labels: false
fields:
customfield_10600: { "value": '{{ template ".Alerts.Front().Labels.severity.Value" }}' }
template: jiralert_v2.tmpl
# jiralert_v2.tmpl
{{ define "jira.summary" }}{{end}}
{{ define "jira.description" }}{{end}}
{{ define "jira.testenv.summary" }}[Prometheus][K8s/testenv-ops][{{ .Status | toUpper }}{{- if eq .Status "firing" -}}:{{- .Alerts.Firing | len -}}{{- end -}}]{{ .CommonLabels.alertname }} for {{ .CommonLabels.job }}{{- end }}{{- if gt (len .CommonLabels) (len .GroupLabels) -}}{{" "}}({{- with .CommonLabels.Remove .GroupLabels.Names }}{{- range $index, $label := .SortedPairs -}}{{ if $index }}, {{ end }}{{- $label.Name }}="{{ $label.Value -}}"{{- end }}{{- end -}}){{- end }}
{{ define "jira.testenv.description" }}
{{ with index .Alerts 0 -}}
*URL: <{{ .GeneratorURL }}>*
{{- if .Annotations.runbook }} :notebook: *<{{ .Annotations.runbook }}|Runbook>*{{ end }}
{{ end }}
Kubernetes Cluster: testenv-ops
Prometheus Alert Details:
{{ range .Alerts}}
* Alert Labels:
{{ range .Labels.SortedPairs }} ** {{ .Name }}: {{ .Value }}
{{ end }}
* Alert Description: {{ .Annotations.message }}
{{ end }}
{{- end }}
Go to Source
Author: anVzdGFub3RoZXJodW1hbg