Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JIRA assignee #974

Merged
merged 4 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## Other changes
- Upgrade pylint 2.15.2 to 2.15.3 and pytest-cov 3.0.0 to 4.0.0 and sphinx 5.1.1 to 5.2.3; Add Google Chat proxy support - [#972](https://github.com/jertel/elastalert2/pull/972) - @nsano-rururu
- Fix Jira assign issue - [#974](https://github.com/jertel/elastalert2/pull/974) - @jorge-gyant

# 2.7.0

Expand Down
13 changes: 4 additions & 9 deletions elastalert/alerters/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ def reset_jira_args(self):
# Support single watcher or list
if type(self.watchers) != list:
self.watchers = [self.watchers]
if self.assignee:
self.jira_args['assignee'] = {'name': self.assignee}

self.set_priority()

Expand Down Expand Up @@ -233,13 +231,6 @@ def get_priorities(self):
for x in range(len(priorities)):
self.priority_ids[x] = priorities[x].id

def set_assignee(self, assignee):
self.assignee = assignee
if assignee:
self.jira_args['assignee'] = {'name': assignee}
elif 'assignee' in self.jira_args:
self.jira_args.pop('assignee')

def find_existing_ticket(self, matches):
# Default title, get stripped search version
if 'alert_subject' not in self.rule:
Expand Down Expand Up @@ -336,6 +327,10 @@ def alert(self, matches):
try:
self.issue = self.client.create_issue(**self.jira_args)

# Set JIRA assignee
if self.assignee:
self.client.assign_issue(self.issue, self.assignee)

# You can not add watchers on initial creation. Only as a follow-up action
if self.watchers:
for watcher in self.watchers:
Expand Down
8 changes: 6 additions & 2 deletions tests/alerters/jira_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_jira(caplog):
'jira_label': 'testlabel',
'jira_component': 'testcomponent',
'jira_description': description_txt,
'jira_assignee': 'testuser',
'jira_watchers': ['testwatcher1', 'testwatcher2'],
'timestamp_field': '@timestamp',
'alert_subject': 'Issue {0} occurred at {1}',
Expand Down Expand Up @@ -70,12 +71,13 @@ def test_jira(caplog):
description=mock.ANY,
summary='Issue test_value occurred at 2014-10-31T00:00:00',
),
mock.call().assign_issue(mock.ANY, 'testuser'),
mock.call().add_watcher(mock.ANY, 'testwatcher1'),
mock.call().add_watcher(mock.ANY, 'testwatcher2'),
]

# We don't care about additional calls to mock_jira, such as __str__
assert mock_jira.mock_calls[:6] == expected
assert mock_jira.mock_calls[:7] == expected
assert mock_jira.mock_calls[3][2]['description'].startswith(description_txt)
user, level, message = caplog.record_tuples[0]
assert 'elastalert' == user
Expand Down Expand Up @@ -213,6 +215,7 @@ def test_jira_arbitrary_field_support():
'jira_label': 'testlabel',
'jira_component': 'testcomponent',
'jira_description': description_txt,
'jira_assignee': 'testuser',
'jira_watchers': ['testwatcher1', 'testwatcher2'],
'jira_arbitrary_reference_string_field': '$owner$',
'jira_arbitrary_string_field': 'arbitrary_string_value',
Expand Down Expand Up @@ -291,12 +294,13 @@ def test_jira_arbitrary_field_support():
arbitrary_complex_array_field=[{'name': 'arbitrary_complex_value1'}, {'name': 'arbitrary_complex_value2'}],
arbitrary_complex_array_field_provided_as_single_value=[{'name': 'arbitrary_complex_value_in_array_field'}],
),
mock.call().assign_issue(mock.ANY, 'testuser'),
mock.call().add_watcher(mock.ANY, 'testwatcher1'),
mock.call().add_watcher(mock.ANY, 'testwatcher2'),
]

# We don't care about additional calls to mock_jira, such as __str__
assert mock_jira.mock_calls[:6] == expected
assert mock_jira.mock_calls[:7] == expected
assert mock_jira.mock_calls[3][2]['description'].startswith(description_txt)

# Reference an arbitrary string field that is not defined on the Jira server
Expand Down