dialyzer fixes
This commit is contained in:
parent
d29fb8cfd7
commit
c149b84db0
6 changed files with 62 additions and 47 deletions
|
|
@ -21,7 +21,7 @@ defmodule Towerops.Application do
|
|||
snmpkit_ebin = Application.app_dir(:towerops, "../snmpkit/ebin")
|
||||
|
||||
if File.dir?(snmpkit_ebin) do
|
||||
:code.add_patha(to_charlist(snmpkit_ebin))
|
||||
_ = :code.add_patha(to_charlist(snmpkit_ebin))
|
||||
end
|
||||
|
||||
# Run migrations on startup (Ecto handles locking for concurrent runs)
|
||||
|
|
|
|||
|
|
@ -510,12 +510,12 @@ defmodule Towerops.Devices do
|
|||
defp handle_monitoring_changes(device, old_monitoring) do
|
||||
cond do
|
||||
device.monitoring_enabled && !old_monitoring ->
|
||||
DeviceMonitorWorker.start_monitoring(device.id)
|
||||
_ = DeviceMonitorWorker.start_monitoring(device.id)
|
||||
# Trigger discovery when monitoring is enabled (if SNMP is also enabled)
|
||||
if device.snmp_enabled, do: DiscoveryWorker.enqueue(device.id)
|
||||
|
||||
!device.monitoring_enabled && old_monitoring ->
|
||||
DeviceMonitorWorker.stop_monitoring(device.id)
|
||||
_ = DeviceMonitorWorker.stop_monitoring(device.id)
|
||||
|
||||
true ->
|
||||
:ok
|
||||
|
|
@ -527,14 +527,14 @@ defmodule Towerops.Devices do
|
|||
|
||||
cond do
|
||||
device.snmp_enabled && !old_snmp ->
|
||||
DevicePollerWorker.start_polling(device.id)
|
||||
_ = DevicePollerWorker.start_polling(device.id)
|
||||
if should_discover, do: DiscoveryWorker.enqueue(device.id)
|
||||
|
||||
!device.snmp_enabled && old_snmp ->
|
||||
DevicePollerWorker.stop_polling(device.id)
|
||||
_ = DevicePollerWorker.stop_polling(device.id)
|
||||
|
||||
should_discover ->
|
||||
DiscoveryWorker.enqueue(device.id)
|
||||
_ = DiscoveryWorker.enqueue(device.id)
|
||||
|
||||
true ->
|
||||
:ok
|
||||
|
|
|
|||
|
|
@ -92,11 +92,10 @@ defmodule Towerops.Organizations do
|
|||
end
|
||||
|
||||
defp do_create_organization(attrs, user_id) do
|
||||
multi = Ecto.Multi.new()
|
||||
multi = Ecto.Multi.insert(multi, :organization, Organization.changeset(%Organization{}, attrs))
|
||||
|
||||
multi =
|
||||
Ecto.Multi.insert(multi, :membership, fn %{organization: organization} ->
|
||||
Ecto.Multi.new()
|
||||
|> Ecto.Multi.insert(:organization, Organization.changeset(%Organization{}, attrs))
|
||||
|> Ecto.Multi.insert(:membership, fn %{organization: organization} ->
|
||||
Membership.changeset(%Membership{}, %{
|
||||
organization_id: organization.id,
|
||||
user_id: user_id,
|
||||
|
|
|
|||
|
|
@ -26,9 +26,11 @@ defmodule Towerops.Snmp.AgentDiscovery do
|
|||
{:ok, %Device{}}
|
||||
"""
|
||||
|
||||
alias Ecto.Association.NotLoaded
|
||||
alias Towerops.Devices
|
||||
alias Towerops.Devices.Device, as: DeviceSchema
|
||||
alias Towerops.Snmp.Adapters.Replay
|
||||
alias Towerops.Snmp.Device, as: DiscoveredDevice
|
||||
alias Towerops.Snmp.Discovery
|
||||
|
||||
require Logger
|
||||
|
|
@ -57,7 +59,7 @@ defmodule Towerops.Snmp.AgentDiscovery do
|
|||
{:ok, %Device{}}
|
||||
"""
|
||||
@spec process_agent_discovery(DeviceSchema.t(), map()) ::
|
||||
{:ok, Discovery.Device.t()} | {:error, term()}
|
||||
{:ok, DiscoveredDevice.t()} | {:error, term()}
|
||||
def process_agent_discovery(device, oid_values) when is_map(oid_values) do
|
||||
oid_count = map_size(oid_values)
|
||||
|
||||
|
|
@ -85,9 +87,16 @@ defmodule Towerops.Snmp.AgentDiscovery do
|
|||
# but read from the OID map instead of making SNMP queries
|
||||
case Discovery.discover_device_with_opts(device, client_opts) do
|
||||
{:ok, discovered_device} ->
|
||||
interfaces_count =
|
||||
case discovered_device.interfaces do
|
||||
%NotLoaded{} -> 0
|
||||
list when is_list(list) -> length(list)
|
||||
_ -> 0
|
||||
end
|
||||
|
||||
Logger.debug("Agent discovery succeeded for #{device.name}",
|
||||
device_id: device.id,
|
||||
interfaces: length(discovered_device.interfaces || []),
|
||||
interfaces: interfaces_count,
|
||||
sensors: count_sensors(discovered_device)
|
||||
)
|
||||
|
||||
|
|
@ -122,12 +131,12 @@ defmodule Towerops.Snmp.AgentDiscovery do
|
|||
end
|
||||
|
||||
# Count sensors in discovered device
|
||||
@spec count_sensors(Discovery.Device.t()) :: non_neg_integer()
|
||||
@spec count_sensors(DiscoveredDevice.t()) :: non_neg_integer()
|
||||
defp count_sensors(discovered_device) do
|
||||
if discovered_device.sensors do
|
||||
length(discovered_device.sensors)
|
||||
else
|
||||
0
|
||||
case discovered_device.sensors do
|
||||
%NotLoaded{} -> 0
|
||||
list when is_list(list) -> length(list)
|
||||
_ -> 0
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -115,25 +115,32 @@ defmodule Towerops.Workers.DiscoveryWorker do
|
|||
|
||||
case result do
|
||||
{:ok, %Oban.Job{conflict?: true}} ->
|
||||
Logger.debug(
|
||||
"Discovery job already enqueued for device, skipping duplicate",
|
||||
device_id: device_id,
|
||||
caller: caller_module
|
||||
)
|
||||
_ =
|
||||
Logger.debug(
|
||||
"Discovery job already enqueued for device, skipping duplicate",
|
||||
device_id: device_id,
|
||||
caller: caller_module
|
||||
)
|
||||
|
||||
:ok
|
||||
|
||||
{:ok, _job} ->
|
||||
Logger.debug(
|
||||
"Discovery job enqueued for device",
|
||||
device_id: device_id,
|
||||
caller: caller_module
|
||||
)
|
||||
_ =
|
||||
Logger.debug(
|
||||
"Discovery job enqueued for device",
|
||||
device_id: device_id,
|
||||
caller: caller_module
|
||||
)
|
||||
|
||||
:ok
|
||||
|
||||
{:error, _} = error ->
|
||||
Logger.warning(
|
||||
"Failed to enqueue discovery job",
|
||||
device_id: device_id,
|
||||
caller: caller_module
|
||||
)
|
||||
_ =
|
||||
Logger.warning(
|
||||
"Failed to enqueue discovery job",
|
||||
device_id: device_id,
|
||||
caller: caller_module
|
||||
)
|
||||
|
||||
error
|
||||
end
|
||||
|
|
@ -241,20 +248,22 @@ defmodule Towerops.Workers.DiscoveryWorker do
|
|||
defp trigger_agent_discovery(device, agent_token_id) do
|
||||
# Broadcast discovery request to agent's channel
|
||||
# The agent will receive this via PubSub and execute discovery
|
||||
Logger.info(
|
||||
"Sending discovery request to remote agent via PubSub",
|
||||
device_id: device.id,
|
||||
device_name: device.name,
|
||||
device_ip: device.ip_address,
|
||||
agent_token_id: agent_token_id,
|
||||
pubsub_channel: "agent:#{agent_token_id}:discovery"
|
||||
)
|
||||
_ =
|
||||
Logger.info(
|
||||
"Sending discovery request to remote agent via PubSub",
|
||||
device_id: device.id,
|
||||
device_name: device.name,
|
||||
device_ip: device.ip_address,
|
||||
agent_token_id: agent_token_id,
|
||||
pubsub_channel: "agent:#{agent_token_id}:discovery"
|
||||
)
|
||||
|
||||
Phoenix.PubSub.broadcast(
|
||||
Towerops.PubSub,
|
||||
"agent:#{agent_token_id}:discovery",
|
||||
{:discovery_requested, device.id}
|
||||
)
|
||||
_ =
|
||||
Phoenix.PubSub.broadcast(
|
||||
Towerops.PubSub,
|
||||
"agent:#{agent_token_id}:discovery",
|
||||
{:discovery_requested, device.id}
|
||||
)
|
||||
|
||||
Logger.info(
|
||||
"Discovery request sent, waiting up to #{@agent_discovery_timeout_ms}ms for agent to respond",
|
||||
|
|
|
|||
|
|
@ -339,8 +339,6 @@ defmodule ToweropsWeb.GraphLive.Show do
|
|||
end
|
||||
end
|
||||
|
||||
defp calculate_chart_stats(_), do: {nil, nil}
|
||||
|
||||
defp extract_min_max_from_datasets(datasets) do
|
||||
values = Enum.flat_map(datasets, &extract_values_from_dataset/1)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue