fluxcd / notification-controller

The GitOps Toolkit event forwarder and notification dispatcher
https://fluxcd.io
Apache License 2.0
150 stars 132 forks source link

Telegram Alerts failed with can't parse entities error #910

Open AlexGurtoff opened 3 weeks ago

AlexGurtoff commented 3 weeks ago

My actual Alert manifest:

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
  name: helmrelease-status
  namespace: flux-system
spec:
  providerRef:
    name: telegram
  eventSeverity: info
  eventSources:
    - kind: HelmRelease
      name: "*"
      namespace: somenamespace

But when it comes to sending an alert, I see an error in the logs:

{"level":"error","ts":"2024-08-20T14:28:35.559Z","logger":"event-server","msg":"failed to send notification","eventInvolvedObject":{"kind":"HelmRelease","namespace":"somenamespace","name":"blabla-some-service","uid":"567941c5-b3c2-495e-bc9a-0b70b84d832d","apiVersion":"helm.toolkit.fluxcd.io/v2","resourceVersion":"5585528"},"Alert":{"name":"helmrelease-status","namespace":"flux-system"},"error":"Bad Request: can't parse entities: Character '-' is reserved and must be escaped with the preceding '\\'"}

I see such code that must handle it in telegram.go

// The telegram API requires that some special characters are escaped
// in the message string. Docs: https://core.telegram.org/bots/api#formatting-options.
func escapeString(str string) string {
    chars := "\\.-_[]()~>`#+=|{}!*"
    for _, char := range chars {
        start := 0
        idx := 0
        for start < len(str) && idx != -1 {
            idx = strings.IndexRune(str[start:], char)
            if idx != -1 {
                newIdx := start + idx
                str = str[:newIdx] + `\` + str[newIdx:]
                start = newIdx + 2
            }
        }
    }

    return str
}

So why isn't it working for me? What am I missing? I would be grateful for any help

AlexGurtoff commented 3 weeks ago

UPD: I don't know why, but when I rebuilt the docker image locally from my laptop on the main branch and changed the image for the notification controller - it starts working. So the 1.3.0 release doesn't work for me, but the last commit on the main branch is fine. Mythic

stefanprodan commented 3 weeks ago

Fixed in https://github.com/fluxcd/notification-controller/pull/829 this PR will be included in Flux 2.4 release.