Commit bb9a5121 authored by Dmitry Volodin's avatar Dmitry Volodin

Merge branch 'patch-avs-add-queue-close_tt' into 'master'

Add queue params to close_tt and add_comment method on TT adapter.

See merge request noc/noc!3158
parents 6a3e34d0 85d1fa92
......@@ -90,7 +90,7 @@ class BaseTTSystem(object):
"""
raise NotImplementedError()
def close_tt(self, tt_id, subject=None, body=None, reason=None, login=None):
def close_tt(self, tt_id, subject=None, body=None, reason=None, login=None, queue=None):
"""
Close TT
:param tt_id: TT id, as returned by create_tt
......@@ -98,18 +98,20 @@ class BaseTTSystem(object):
:param body: Closing message body
:param reason: Final reason
:param login: User login
:param queue: ticket queue
:returns: Boolean. True, when alarm is closed properly
:raises TTError:
"""
raise NotImplementedError()
def add_comment(self, tt_id, subject=None, body=None, login=None):
def add_comment(self, tt_id, subject=None, body=None, login=None, queue=None):
"""
Append comment to TT
:param tt_id: TT id, as returned by create_tt
:param subject: Closing message subject
:param body: Closing message body
:param login: User login
:param queue: ticket queue
:raises TTError:
"""
raise NotImplementedError()
......
......@@ -337,6 +337,8 @@ class ActiveAlarm(Document):
if self.clear_notification_group
else None,
close_tt=self.close_tt,
login="correlator",
queue=a.managed_object.tt_queue,
)
# Gather diagnostics
AlarmDiagnosticConfig.on_clear(a)
......
......@@ -41,7 +41,7 @@ retry_lock = threading.Lock()
next_retry = datetime.datetime.now()
def escalate(alarm_id, escalation_id, escalation_delay, *args, **kwargs):
def escalate(alarm_id, escalation_id, escalation_delay, login="correlator", *args, **kwargs):
def log(message, *args):
msg = message % args
logger.info("[%s] %s", alarm_id, msg)
......@@ -187,7 +187,7 @@ def escalate(alarm_id, escalation_id, escalation_delay, *args, **kwargs):
reason=pre_reason,
subject=subject,
body=body,
login="correlator",
login=login,
timestamp=alarm.timestamp,
)
except TemporaryTTError as e:
......@@ -247,7 +247,10 @@ def escalate(alarm_id, escalation_id, escalation_delay, *args, **kwargs):
try:
log("Appending comment to TT %s", tt_id)
tts.add_comment(
c_tt_id, body="Covered by TT %s" % tt_id, login="correlator"
c_tt_id,
body="Covered by TT %s" % tt_id,
login=login,
queue=mo.tt_queue,
)
metrics["escalation_tt_comment"] += 1
except NotImplementedError:
......@@ -294,17 +297,22 @@ def escalate(alarm_id, escalation_id, escalation_delay, *args, **kwargs):
if alarm.clear_notification_group
else None,
close_tt=alarm.close_tt,
login=login,
queue=mo.tt_queue,
)
elif nalarm == "A" and not nalarm.escalation_tt and tt_id:
logger.error("[%s] Alarm without escalation TT: %s", alarm.id, tt_id)
logger.info("[%s] Escalations loop end", alarm_id)
def notify_close(alarm_id, tt_id, subject, body, notification_group_id, close_tt=False):
def notify_close(
alarm_id, tt_id, subject, body, notification_group_id, close_tt=False, login=None, queue=None
):
def log(message, *args):
msg = message % args
logger.info("[%s] %s", alarm_id, msg)
login = login or "correlator"
if tt_id:
alarm = get_alarm(alarm_id)
alarm.set_escalation_close_ctx()
......@@ -325,7 +333,7 @@ def notify_close(alarm_id, tt_id, subject, body, notification_group_id, close_tt
# Close tt
try:
log("Closing TT %s", tt_id)
tts.close_tt(c_tt_id, subject=subject, body=body, login="correlator")
tts.close_tt(c_tt_id, subject=subject, body=body, login=login, queue=queue)
metrics["escalation_tt_close"] += 1
if alarm:
alarm.close_escalation()
......@@ -349,7 +357,9 @@ def notify_close(alarm_id, tt_id, subject, body, notification_group_id, close_tt
# Append comment to tt
try:
log("Appending comment to TT %s", tt_id)
tts.add_comment(c_tt_id, subject=subject, body=body, login="correlator")
tts.add_comment(
c_tt_id, subject=subject, body=body, login=login, queue=queue
)
metrics["escalation_tt_comment"] += 1
except TTError as e:
log("Failed to add comment to %s: %s", tt_id, e)
......
......@@ -41,7 +41,7 @@ class StubTTSystem(BaseTTSystem):
)
return str(uuid.uuid4())
def add_comment(self, tt_id, subject=None, body=None, login=None):
def add_comment(self, tt_id, subject=None, body=None, login=None, queue=None):
self.logger.info(
"add_comment(tt_id=%s, subject=%s, body=%s, login=%s)", tt_id, subject, body, login
)
......@@ -63,7 +63,7 @@ class StubTTSystem(BaseTTSystem):
"""
self.logger.info("Object %s appended to group TT %s", obj, gtt_id)
def close_tt(self, tt_id, subject=None, body=None, reason=None, login=None):
def close_tt(self, tt_id, subject=None, body=None, reason=None, login=None, queue=None):
"""
Close TT
:param tt_id: TT id, as returned by create_tt
......@@ -71,6 +71,7 @@ class StubTTSystem(BaseTTSystem):
:param body: Closing message body
:param reason: Final reason
:param login: User login
:param queue: ticket queue
:returns: Boolean. True, when alarm is closed properly
:raises TTError:
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment