VictoriaMetrics/app/vmalert/notifier
Aliaksandr Valialkin a018b1d75e
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-10-28 00:01:16 +03:00
..
testdata vmalert: support auth configs per static_target (#3188) 2022-09-30 17:10:17 +02:00
alert_test.go app/vmalert/templates: properly escape all the special chars in quotesEscape function 2022-10-28 00:01:16 +03:00
alert.go lib/promrelabel: remove unconditional sorting of the labels in ParsedConfigs.Apply(), since the sorting isnt needed in many places 2022-10-09 14:51:16 +03:00
alertmanager_request.qtpl fix issue#3053 (#3182) 2022-10-10 09:44:58 +02:00
alertmanager_request.qtpl.go vmalert: revert unexpected fileds rename during refactoring (#3222) 2022-10-11 12:37:47 +02:00
alertmanager_test.go fix issue#3053 (#3182) 2022-10-10 09:44:58 +02:00
alertmanager.go all: subsitute ioutil.ReadAll with io.ReadAll 2022-08-22 00:16:37 +03:00
config_test.go vmalert: add DNS service discovery (#2465) 2022-04-13 11:50:26 +03:00
config_watcher_test.go vmalert: support auth configs per static_target (#3188) 2022-09-30 17:10:17 +02:00
config_watcher.go vmalert: support auth configs per static_target (#3188) 2022-09-30 17:10:17 +02:00
config.go lib/promrelabel: remove unconditional sorting of the labels in ParsedConfigs.Apply(), since the sorting isnt needed in many places 2022-10-09 14:51:16 +03:00
init.go lib/flagutil: rename Array to ArrayString 2022-10-01 18:26:36 +03:00
notifier.go vmalert: support configuration file for notifiers (#2127) 2022-02-02 14:11:41 +02:00
package_test.go added reusable templates support (#2532) 2022-05-14 11:38:44 +02:00