@@ -137,32 +137,32 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum
137137
138138 if len (data .Alerts .Firing ()) == 0 {
139139 if r .conf .AutoResolve != nil {
140- level .Debug (r .logger ).Log ("msg" , "no firing alert; resolving issue" , "key" , issue .Key , "label" , issueGroupLabel )
140+ level .Debug (r .logger ).Log ("msg" , "no firing alert; resolving issue" , "key" , issue .Key , r . conf . FieldLabels , issueGroupLabel )
141141 retry , err := r .resolveIssue (issue .Key )
142142 if err != nil {
143143 return retry , err
144144 }
145145 return false , nil
146146 }
147147
148- level .Debug (r .logger ).Log ("msg" , "no firing alert; summary checked, nothing else to do." , "key" , issue .Key , "label" , issueGroupLabel )
148+ level .Debug (r .logger ).Log ("msg" , "no firing alert; summary checked, nothing else to do." , "key" , issue .Key , r . conf . FieldLabels , issueGroupLabel )
149149 return false , nil
150150 }
151151
152152 // The set of JIRA status categories is fixed, this is a safe check to make.
153153 if issue .Fields .Status .StatusCategory .Key != "done" {
154- level .Debug (r .logger ).Log ("msg" , "issue is unresolved, all is done" , "key" , issue .Key , "label" , issueGroupLabel )
154+ level .Debug (r .logger ).Log ("msg" , "issue is unresolved, all is done" , "key" , issue .Key , r . conf . FieldLabels , issueGroupLabel )
155155 return false , nil
156156 }
157157
158158 if reopenTickets {
159159 if r .conf .WontFixResolution != "" && issue .Fields .Resolution != nil &&
160160 issue .Fields .Resolution .Name == r .conf .WontFixResolution {
161- level .Info (r .logger ).Log ("msg" , "issue was resolved as won't fix, not reopening" , "key" , issue .Key , "label" , issueGroupLabel , "resolution" , issue .Fields .Resolution .Name )
161+ level .Info (r .logger ).Log ("msg" , "issue was resolved as won't fix, not reopening" , "key" , issue .Key , r . conf . FieldLabels , issueGroupLabel , "resolution" , issue .Fields .Resolution .Name )
162162 return false , nil
163163 }
164164
165- level .Info (r .logger ).Log ("msg" , "issue was recently resolved, reopening" , "key" , issue .Key , "label" , issueGroupLabel )
165+ level .Info (r .logger ).Log ("msg" , "issue was recently resolved, reopening" , "key" , issue .Key , r . conf . FieldLabels , issueGroupLabel )
166166 return r .reopen (issue .Key )
167167 }
168168
@@ -171,11 +171,11 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum
171171 }
172172
173173 if len (data .Alerts .Firing ()) == 0 {
174- level .Debug (r .logger ).Log ("msg" , "no firing alert; nothing to do." , "label" , issueGroupLabel )
174+ level .Debug (r .logger ).Log ("msg" , "no firing alert; nothing to do." , r . conf . FieldLabels , issueGroupLabel )
175175 return false , nil
176176 }
177177
178- level .Info (r .logger ).Log ("msg" , "no recent matching issue found, creating new issue" , "label" , issueGroupLabel )
178+ level .Info (r .logger ).Log ("msg" , "no recent matching issue found, creating new issue" , r . conf . FieldLabels , issueGroupLabel )
179179
180180 issueType , err := r .tmpl .Execute (r .conf .IssueType , data )
181181 if err != nil {
@@ -190,10 +190,14 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum
190190 Type : jira.IssueType {Name : issueType },
191191 Description : issueDesc ,
192192 Summary : issueSummary ,
193- Labels : append (staticLabels , issueGroupLabel ),
194193 Unknowns : tcontainer .NewMarshalMap (),
195194 },
196195 }
196+ if r .conf .FieldLabels == "Labels" {
197+ issue .Fields .Labels = append (staticLabels , issueGroupLabel )
198+ } else {
199+ issue .Fields .Unknowns [r .conf .FieldLabelsKey ] = append (staticLabels , issueGroupLabel )
200+ }
197201 if r .conf .Priority != "" {
198202 issuePrio , err := r .tmpl .Execute (r .conf .Priority , data )
199203 if err != nil {
@@ -312,9 +316,15 @@ func toGroupTicketLabel(groupLabels alertmanager.KV, hashJiraLabel bool) string
312316}
313317
314318func (r * Receiver ) search (projects []string , issueLabel string ) (* jira.Issue , bool , error ) {
319+ var labelKey string
315320 // Search multiple projects in case issue was moved and further alert firings are desired in existing JIRA.
316321 projectList := "'" + strings .Join (projects , "', '" ) + "'"
317- query := fmt .Sprintf ("project in(%s) and labels=%q order by resolutiondate desc" , projectList , issueLabel )
322+ if r .conf .FieldLabels == "Labels" {
323+ labelKey = "labels"
324+ } else {
325+ labelKey = fmt .Sprintf ("cf[%s]" , strings .Split (r .conf .FieldLabelsKey , "_" )[1 ])
326+ }
327+ query := fmt .Sprintf ("project in(%s) and %s=%q order by resolutiondate desc" , projectList , labelKey , issueLabel )
318328 options := & jira.SearchOptions {
319329 Fields : []string {"summary" , "status" , "resolution" , "resolutiondate" , "description" , "comment" },
320330 MaxResults : 2 ,
@@ -361,7 +371,7 @@ func (r *Receiver) findIssueToReuse(project string, issueGroupLabel string) (*ji
361371
362372 resolutionTime := time .Time (issue .Fields .Resolutiondate )
363373 if resolutionTime != (time.Time {}) && resolutionTime .Add (time .Duration (* r .conf .ReopenDuration )).Before (r .timeNow ()) && * r .conf .ReopenDuration != 0 {
364- level .Debug (r .logger ).Log ("msg" , "existing resolved issue is too old to reopen, skipping" , "key" , issue .Key , "label" , issueGroupLabel , "resolution_time" , resolutionTime .Format (time .RFC3339 ), "reopen_duration" , * r .conf .ReopenDuration )
374+ level .Debug (r .logger ).Log ("msg" , "existing resolved issue is too old to reopen, skipping" , "key" , issue .Key , r . conf . FieldLabels , issueGroupLabel , "resolution_time" , resolutionTime .Format (time .RFC3339 ), "reopen_duration" , * r .conf .ReopenDuration )
365375 return nil , false , nil
366376 }
367377
@@ -423,7 +433,6 @@ func (r *Receiver) reopen(issueKey string) (bool, error) {
423433}
424434
425435func (r * Receiver ) create (issue * jira.Issue ) (bool , error ) {
426- level .Debug (r .logger ).Log ("msg" , "create" , "issue" , fmt .Sprintf ("%+v" , * issue .Fields ))
427436 newIssue , resp , err := r .client .Create (issue )
428437 if err != nil {
429438 return handleJiraErrResponse ("Issue.Create" , resp , err , r .logger )
0 commit comments