Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 Bad request, String value is not support for Custom Field #179

Open
RasheedJad opened this issue Oct 23, 2023 · 0 comments
Open

400 Bad request, String value is not support for Custom Field #179

RasheedJad opened this issue Oct 23, 2023 · 0 comments

Comments

@RasheedJad
Copy link

RasheedJad commented Oct 23, 2023

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant