Skip to content

Commit

Permalink
Make sure tnc alerts are properly raised
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Jan 23, 2025
1 parent b8ca512 commit 731338c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def start(self):
self.middleware.send_event(
'tn_connect.config', 'CHANGED', fields=await self.middleware.call('tn_connect.config')
)
await self.middleware.call('alert.oneshot_create', 'TNCDisabledAutoUnconfigured', None)
return
case 500:
logger.debug('TNC Heartbeat: Received 500')
Expand All @@ -88,7 +89,7 @@ async def start(self):
'TNC Heartbeat: Unable to calculate sleep time, raising alert as it has likely been 48 hours '
'since the last successful heartbeat (last failure: %s)', last_failure,
)
# TODO: Raise alert
await self.middleware.call('alert.oneshot_create', 'TNCHeartbeatConnectionFailure', None)
break
else:
logger.debug(
Expand All @@ -102,6 +103,8 @@ async def start(self):
})
logger.debug('TNC Heartbeat: Resetting last heartbeat failure datetime')


await self.middleware.call('alert.oneshot_delete', 'TNCHeartbeatConnectionFailure')
await asyncio.sleep(self.HEARTBEAT_INTERVAL)

tnc_config = await self.middleware.call('tn_connect.config_internal')
Expand Down
6 changes: 6 additions & 0 deletions src/middlewared/middlewared/plugins/truenas_connect/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ async def do_update(self, data):
with contextlib.suppress(KeyError):
await self.middleware.call('cache.pop', CLAIM_TOKEN_CACHE_KEY)
db_payload['status'] = Status.CLAIM_TOKEN_MISSING.name
logger.debug('Removing any stale TNC unconfigured alert or heartbeat alert')
await self.middleware.call('alert.oneshot_delete', 'TNCDisabledAutoUnconfigured')
await self.middleware.call('alert.oneshot_delete', 'TNCHeartbeatConnectionFailure')
elif config['enabled'] is True and data['enabled'] is False:
await self.unset_registration_details()
db_payload.update(get_unset_payload())
Expand All @@ -139,6 +142,9 @@ async def unset_registration_details(self):
with contextlib.suppress(KeyError):
await self.middleware.call('cache.pop', CLAIM_TOKEN_CACHE_KEY)

logger.debug('TNC is being disabled, removing any stale TNC heartbeat failure alert')
await self.middleware.call('alert.oneshot_delete', 'TNCHeartbeatConnectionFailure')

config = await self.config_internal()
creds = get_account_id_and_system_id(config)
if creds is None:
Expand Down

0 comments on commit 731338c

Please sign in to comment.