Skip to content

Commit

Permalink
Add incident ID
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Aug 28, 2024
1 parent f188d7a commit 62b36c1
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import time

from middlewared.alert.base import AlertClass, AlertCategory, AlertLevel, Alert, AlertSource, UnavailableException
from middlewared.utils.crypto import generate_token


class FailoverRemoteSystemInaccessibleAlertClass(AlertClass):
category = AlertCategory.HA
level = AlertLevel.CRITICAL
title = 'Other Controller is Inaccessible'
text = 'Other TrueNAS controller is inaccessible. Contact support.'
text = 'Other TrueNAS controller is inaccessible. Contact support. Incident ID: %s.'
products = ('SCALE_ENTERPRISE',)
proactive_support = True
proactive_support_notify_gone = True
Expand All @@ -26,15 +27,19 @@ class FailoverRemoteSystemInaccessibleAlertSource(AlertSource):
def __init__(self, middleware):
super().__init__(middleware)
self.last_available = time.monotonic()
self.incident_id = None

async def check(self):
try:
await self.middleware.call('failover.call_remote', 'core.ping', {'timeout': 2})
except Exception:
if time.monotonic() - self.last_available > 4 * 3600:
return [Alert(FailoverRemoteSystemInaccessibleAlertClass)]
if self.incident_id is None:
self.incident_id = generate_token(16, url_safe=True)
return [Alert(FailoverRemoteSystemInaccessibleAlertClass, args=[self.incident_id])]
else:
raise UnavailableException()

self.last_available = time.monotonic()
self.incident_id = None
return []

0 comments on commit 62b36c1

Please sign in to comment.