diff --git a/test/towerops/snmp/profiles/vendors/routeros_test.exs b/test/towerops/snmp/profiles/vendors/routeros_test.exs index 6ca7ac68..733d94e6 100644 --- a/test/towerops/snmp/profiles/vendors/routeros_test.exs +++ b/test/towerops/snmp/profiles/vendors/routeros_test.exs @@ -267,5 +267,79 @@ defmodule Towerops.Snmp.Profiles.Vendors.RouterosTest do assert sensors == [] end + + test "discovers gauge sensors with correct divisors for voltage" do + expect(SnmpMock, :walk, fn _, @wl_ap_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @wl_stat_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @wl_60g_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @lte_modem_table, _ -> {:ok, []} end) + + # mtxrGaugeTable with voltage sensor (unit type 3 = deci-volts) + # .2.{idx} = mtxrGaugeName, .3.{idx} = mtxrGaugeValue, .4.{idx} = mtxrGaugeUnit + expect(SnmpMock, :walk, fn _, @gauge_table, _ -> + {:ok, + [ + # PSU Voltage: raw value 469, unit type 3 (deci-volts) -> should be 46.9V + %{oid: "#{@gauge_table}.2.1", value: "psu-voltage"}, + %{oid: "#{@gauge_table}.3.1", value: 469}, + %{oid: "#{@gauge_table}.4.1", value: 3}, + # CPU Temperature: raw value 450, unit type 1 (celsius * 10) -> should be 45.0°C + %{oid: "#{@gauge_table}.2.2", value: "cpu-temperature"}, + %{oid: "#{@gauge_table}.3.2", value: 450}, + %{oid: "#{@gauge_table}.4.2", value: 1} + ]} + end) + + expect(SnmpMock, :walk, fn _, @optical_table, _ -> {:ok, []} end) + expect(SnmpMock, :get, 2, fn _, _oid, _ -> {:error, :timeout} end) + + sensors = Routeros.discover_wireless_sensors(@client_opts) + + # Find the voltage sensor + voltage_sensor = Enum.find(sensors, &(&1.sensor_descr == "psu-voltage")) + assert voltage_sensor + assert voltage_sensor.sensor_type == "voltage" + assert voltage_sensor.sensor_unit == "V" + assert voltage_sensor.sensor_divisor == 10 + assert voltage_sensor.last_value == 46.9 + + # Find the temperature sensor + temp_sensor = Enum.find(sensors, &(&1.sensor_descr == "cpu-temperature")) + assert temp_sensor + assert temp_sensor.sensor_type == "temperature" + assert temp_sensor.sensor_unit == "°C" + assert temp_sensor.sensor_divisor == 10 + assert temp_sensor.last_value == 45.0 + end + + test "overrides sensor type based on name when unit type is unknown" do + expect(SnmpMock, :walk, fn _, @wl_ap_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @wl_stat_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @wl_60g_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @lte_modem_table, _ -> {:ok, []} end) + + # Device reports wrong unit type (0 = unknown) but name contains "voltage" + expect(SnmpMock, :walk, fn _, @gauge_table, _ -> + {:ok, + [ + %{oid: "#{@gauge_table}.2.1", value: "Board Voltage"}, + %{oid: "#{@gauge_table}.3.1", value: 120}, + %{oid: "#{@gauge_table}.4.1", value: 0} + ]} + end) + + expect(SnmpMock, :walk, fn _, @optical_table, _ -> {:ok, []} end) + expect(SnmpMock, :get, 2, fn _, _oid, _ -> {:error, :timeout} end) + + sensors = Routeros.discover_wireless_sensors(@client_opts) + + voltage_sensor = Enum.find(sensors, &(&1.sensor_descr == "Board Voltage")) + assert voltage_sensor + # Should override to voltage based on name, with divisor 10 + assert voltage_sensor.sensor_type == "voltage" + assert voltage_sensor.sensor_unit == "V" + assert voltage_sensor.sensor_divisor == 10 + assert voltage_sensor.last_value == 12.0 + end end end