i am struggling to create a custom subject when receiving alerts from my AlertManager, i am doing it with manifest file:
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: my-name
labels:
alertmanagerConfig: email
alertconfig: email-config
spec:
route:
groupBy:
- node
groupWait: 30s
groupInterval: 5m
repeatInterval: 12h
receiver: 'myReceiver'
receivers:
- name: 'Name'
emailConfigs:
- to: [email protected]
i have read that i need to add headers under the emailConfigs tab, but when i do like follows:
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: my-name
labels:
alertmanagerConfig: email
alertconfig: email-config
spec:
route:
groupBy:
- node
groupWait: 30s
groupInterval: 5m
repeatInterval: 12h
receiver: 'myReceiver'
receivers:
- name: 'Name'
emailConfigs:
- to: [email protected]
headers:
- subject: "MyTestSubject"
or
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: my-name
labels:
alertmanagerConfig: email
alertconfig: email-config
spec:
route:
groupBy:
- node
groupWait: 30s
groupInterval: 5m
repeatInterval: 12h
receiver: 'myReceiver'
receivers:
- name: 'Name'
emailConfigs:
- to: [email protected]
headers:
subject: "MyTestSubject"
I receive following errors:
either:
com.coreos.monitoring.v1alpha1.AlertmanagerConfig.spec.receivers.emailConfigs.headers, ValidationError(AlertmanagerConfig.spec.receivers[0].emailConfigs[0].headers[0]): missing required field "key" in com.coreos.monitoring.v1alpha1.AlertmanagerConfig.spec.receivers.emailConfigs.headers, ValidationError(AlertmanagerConfig.spec.receivers[0].emailConfigs[0].headers[0]): missing required field "value" in com.coreos.monitoring.v1alpha1.AlertmanagerConfig.spec.receivers.emailConfigs.headers];
or
error: error validating "alert-config.yaml": error validating data: ValidationError(AlertmanagerConfig.spec.receivers[0].emailConfigs[0].headers): invalid type for com.coreos.monitoring.v1alpha1.AlertmanagerConfig.spec.receivers.emailConfigs.headers: got "map", expected "array"
am i doing something wrong or? Please can you help me, i read this in official alertmangger documentation, from there i saw the headers map i need, i have checked other solutions and everyone is doing it like
headers:
subject: mySubject
but for some reason to me, it doesn't work
CodePudding user response:
Hi @Blackcat from this example I found that you might need to use Catipal 'S' for the subject under headers looks like we need to use first letter capital for the keys under headers like mentioned below.
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: my-name
labels:
alertmanagerConfig: email
alertconfig: email-config
spec:
route:
groupBy:
- node
groupWait: 30s
groupInterval: 5m
repeatInterval: 12h
receiver: 'myReceiver'
receivers:
- name: 'Name'
emailConfigs:
- to: [email protected]
headers:
Subject: "MyTestSubject"
From: Me
To: You
For more detailed information check this link
CodePudding user response:
I managed to get it working:
emailConfigs:
- to: myreceiver@mail
headers:
- key: subject
value: "Custom subject goes here"
cheers :)