Show state transitions in equipment event logs

Update interface operational status event messages to show both the
previous state and new state (e.g., 'Interface eth0 changed from DOWN
to UP' instead of just 'Interface eth0 is now up'). This provides
better context in the event logs.

Other event types already showed transitions:
- Admin status changes
- Speed changes
- MAC address changes
- Sensor threshold events
- Sensor spikes/drops
This commit is contained in:
Graham McIntire 2026-01-15 13:35:50 -06:00
parent 85abdedf8b
commit 0a410ecf81
No known key found for this signature in database

View file

@ -346,11 +346,18 @@ defmodule Towerops.Snmp.PollerWorker do
end
defp build_oper_status_event(interface, current_attrs, equipment_id, timestamp) do
message =
if interface.if_oper_status do
"Interface #{interface.if_name} changed from #{String.upcase(interface.if_oper_status)} to #{String.upcase(current_attrs.if_oper_status)}"
else
"Interface #{interface.if_name} is now #{String.upcase(current_attrs.if_oper_status)}"
end
%{
equipment_id: equipment_id,
event_type: if(current_attrs.if_oper_status == "up", do: "interface_up", else: "interface_down"),
severity: if(current_attrs.if_oper_status == "up", do: "info", else: "warning"),
message: "Interface #{interface.if_name} is now #{current_attrs.if_oper_status}",
message: message,
metadata: %{
interface_id: interface.id,
interface_name: interface.if_name,