Skip to content

Commit

Permalink
disable update existing jira issues with parameter (prometheus-commun…
Browse files Browse the repository at this point in the history
…ity#150)

* Bump all dependencies (prometheus-community#133)

Signed-off-by: Jan-Otto Kröpke <jok@cloudeteer.de>

Signed-off-by: Jan-Otto Kröpke <jok@cloudeteer.de>
Signed-off-by: Holger Waschke <holger.waschke@dvag.com>

* parameter to disable update jira issues

Signed-off-by: Holger Waschke <holger_2000@hotmail.com>
Signed-off-by: Holger Waschke <holger.waschke@dvag.com>

* rename parameter to make it more clear and avoid double negation. fix bug with missing return value.

Signed-off-by: Holger Waschke <holger.waschke@dvag.com>

* Update main.go

Signed-off-by: dvag-holger-waschke <85643002+dvag-holger-waschke@users.noreply.github.com>

* Update notify.go

Signed-off-by: dvag-holger-waschke <85643002+dvag-holger-waschke@users.noreply.github.com>

* Update main.go

Signed-off-by: dvag-holger-waschke <85643002+dvag-holger-waschke@users.noreply.github.com>

* Update main.go

Signed-off-by: dvag-holger-waschke <85643002+dvag-holger-waschke@users.noreply.github.com>

* Update main.go

Signed-off-by: dvag-holger-waschke <85643002+dvag-holger-waschke@users.noreply.github.com>

* Update notify.go

Signed-off-by: dvag-holger-waschke <85643002+dvag-holger-waschke@users.noreply.github.com>

* fix for notify test

Signed-off-by: Holger Waschke <holger.waschke@dvag.com>

---------

Signed-off-by: Jan-Otto Kröpke <jok@cloudeteer.de>
Signed-off-by: Holger Waschke <holger.waschke@dvag.com>
Signed-off-by: Holger Waschke <holger_2000@hotmail.com>
Signed-off-by: dvag-holger-waschke <85643002+dvag-holger-waschke@users.noreply.github.com>
Co-authored-by: Jan-Otto Kröpke <github@jkroepke.de>
Co-authored-by: Holger Waschke <holger_2000@hotmail.com>
  • Loading branch information
3 people authored and rufusnufus committed May 13, 2024
1 parent 17d1ac3 commit 177ee50
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
5 changes: 4 additions & 1 deletion cmd/jiralert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var (
logFormat = flag.String("log.format", logFormatLogfmt, "Log format to use ("+logFormatLogfmt+", "+logFormatJSON+")")
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"+
"- this ensures that the label text does not overflow the allowed length in jira (255)")
updateSummary = flag.Bool("update-summary", true, "When false, jiralert does not update the summary of the existing jira issue, even when changes are spotted.")
updateDescription = flag.Bool("update-description", true, "When false, jiralert does not update the description of the existing jira issue, even when changes are spotted.")
reopenTickets = flag.Bool("reopen-tickets", true, "When false, jiralert does not reopen tickets.")

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

if retry, err := notify.NewReceiver(logger, conf, tmpl, client.Issue).Notify(&data, *hashJiraLabel); err != nil {
if retry, err := notify.NewReceiver(logger, conf, tmpl, client.Issue).Notify(&data, *hashJiraLabel, *updateSummary, *updateDescription, *reopenTickets); err != nil {
var status int
if retry {
// Instruct Alertmanager to retry.
Expand Down
41 changes: 24 additions & 17 deletions pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewReceiver(logger log.Logger, c *config.ReceiverConfig, t *template.Templa
}

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

if issue != nil {

// Update summary if needed.
if issue.Fields.Summary != issueSummary {
retry, err := r.updateSummary(issue.Key, issueSummary)
if err != nil {
return retry, err
if updateSummary {
if issue.Fields.Summary != issueSummary {
level.Debug(r.logger).Log("updateSummaryDisabled executing")
retry, err := r.updateSummary(issue.Key, issueSummary)
if err != nil {
return retry, err
}
}
}

if issue.Fields.Description != issueDesc {
retry, err := r.updateDescription(issue.Key, issueDesc)
if err != nil {
return retry, err
if updateDescription {
if issue.Fields.Description != issueDesc {
retry, err := r.updateDescription(issue.Key, issueDesc)
if err != nil {
return retry, err
}
}
}

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

if r.conf.WontFixResolution != "" && issue.Fields.Resolution != nil &&
issue.Fields.Resolution.Name == r.conf.WontFixResolution {
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)
return false, nil
}
if reopenTickets {
if r.conf.WontFixResolution != "" && issue.Fields.Resolution != nil &&
issue.Fields.Resolution.Name == r.conf.WontFixResolution {
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)
return false, nil
}

if r.conf.ReopenEnabled != nil && !*r.conf.ReopenEnabled {
level.Debug(r.logger).Log("msg", "reopening disabled, skipping search for existing issue")
} else {
level.Info(r.logger).Log("msg", "issue was recently resolved, reopening", "key", issue.Key, "label", issueGroupLabel)
return r.reopen(issue.Key)
}

level.Debug(r.logger).Log("Did not update anything")
return false, nil
}

if len(data.Alerts.Firing()) == 0 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ package notify

import (
"fmt"
"github.com/andygrunwald/go-jira"
"os"
"sort"
"testing"
"time"

"github.com/andygrunwald/go-jira"

"github.com/trivago/tgo/tcontainer"

"github.com/go-kit/log"
Expand Down Expand Up @@ -550,7 +551,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
return testNowTime
}

_, err := receiver.Notify(tcase.inputAlert, true)
_, err := receiver.Notify(tcase.inputAlert, true, true, true, true)
require.NoError(t, err)
require.Equal(t, tcase.expectedJiraIssues, fakeJira.issuesByKey)
}); !ok {
Expand Down

0 comments on commit 177ee50

Please sign in to comment.