Skip to content

Commit a620252

Browse files
authored
Merge pull request #2 from taktv6/master
Added config options for JIRA components + prom labels as JIRA labels
2 parents 546ee64 + 293692d commit a620252

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ type ReceiverConfig struct {
9191
Description string `yaml:"description" json:"description"`
9292
WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"`
9393
Fields map[string]interface{} `yaml:"fields" json:"fields"`
94+
Components []string `yaml:"components" json:"components"`
95+
96+
// Label copy settings
97+
AddGroupLabels bool `yaml:"add_group_labels" json:"add_group_labels"`
9498

9599
// Catches all undefined fields and must be empty after parsing.
96100
XXX map[string]interface{} `yaml:",inline" json:"-"`

config/jiralert.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ receivers:
2424
- name: 'jira-ab'
2525
# JIRA project to create the issue in. Required.
2626
project: AB
27+
# Copy all Prometheus labels into separate JIRA labels.
28+
add_group_labels: false
2729

2830
- name: 'jira-xy'
2931
project: XY
3032
issue_type: Task
33+
# JIRA components. Optional.
34+
components: [ 'Operations' ]
3135
# Standard or custom field values to set on created issue. Optional.
3236
fields:
3337
foo: bar

notify.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ func (r *Receiver) Notify(data *alertmanager.Data) (bool, error) {
7878
if r.conf.Priority != "" {
7979
issue.Fields.Priority = &jira.Priority{Name: r.tmpl.Execute(r.conf.Priority, data)}
8080
}
81+
82+
// Add Components
83+
issue.Fields.Components = make([]*jira.Component, 0, len(r.conf.Components))
84+
for _, component := range r.conf.Components {
85+
issue.Fields.Components = append(issue.Fields.Components, &jira.Component{Name: component})
86+
}
87+
88+
// Add Labels
89+
if r.conf.AddGroupLabels {
90+
for k, v := range data.GroupLabels {
91+
issue.Fields.Labels = append(issue.Fields.Labels, fmt.Sprintf("%s=%q", k, v))
92+
}
93+
}
94+
8195
for key, value := range r.conf.Fields {
8296
issue.Fields.Unknowns[key] = r.tmpl.Execute(fmt.Sprint(value), data)
8397
}

0 commit comments

Comments
 (0)