这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Conversation

@mvuets
Copy link
Contributor

@mvuets mvuets commented May 23, 2018

Follow-up on #2197 and #2243.

jsonStr template function is a new better version of its ancestor
.RemoveQuotes. The .RemoveQuotes helper is a temporary patch that helps
to sanitise data in order to use it inside JSON string literals.
Unfortunately it does not handle all characters (e.g. \n) but only
", so at times resulting JSON documents still would be malformed. That
results in failure to deliver notifications.

The new version "jsonStr" works just like "json", but it cuts front and
rear double quotes off. So now one can include any template rubbish
inside JSON string literal and worry about breaking JSON not:

alert A {
    $Rubbish= `say "hi '\xyz'!\n" &
        jump <sup>high</sup>`
    ...
}

template T {
    jabberAlertBody = `{
        "text": "hello {{ .Alert.Vars.Rubbish | jsonStr }}!"
    }`
    ...
}

jsonStr template function is a new better version of its ancestor
.RemoveQuotes. The .RemoveQuotes helper is a temporary patch that helps
to sanitise data in order to use it inside JSON string literals.
Unfortunately it does not handle all characters (e.g. `\n`) but only
`"`, so at times resulting JSON documents still would be malformed. That
results in failure to deliver notifications.

The new version "jsonStr" works just like "json", but it cuts front and
rear double quotes off. So now one can include any template rubbish
*inside* JSON string literal and worry about breaking JSON not:

    alert A {
        $Rubbish= `say "hi '\xyz'!\n" &
            jump <sup>high</sup>`
        ...
    }

    template T {
        jabberAlertBody = `{
            "text": "hello {{ .Alert.Vars.Rubbish | jsonStr }}!"
        }`
        ...
    }
@stepashka
Copy link

Hey @kylebrandt, @captncraig!
Any objections to this change? Is there something else we need to implement before this gets merged?
Thanks,
Anna

@kylebrandt
Copy link
Member

@stepashka / @mvuets I've really wanted more of an object based approach for building json notifications, I believe the main blocker to that was the lack of in-block assignment, but now go1.11 has that.

For example the following POC code and sample config exposes append to templates: #2320

@kylebrandt
Copy link
Member

closing in favor of constructing objects now with append and inblock assignment supported in the templates.

@kylebrandt kylebrandt closed this Jan 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants