fix: auto-dismiss agent offline insights when agent reconnects
This commit is contained in:
parent
8109bd71c8
commit
11d976531b
1 changed files with 26 additions and 3 deletions
|
|
@ -195,9 +195,32 @@ defmodule Towerops.Agents do
|
|||
_ -> [last_seen_at: now, last_ip: ip_address]
|
||||
end
|
||||
|
||||
AgentToken
|
||||
|> where([t], t.id == ^agent_token_id)
|
||||
|> Repo.update_all(set: updates)
|
||||
result =
|
||||
AgentToken
|
||||
|> where([t], t.id == ^agent_token_id)
|
||||
|> Repo.update_all(set: updates)
|
||||
|
||||
# Auto-dismiss agent offline insights when agent comes back online
|
||||
dismiss_agent_offline_insights(agent_token_id)
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
defp dismiss_agent_offline_insights(agent_token_id) do
|
||||
alias Towerops.Preseem.Insight
|
||||
|
||||
now = DateTime.truncate(DateTime.utc_now(), :second)
|
||||
|
||||
{count, _} =
|
||||
Insight
|
||||
|> where(agent_token_id: ^agent_token_id, type: "agent_offline", status: "active")
|
||||
|> Repo.update_all(set: [status: "dismissed", dismissed_at: now])
|
||||
|
||||
if count > 0 do
|
||||
Logger.info("Auto-dismissed #{count} agent offline insight(s) for agent #{agent_token_id}")
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue