Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlexGurtoff opened this issue Aug 20, 2024 · 2 comments
Open

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

AlexGurtoff opened this issue Aug 20, 2024 · 2 comments

Comments

@AlexGurtoff
Copy link

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
Copy link
Author

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
Copy link
Member

Fixed in #829 this PR will be included in Flux 2.4 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants