diff --git a/config.go b/config.go index c26fec2..b604a77 100644 --- a/config.go +++ b/config.go @@ -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:"-"` diff --git a/config/jiralert.yml b/config/jiralert.yml index 0fd93ab..17b66a3 100644 --- a/config/jiralert.yml +++ b/config/jiralert.yml @@ -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 diff --git a/notify.go b/notify.go index 41e4e9c..863ede8 100644 --- a/notify.go +++ b/notify.go @@ -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) }