dadevel / alertmanager-signal-receiver

Signal Messenger Support for Prometheus Alertmanager
MIT License
22 stars 6 forks source link

Docker build is failing #9

Closed ghost closed 2 years ago

ghost commented 2 years ago

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

So I created the folder src then rerun the build

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'

I really don't understand why it can't locate the ./cmd/main.go even the file exist I tried to remove RUN go build and RUN strip then below error follows

Step 11/16 : COPY --from=signal-receiver /build/alertmanager-signal-receiver ./bin/ COPY failed: stat build/alertmanager-signal-receiver: file does not exist

ghost commented 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

ghost commented 2 years ago

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?

dadevel commented 2 years ago

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
dadevel commented 2 years ago

If the issue is not resolved feel free to comment again.

ghost commented 2 years ago

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?

dadevel commented 2 years ago

No that's currently not supported. But you could do something like this:

{{ if eq .Status "firing" }}
...
{{ end }}
{{ if eq .Status "resolved" }}
...
{{ end }}
ghost commented 2 years ago

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!

ghost commented 2 years ago

I also tried 'else' just in case:

{{ if eq .Status "firing" }} ... {{ end }} {{ else }} ... {{ end }}

But there is still a syntax error

dadevel commented 2 years ago

What's the error message?

ghost commented 2 years ago

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 }}`