Closed ghost closed 2 years ago
I was somehow able to make it work. But on the step 19 it can't find a certain file
Step 18/24 : COPY --from=signal-cli /build/signal-cli/lib/ ./lib/ ---> Using cache ---> 298943dbe998 Step 19/24 : COPY --from=signal-receiver /build/alertmanager-signal-receiver ./bin/ COPY failed: stat build/alertmanager-signal-receiver: file does not exist
BTW the only purpose why I'm building it locally is to change the message template, is there another way to do it without rebuilding the image?
Yes, that should be possible. For example:
export SIGNAL_RECEIVER_MESSAGE_TEMPLATE="$(cat << 'EOF'
{{ .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 }}
EOF
)"
docker run [...] -e SIGNAL_RECEIVER_MESSAGE_TEMPLATE ghcr.io/dadevel/signal-receiver
If the issue is not resolved feel free to comment again.
Awesome! that fixed it. Another question, is there a way to have a different template for FIRING and RESOLVED? I mean can I export 2 different message templates?
No that's currently not supported. But you could do something like this:
{{ if eq .Status "firing" }}
...
{{ end }}
{{ if eq .Status "resolved" }}
...
{{ end }}
Hi @dadevel , I tried your advise and got an error and it is probably a syntax error. Below is the defaults.go configuration:
package defaults
const ListenAddress = ":9709" const DataDir = "./data" const MessageTemplate = `{{ if eq .Status "firing" | ToUpper }} ALERT IS: {{ .AlertName }}{{ "\n" }} {{- if .Severity -}} SEVERITY: {{ .Severity | ToUpper }}{{ "\n" }} {{- end -}} {{- range $key, $value := .Annotations -}} {{ $key | ToLower }}: {{ $value }}{{ "\n" }} {{- end -}} {{- if .Summary -}} {{ "\n" }}{{ .Summary }} {{- end -}} {{- if .Description -}} {{ "\n" }}{{ .Description }} {{- end }}
{{ if eq .Status "resolved" | ToUpper}} ALERT IS: {{ .AlertName }}{{ "\n" }} {{- if .Severity -}} SEVERITY: {{ .Severity | ToUpper }}{{ "\n" }} {{- end -}} {{- range $key, $value := .Annotations -}} {{ $key | ToLower }}: {{ $value }}{{ "\n" }} {{- end -}} {{- if .Summary -}} {{ "\n" }}{{ .Summary }} {{- end -}} {{- if .Description -}} {{ "\n" }}{{ .Description }} {{- end }}`
I can't figured out where the error/s coming, hope you can help me with this. Thanks!
I also tried 'else' just in case:
{{ if eq .Status "firing" }} ... {{ end }} {{ else }} ... {{ end }}
But there is still a syntax error
What's the error message?
Hi @dadevel I have it working now. Thank you for your assistance!
cat defaults/defaults.go package defaults
const ListenAddress = ":9709" const DataDir = "./data" const MessageTemplate = `{{ if eq .Status "firing" -}}🔥🔥🔥 FIRING 🔥🔥🔥 {{ "\n" }} ALERT NAME: {{ .AlertName }}{{ "\n" }} {{- if .Severity -}} SEVERITY: {{ .Severity | ToUpper }}{{ "\n" }} {{- end -}} {{- range $key, $value := .Annotations -}} {{ $key | ToLower }}: {{ $value }}{{ "\n" }} {{- end -}} {{- if .Summary -}} {{ "\n" }}{{ .Summary }} {{- end -}} {{- if .Description -}} {{ "\n" }}{{ .Description }} {{- end -}} {{- end }}
{{ if eq .Status "resolved" -}}👍👍👍 RESOLVED 👍👍👍{{ "\n" }} ALERT NAME: {{ .AlertName }}{{ "\n" }} {{- if .Severity -}} SEVERITY: {{ .Severity | ToUpper }}{{ "\n" }} {{- end -}} {{- range $key, $value := .Annotations -}} {{ $key | ToLower }}: {{ $value }}{{ "\n" }} {{- end -}} {{- if .Summary -}} {{ "\n" }}{{ .Summary }} {{- end -}} {{- if .Description -}} {{ "\n" }}{{ .Description }} {{- end -}} {{- end }}`
Hi,
Hope you can assist me on building the image, I've been running lots of error when building the Dockerfile you provided here: https://github.com/dadevel/dockerfiles/blob/main/signal-receiver/Dockerfile
alertmanager-signal-receiver$ docker build . -t test:signal
Step 6/18 : COPY ./src . COPY failed: file not found in build context or excluded by .dockerignore: stat src: file does not exist
Step 7/18 : RUN go build -o ./alertmanager-signal-receiver ./cmd/main.go ---> Running in f90c8088ebe7 go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Step 11/16 : COPY --from=signal-receiver /build/alertmanager-signal-receiver ./bin/ COPY failed: stat build/alertmanager-signal-receiver: file does not exist