-
Notifications
You must be signed in to change notification settings - Fork 132
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
jiralert: Improved docs and config. #32
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -52,9 +52,19 @@ $ curl -H "Content-type: application/json" -X POST \ | |||||
|
||||||
## Configuration | ||||||
|
||||||
The configuration file is essentially a list of receivers matching 1-to-1 all Alertmanager receivers using JIRAlert; plus defaults (in the form of a partially defined receiver); and a pointer to the template file. | ||||||
The configuration file is essentially a list of JiraAlert receivers plus defaults (in the form of a partially defined receiver); and a pointer to the template file. | ||||||
|
||||||
Each receiver must have a unique name (matching the Alertmanager receiver name), JIRA API access fields (URL, username and password), a handful of required issue fields (such as the JIRA project and issue summary), some optional issue fields (e.g. priority) and a `fields` map for other (standard or custom) JIRA fields. Most of these may use [Go templating](https://golang.org/pkg/text/template/) to generate the actual field values based on the contents of the Alertmanager notification. The exact same data structures and functions as those defined in the [Alertmanager template reference](https://prometheus.io/docs/alerting/notifications/) are available in JIRAlert. | ||||||
You can find more docs in [the configuration itself](/pkg/config/config.go) | ||||||
|
||||||
Each receiver must have: | ||||||
* a unique name (matching the Alertmanager receiver name) | ||||||
* JIRA API access fields (URL, username and password), | ||||||
* handful of required issue fields (such as the JIRA project and issue summary), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* some optional issue fields (e.g. priority) and a `fields` map for other (standard or custom) JIRA fields. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Most of these may use [Go templating](https://golang.org/pkg/text/template/) to generate the actual field values based on the contents of the Alertmanager notification. | ||||||
|
||||||
The exact same data structures and functions as those defined in the [Alertmanager template reference](https://prometheus.io/docs/alerting/notifications/) are available in JIRAlert. | ||||||
|
||||||
## Alertmanager configuration | ||||||
|
||||||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -74,31 +74,52 @@ func resolveFilepaths(baseDir string, cfg *Config, logger log.Logger) { | |||||||||||
cfg.Template = join(cfg.Template) | ||||||||||||
} | ||||||||||||
|
||||||||||||
// ReceiverConfig is the configuration for one receiver. It has a unique name and includes API access fields (URL, user | ||||||||||||
// and password) and issue fields (required -- e.g. project, issue type -- and optional -- e.g. priority). | ||||||||||||
// ReceiverConfig is the configuration for one receiver. | ||||||||||||
type ReceiverConfig struct { | ||||||||||||
// Name represents unique name for a receiver. | ||||||||||||
// If Iiralert is used with Alertmanager, name it as Alertmanager receiver that sends alert via webhook to Jiralert for | ||||||||||||
// desired propagation. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd replace all this with // Name is a unique receiver name. It must match an Alertmanager receiver name. Required. |
||||||||||||
Name string `yaml:"name" json:"name"` | ||||||||||||
|
||||||||||||
// API access fields | ||||||||||||
// APIURL specifies API URL for JIRA e.g https://<your org>.atlassian.net. | ||||||||||||
// Required. | ||||||||||||
APIURL string `yaml:"api_url" json:"api_url"` | ||||||||||||
// User specifies user to pass in basicauth against JIRA. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
User string `yaml:"user" json:"user"` | ||||||||||||
// Password specifies password in baiscauth against JIRA. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
Password Secret `yaml:"password" json:"password"` | ||||||||||||
|
||||||||||||
// Required issue fields | ||||||||||||
// Required issue fields. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this actually create a heading or something like that in the documentation? Or will it be ignored? If the latter, then I'd rather add required/optional notes to every field separately. |
||||||||||||
|
||||||||||||
// Projects specifies in what project within org to create/reopen JIRA issues. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
Project string `yaml:"project" json:"project"` | ||||||||||||
// IssueType specifies what type of the issue to use for new JIRA issues. | ||||||||||||
IssueType string `yaml:"issue_type" json:"issue_type"` | ||||||||||||
// Summary specifies Golang template invocation for generating the issue summary. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
Summary string `yaml:"summary" json:"summary"` | ||||||||||||
// ReopenState specifies the state to transition into when reopening a closed issue. | ||||||||||||
// This state has to exists for the chosen project. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
ReopenState string `yaml:"reopen_state" json:"reopen_state"` | ||||||||||||
// ReopenDuration specifies the time after being closed that an issue should be reopened, after which, | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
// a new issue is created instead. Set to large value if you always want to reopen. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
ReopenDuration *Duration `yaml:"reopen_duration" json:"reopen_duration"` | ||||||||||||
|
||||||||||||
// Optional issue fields. | ||||||||||||
|
||||||||||||
// Optional issue fields | ||||||||||||
// Priority represents issue priority. | ||||||||||||
Priority string `yaml:"priority" json:"priority"` | ||||||||||||
// Description specifies Golang template invocation for generating the issue description. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
Description string `yaml:"description" json:"description"` | ||||||||||||
// WontFixResolution specifies to not reopen issues with this resolution. Useful for silencing alerts. | ||||||||||||
WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"` | ||||||||||||
// Fields specifies standard or custom field values to set on created issue. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
// | ||||||||||||
// See https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#setting-custom-field-data-for-other-field-types for further examples. | ||||||||||||
Fields map[string]interface{} `yaml:"fields" json:"fields"` | ||||||||||||
// Components specifies issue components. Sometimes required, depending on JIRA project. | ||||||||||||
Components []string `yaml:"components" json:"components"` | ||||||||||||
ReopenDuration *Duration `yaml:"reopen_duration" json:"reopen_duration"` | ||||||||||||
|
||||||||||||
// Label copy settings | ||||||||||||
// AddGroupLabels specifies if all Prometheus labels should be copied into separate JIRA labels. | ||||||||||||
// Default: false. | ||||||||||||
AddGroupLabels bool `yaml:"add_group_labels" json:"add_group_labels"` | ||||||||||||
|
||||||||||||
// Catches all undefined fields and must be empty after parsing. | ||||||||||||
|
@@ -123,8 +144,13 @@ func (rc *ReceiverConfig) UnmarshalYAML(unmarshal func(interface{}) error) error | |||||||||||
|
||||||||||||
// Config is the top-level configuration for JIRAlert's config file. | ||||||||||||
type Config struct { | ||||||||||||
// Default specifies default values to be used in place of any ReceiverConfig' empty field. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
Defaults *ReceiverConfig `yaml:"defaults,omitempty" json:"defaults,omitempty"` | ||||||||||||
|
||||||||||||
// Receivers contains configuration per each receiver. | ||||||||||||
Receivers []*ReceiverConfig `yaml:"receivers,omitempty" json:"receivers,omitempty"` | ||||||||||||
|
||||||||||||
// Template specifies an optional file with template definitions. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have an issue with defaulting to no template file: with no templating, JIRAlert will always create identical JIRA tickets (except the label, but that's not even intended for human consumption). Why would anyone want that at all? Much less as default behavior? (I know about the deployment issue someone brought up, but I have a hard time believing there exists a widely used deployment tool that trips up on Golang templates and provides no workaround for that. What if the binary contains Golang templates as strings?) |
||||||||||||
Template string `yaml:"template" json:"template"` | ||||||||||||
|
||||||||||||
// Catches all undefined fields and must be empty after parsing. | ||||||||||||
|
@@ -232,10 +258,6 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||||||||||
return fmt.Errorf("no receivers defined") | ||||||||||||
} | ||||||||||||
|
||||||||||||
if c.Template == "" { | ||||||||||||
return fmt.Errorf("missing template file") | ||||||||||||
} | ||||||||||||
|
||||||||||||
return checkOverflow(c.XXX, "config") | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,13 +32,19 @@ var funcs = template.FuncMap{ | |||||
} | ||||||
|
||||||
// LoadTemplate reads and parses all templates defined in the given file and constructs a jiralert.Template. | ||||||
// If file is empty, or no file is passed, empty file template is returned. | ||||||
func LoadTemplate(path string, logger log.Logger) (*Template, error) { | ||||||
level.Debug(logger).Log("msg", "loading templates", "path", path) | ||||||
tmpl, err := template.New("").Option("missingkey=zero").Funcs(funcs).ParseFiles(path) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
if len(path) > 0 { | ||||||
level.Debug(logger).Log("msg", "loading templates", "path", path) | ||||||
tmpl, err := template.New("").Option("missingkey=zero").Funcs(funcs).ParseFiles(path) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
return &Template{tmpl: tmpl}, nil | ||||||
} | ||||||
return &Template{tmpl: tmpl}, nil | ||||||
|
||||||
level.Info(logger).Log("msg", "no template was passed.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return &Template{tmpl: template.New("")}, nil | ||||||
} | ||||||
|
||||||
func (t *Template) Err() error { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.