VictoriaMetrics/app/vmalert/notifier
Aliaksandr Valialkin df8ec22662
app/vmalert/templates: properly escape all the special chars in quotesEscape function
Previously the `quotesEscape` function was escaping only double quotes.
This wasn't enough, since the input string could contain other special chars,
which must be escaped when put inside JSON string. For example, carriage return and line feed chars (\n\r),
backslash char, etc. This led to the following issues, which were improperly fixed:

- https://github.com/VictoriaMetrics/VictoriaMetrics/issues/890 - this issue
  was "fixed" by introducing the `crlfEscape` function, which led to unnecessary
  complications in user templates, while not fixing various corner cases
  such as backslash chars in the input string.
  See 1de15ad490

- https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3139 - this issue
  was "fixed" by urlencoding the whole string passed to -external.alert.source
  command-line flag. This led to invalid urls, which couldn't be parsed by Grafana.
  See 00c838353d
  and 4bd0244599

This commit properly encodes the input string passed to `quotesEscape`, so it can be safely embedded inside JSON strings.

This commit deprecates crlfEscape template function and adds the following new template functions:

- strvalue and stripDomain - these functions are supported by Prometheus, so they were added
  for compatibility purposes.
- jsonEscape and htmlEscape for converting the input string to valid quoted JSON string
  and for html-escaping the input string, so it could be safely embedded as a plaintext
  into html.

This commit also documents all supported template functions at https://docs.victoriametrics.com/vmalert.html#template-functions
The deprecated crlfEscape function isn't documented on purpose, since its usefulness is negative in general case.
2022-11-07 14:41:44 +02:00
..
testdata vmalert: add DNS service discovery (#2465) 2022-04-13 14:14:25 +03:00
alert.go chore: remove duplicated code (#2657) 2022-05-30 12:27:47 +03:00
alert_test.go app/vmalert/templates: properly escape all the special chars in quotesEscape function 2022-11-07 14:41:44 +02:00
alertmanager.go lib/promauth: add ability to send additional http headers in requests to scrape targets 2022-06-22 20:40:50 +03:00
alertmanager_request.qtpl vmalert: support relabeling for alert labels sent via notifier 2022-04-11 12:12:04 +03:00
alertmanager_request.qtpl.go app/vmalert: run make quicktemplate-gen from the root directory after the commit f6dcfbcdd6 2022-05-04 20:28:37 +03:00
alertmanager_test.go vmalert: support relabeling for alert labels sent via notifier 2022-04-11 12:12:04 +03:00
config.go all: make fmt via the upcoming Go1.19 2022-07-11 19:23:25 +03:00
config_test.go vmalert: add DNS service discovery (#2465) 2022-04-13 14:14:25 +03:00
config_watcher.go fix alert relabeling (#2633) 2022-05-25 15:05:10 +03:00
config_watcher_test.go Consul SD - update services on the watcher's start (#2202) 2022-02-21 15:33:33 +02:00
init.go all: make fmt via the upcoming Go1.19 2022-07-11 19:23:25 +03:00
notifier.go vmalert: support configuration file for notifiers (#2127) 2022-02-02 23:42:25 +02:00
package_test.go added reusable templates support (#2532) 2022-05-20 12:25:11 +03:00