Skip to content

Commit

Permalink
Merge pull request #2 from taktv6/master
Browse files Browse the repository at this point in the history
Added config options for JIRA components + prom labels as JIRA labels
  • Loading branch information
free authored Mar 16, 2018
2 parents 546ee64 + 293692d commit a620252
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ type ReceiverConfig struct {
Description string `yaml:"description" json:"description"`
WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"`
Fields map[string]interface{} `yaml:"fields" json:"fields"`
Components []string `yaml:"components" json:"components"`

// Label copy settings
AddGroupLabels bool `yaml:"add_group_labels" json:"add_group_labels"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
Expand Down
4 changes: 4 additions & 0 deletions config/jiralert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ receivers:
- name: 'jira-ab'
# JIRA project to create the issue in. Required.
project: AB
# Copy all Prometheus labels into separate JIRA labels.
add_group_labels: false

- name: 'jira-xy'
project: XY
issue_type: Task
# JIRA components. Optional.
components: [ 'Operations' ]
# Standard or custom field values to set on created issue. Optional.
fields:
foo: bar
Expand Down
14 changes: 14 additions & 0 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func (r *Receiver) Notify(data *alertmanager.Data) (bool, error) {
if r.conf.Priority != "" {
issue.Fields.Priority = &jira.Priority{Name: r.tmpl.Execute(r.conf.Priority, data)}
}

// Add Components
issue.Fields.Components = make([]*jira.Component, 0, len(r.conf.Components))
for _, component := range r.conf.Components {
issue.Fields.Components = append(issue.Fields.Components, &jira.Component{Name: component})
}

// Add Labels
if r.conf.AddGroupLabels {
for k, v := range data.GroupLabels {
issue.Fields.Labels = append(issue.Fields.Labels, fmt.Sprintf("%s=%q", k, v))
}
}

for key, value := range r.conf.Fields {
issue.Fields.Unknowns[key] = r.tmpl.Execute(fmt.Sprint(value), data)
}
Expand Down

0 comments on commit a620252

Please sign in to comment.