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

cmd/Bosun: support / in lookup sections #1297

Merged
merged 1 commit into from
Sep 3, 2015
Merged

cmd/Bosun: support / in lookup sections #1297

merged 1 commit into from
Sep 3, 2015

Conversation

giganteous
Copy link
Contributor

With regards to the os.diskspace alert, I like to write my exceptions for disks like this:

lookup disk_space {
    entry host=netlog,disk=/data {
        warn_percent_free = 5
        crit_percent_free = 0
    }
    entry host=*,disk=* {
        warn_percent_free = 10
        crit_percent_free = 0
    }
}

Currently this gives an error: "unexpected invalid character: / in section declaration", this change should remove the bug.

Thanks,

captncraig pushed a commit that referenced this pull request Sep 3, 2015
cmd/Bosun: support / in lookup sections
@captncraig captncraig merged commit f11e6f4 into bosun-monitor:master Sep 3, 2015
@giganteous giganteous deleted the add-slash-to-parse branch September 3, 2015 18:37
mvuets pushed a commit to bookingcom/bosun that referenced this pull request Apr 18, 2018
In this commit I try to partly address an issue raised in the report bosun-monitor#1297:
I want to generate a JSON on `actionBodyAck` and send it to an HTTP API.
One of the fields in the JSON payload should contain a message attached
to the performed action and also a list of ids of affected incidents,
e.g.: "User X acknowledged N incidents (ids: 1, 2, 4) with a note: M".
I need to use `makeMap` and `json` functions, which take a "pipeline"
in Go's terms, to build a properly encoded JSON; but I also need a
way to traverse `.States[]` and extract a list of ids in a form of a
"pipeline". I could traverse with a help of the `{{range}}` template
action, but there is no way I can capture the result of that execution.

This patch adds a template function `execTmpl` which executes given Go
text/template provided a data structure and returns a resulting string
which can be kept in a template variable or passed on through the
template pipeline. Another way of looking at it is in-line or
sub-templates.

    {{- $list := execTmpl "{{range .}}<li>{{.Id}}</li>\n{{end}}" .States -}}
    {{- $html := printf "%v<br/>Affected incidents:<ul>%v</ul>" .Message $list -}}
    {{- makeMap "message" $html | json -}}

At first I wanted to take advantage of Go's named sub-templates
(`{{define NAME}}...`) and pass that NAME to `execTmpl` instead of a
literal template. Unfortunately template functions do not get a context
of a template in which they are being invoked, therefore I did not have
an access to the parent template containing sub-templates. I could wrap
it in a closure, but there are too many text/template instances created
in different places in code, so I figured that I will give the current
approach a go first and see how is it accepted.
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

Successfully merging this pull request may close these issues.

2 participants