Description
Hi recently we started using jiralert, and we faced an issue with the numaric custom field to set its value from a PrometheusRule which contains an alert that have a label called "severity_num" in labels section.
So the secnario is like following:
PrometheusRule -> Alertmanager openshift -> Jiralert -> Jira.
Well jiralert keeps sending back 400 Bad request, String value is not support. I tried to find a way to convert the String to INT but thats require a modification in source code and create a method there so that can be used in "jiralert.tmpl".
Here are the configurations and the prometheusRule:
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: infra-jiralert
spec:
groups:
- name: infra-jiralert
rules:
- alert: VM memory test alert
expr: vm_memory_heap_usage > 0
labels: // severity_num only allowed to be strings
severity: critical
severity_num: "300"
channel: jira-cloud
alert_receiver: area-cloud
cluster: STR02
annotations:
description: 'VM memory test alert'
summary: "VM memory test alert"
jiralert.tmpl
{{ define "jira.summary" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join "," }}{{ end }}
{{ define "jira.priority" }}
{{- range .Alerts.Firing -}}
{{- range .Labels.SortedPairs -}}
{{- if eq .Name "severity" -}}
{{ if eq .Value "critical" }}Critical{{ else }}Minor{{ end }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{ define "jira.severity" }}
{{- range .Alerts.Firing -}}
{{- range .Labels.SortedPairs -}}
{{ if eq .Name "severity_num" }}{{ .Value }}{{ end }}
{{- end -}}
{{- end -}}
{{- 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
defaults:
api_url: $(JIRA_API)
user: $(JIRA_USER)
password: $(JIRA_PASS)
issue_type: Incident
priority: '{{ template "jira.priority" . }}'
summary: '{{ template "jira.summary" . }}'
description: '{{ template "jira.description" . }}'
reopen_state: "To Do"
wont_fix_resolution: "Won't Fix"
reopen_duration: 0h
receivers:
- name: "jira-cloud"
project: "CLI"
fields:
customfield_11170: '{{ template "jira.severity" . }}'
auto_resolve:
state: "Done"