fix remote agent ip
This commit is contained in:
parent
e6054129b2
commit
af71d3f4f9
1 changed files with 26 additions and 2 deletions
|
|
@ -52,8 +52,9 @@ defmodule ToweropsWeb.AgentChannel do
|
|||
# Subscribe to assignment changes for this agent
|
||||
Phoenix.PubSub.subscribe(Towerops.PubSub, "agent:#{agent_token.id}:assignments")
|
||||
|
||||
# Update last_seen_at on join
|
||||
_ = Agents.update_agent_token_heartbeat(agent_token.id, nil, %{})
|
||||
# Update last_seen_at and IP on join
|
||||
remote_ip = get_remote_ip(socket)
|
||||
_ = Agents.update_agent_token_heartbeat(agent_token.id, remote_ip, %{})
|
||||
|
||||
# Send initial job list
|
||||
send(self(), :send_jobs)
|
||||
|
|
@ -454,4 +455,27 @@ defmodule ToweropsWeb.AgentChannel do
|
|||
end
|
||||
|
||||
defp parse_float(_), do: nil
|
||||
|
||||
defp get_remote_ip(socket) do
|
||||
case socket.transport_pid do
|
||||
nil ->
|
||||
nil
|
||||
|
||||
pid when is_pid(pid) ->
|
||||
case :ranch.get_addr(pid) do
|
||||
{ip, _port} -> format_ip(ip)
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
rescue
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
defp format_ip({a, b, c, d}), do: "#{a}.#{b}.#{c}.#{d}"
|
||||
|
||||
defp format_ip({a, b, c, d, e, f, g, h}),
|
||||
do:
|
||||
"#{Integer.to_string(a, 16)}:#{Integer.to_string(b, 16)}:#{Integer.to_string(c, 16)}:#{Integer.to_string(d, 16)}:#{Integer.to_string(e, 16)}:#{Integer.to_string(f, 16)}:#{Integer.to_string(g, 16)}:#{Integer.to_string(h, 16)}"
|
||||
|
||||
defp format_ip(_), do: nil
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue