Closed spammads closed 2 years ago
Not sure what's going wrong there, maybe try a minimal example like {{ .Summary }}
first.
From the syntax in your example, I assume that your using docker-compose. You could try this:
signal-receiver:
image: ghcr.io/dadevel/signal-receiver
environment:
SIGNAL_RECEIVER_MESSAGE_TEMPLATE: |
{{ .Status | ToUpper }}
{{ .AlertName }}
{{ if .Instance -}}
instance: {{ .Instance }}{{ "\n" }}
{{- end -}}
{{- if .Severity -}}
severity: {{ .Severity }}{{ "\n" }}
{{- end -}}
{{- range $key, $value := .Labels -}}
{{ $key | ToLower }}: {{ $value }}{{ "\n" }}
{{- end -}}
{{- range $key, $value := .Annotations -}}
{{ $key | ToLower }}: {{ $value }}{{ "\n" }}
{{- end -}}
{{- if .Summary -}}
{{ "\n" }}{{ .Summary }}
{{- end -}}
{{- if .Description -}}
{{ "\n" }}{{ .Description }}
{{- end }}
Thanks for taking your time.
I am using docker swarm with a stack file.
Tried your minimal example and got:
failed to update service signalreceiver_app: Error response from daemon: rpc error: code = InvalidArgument desc = expanding env failed: expanding env "SIGNAL_RECEIVER_MESSAGE_TEMPLATE={{ .Status }}\n": template: expansion:1:3: executing "expansion" at <.Status>: can't evaluate field Status in type *template.Context
You got any idea what else I could try? Thanks. Best regards.
I verified that specifying the environment variable SIGNAL_RECEIVER_MESSAGE_TEMPLATE={{ .Status }}
works as expected, so I think it has to do something with your setup.
Maybe try this steps:
entrypoint: env
and check the container logs to see if the env var has the expected value.docker run
and -e 'SIGNAL_RECEIVER_MESSAGE_TEMPLATE={{ .Status }}'
and see if that works.Tried your first suggestion. No luck.
I think the problem is, that Docker Swarm uses Go-Templating for Service-Creation: https://docs.docker.com/engine/reference/commandline/service_create/#create-services-using-templates
When I start your container with:
SIGNAL_RECEIVER_MESSAGE_TEMPLATE={{ .Service.ID }}
the creation succeeds & I get no error message.
But of course the template does use the swarm-variable instead of the correct variable coming from the alert.
Any idea how to overcome this swarm-parsing?
Ah, that makes sense. I never used Docker Swarm, but maybe if you use env_file instead of environment?
Hey @CKranebitter did you found a solution?
Still working on it as docker swarm prohibits the use of env_file
Ah, alright. Didn't know that. Than I'll keep this open for now.
Thanks for the Webhook. Works very well for my businesscase. But I am not able to get the Message Templating to work. I pass:
- SIGNAL_RECEIVER_MESSAGE_TEMPLATE=
{{- if .Summary -}}{{ "\n" }}{{ .Summary }}{{- end -}}{{- if .Description -}}{{ "\n" }}{{ .Description }}{{- end }}``but service replies with:
template: expansion:1:8: executing "expansion" at <.Summary>: can't evaluate field Summary in type *template.Context
Can you advise a bit how to correctly set the environment variable? Any advice appreciated. Thanks!