Skip to content

Commit 177ee50

Browse files
holger-waschkejkroepkedj-holgie
authored andcommitted
disable update existing jira issues with parameter (prometheus-community#150)
* Bump all dependencies (prometheus-community#133) Signed-off-by: Jan-Otto Kröpke <[email protected]> Signed-off-by: Jan-Otto Kröpke <[email protected]> Signed-off-by: Holger Waschke <[email protected]> * parameter to disable update jira issues Signed-off-by: Holger Waschke <[email protected]> Signed-off-by: Holger Waschke <[email protected]> * rename parameter to make it more clear and avoid double negation. fix bug with missing return value. Signed-off-by: Holger Waschke <[email protected]> * Update main.go Signed-off-by: dvag-holger-waschke <[email protected]> * Update notify.go Signed-off-by: dvag-holger-waschke <[email protected]> * Update main.go Signed-off-by: dvag-holger-waschke <[email protected]> * Update main.go Signed-off-by: dvag-holger-waschke <[email protected]> * Update main.go Signed-off-by: dvag-holger-waschke <[email protected]> * Update notify.go Signed-off-by: dvag-holger-waschke <[email protected]> * fix for notify test Signed-off-by: Holger Waschke <[email protected]> --------- Signed-off-by: Jan-Otto Kröpke <[email protected]> Signed-off-by: Holger Waschke <[email protected]> Signed-off-by: Holger Waschke <[email protected]> Signed-off-by: dvag-holger-waschke <[email protected]> Co-authored-by: Jan-Otto Kröpke <[email protected]> Co-authored-by: Holger Waschke <[email protected]>
1 parent 17d1ac3 commit 177ee50

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

cmd/jiralert/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ var (
4848
logFormat = flag.String("log.format", logFormatLogfmt, "Log format to use ("+logFormatLogfmt+", "+logFormatJSON+")")
4949
hashJiraLabel = flag.Bool("hash-jira-label", false, "if enabled: renames ALERT{...} to JIRALERT{...}; also hashes the key-value pairs inside of JIRALERT{...} in the created jira issue labels"+
5050
"- this ensures that the label text does not overflow the allowed length in jira (255)")
51+
updateSummary = flag.Bool("update-summary", true, "When false, jiralert does not update the summary of the existing jira issue, even when changes are spotted.")
52+
updateDescription = flag.Bool("update-description", true, "When false, jiralert does not update the description of the existing jira issue, even when changes are spotted.")
53+
reopenTickets = flag.Bool("reopen-tickets", true, "When false, jiralert does not reopen tickets.")
5154

5255
// Version is the build version, set by make to latest git tag/hash via `-ldflags "-X main.Version=$(VERSION)"`.
5356
Version = "<local build>"
@@ -121,7 +124,7 @@ func main() {
121124
return
122125
}
123126

124-
if retry, err := notify.NewReceiver(logger, conf, tmpl, client.Issue).Notify(&data, *hashJiraLabel); err != nil {
127+
if retry, err := notify.NewReceiver(logger, conf, tmpl, client.Issue).Notify(&data, *hashJiraLabel, *updateSummary, *updateDescription, *reopenTickets); err != nil {
125128
var status int
126129
if retry {
127130
// Instruct Alertmanager to retry.

pkg/notify/notify.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewReceiver(logger log.Logger, c *config.ReceiverConfig, t *template.Templa
6060
}
6161

6262
// Notify manages JIRA issues based on alertmanager webhook notify message.
63-
func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool) (bool, error) {
63+
func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSummary bool, updateDescription bool, reopenTickets bool) (bool, error) {
6464
project, err := r.tmpl.Execute(r.conf.Project, data)
6565
if err != nil {
6666
return false, errors.Wrap(err, "generate project from template")
@@ -87,18 +87,24 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool) (bool, er
8787
}
8888

8989
if issue != nil {
90+
9091
// Update summary if needed.
91-
if issue.Fields.Summary != issueSummary {
92-
retry, err := r.updateSummary(issue.Key, issueSummary)
93-
if err != nil {
94-
return retry, err
92+
if updateSummary {
93+
if issue.Fields.Summary != issueSummary {
94+
level.Debug(r.logger).Log("updateSummaryDisabled executing")
95+
retry, err := r.updateSummary(issue.Key, issueSummary)
96+
if err != nil {
97+
return retry, err
98+
}
9599
}
96100
}
97101

98-
if issue.Fields.Description != issueDesc {
99-
retry, err := r.updateDescription(issue.Key, issueDesc)
100-
if err != nil {
101-
return retry, err
102+
if updateDescription {
103+
if issue.Fields.Description != issueDesc {
104+
retry, err := r.updateDescription(issue.Key, issueDesc)
105+
if err != nil {
106+
return retry, err
107+
}
102108
}
103109
}
104110

@@ -122,18 +128,19 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool) (bool, er
122128
return false, nil
123129
}
124130

125-
if r.conf.WontFixResolution != "" && issue.Fields.Resolution != nil &&
126-
issue.Fields.Resolution.Name == r.conf.WontFixResolution {
127-
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)
128-
return false, nil
129-
}
131+
if reopenTickets {
132+
if r.conf.WontFixResolution != "" && issue.Fields.Resolution != nil &&
133+
issue.Fields.Resolution.Name == r.conf.WontFixResolution {
134+
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)
135+
return false, nil
136+
}
130137

131-
if r.conf.ReopenEnabled != nil && !*r.conf.ReopenEnabled {
132-
level.Debug(r.logger).Log("msg", "reopening disabled, skipping search for existing issue")
133-
} else {
134138
level.Info(r.logger).Log("msg", "issue was recently resolved, reopening", "key", issue.Key, "label", issueGroupLabel)
135139
return r.reopen(issue.Key)
136140
}
141+
142+
level.Debug(r.logger).Log("Did not update anything")
143+
return false, nil
137144
}
138145

139146
if len(data.Alerts.Firing()) == 0 {

pkg/notify/notify_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ package notify
1414

1515
import (
1616
"fmt"
17-
"github.com/andygrunwald/go-jira"
1817
"os"
1918
"sort"
2019
"testing"
2120
"time"
2221

22+
"github.com/andygrunwald/go-jira"
23+
2324
"github.com/trivago/tgo/tcontainer"
2425

2526
"github.com/go-kit/log"
@@ -550,7 +551,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
550551
return testNowTime
551552
}
552553

553-
_, err := receiver.Notify(tcase.inputAlert, true)
554+
_, err := receiver.Notify(tcase.inputAlert, true, true, true, true)
554555
require.NoError(t, err)
555556
require.Equal(t, tcase.expectedJiraIssues, fakeJira.issuesByKey)
556557
}); !ok {

0 commit comments

Comments
 (0)