fix: correct misclassified MikroTik voltage sensors
Fixes voltage sensors that were incorrectly classified as temperature
sensors due to MikroTik devices reporting wrong mtxrGaugeUnit values.
Problem:
- Sensors with names like "psu1-voltage" and "psu2-voltage" were
classified as temperature sensors with divisor=1
- This caused voltage readings to display as 469V instead of 46.9V
- The RouterOS profile already has name-based override logic for new
discoveries, but existing sensors needed fixing
Solution:
- Migration identifies sensors by:
- OID pattern: 1.3.6.1.4.1.14988.1.1.3.100.1.3.%
- Type mismatch: sensor_type = 'temperature' but name contains 'voltage'
- Incorrect divisor: sensor_divisor = 1
- Updates sensor metadata: type, unit, divisor
- Corrects historical sensor_reading values by dividing by 10
Future discoveries are already protected by the name-based override
logic in lib/towerops/snmp/profiles/vendors/routeros.ex:620-630
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
277d3be2bd
commit
68a4ebf601
1 changed files with 63 additions and 0 deletions
|
|
@ -0,0 +1,63 @@
|
||||||
|
defmodule Towerops.Repo.Migrations.FixMisclassifiedMikrotikVoltageSensors do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def up do
|
||||||
|
# Fix voltage sensors that were incorrectly classified as temperature
|
||||||
|
# These sensors have "voltage" in their name but were classified as temperature
|
||||||
|
# This happens when MikroTik devices report incorrect mtxrGaugeUnit values
|
||||||
|
|
||||||
|
# Update sensors: set correct type, unit, and divisor
|
||||||
|
execute """
|
||||||
|
UPDATE snmp_sensors
|
||||||
|
SET sensor_type = 'voltage',
|
||||||
|
sensor_unit = 'V',
|
||||||
|
sensor_divisor = 10
|
||||||
|
WHERE sensor_oid LIKE '1.3.6.1.4.1.14988.1.1.3.100.1.3.%'
|
||||||
|
AND sensor_type = 'temperature'
|
||||||
|
AND LOWER(sensor_descr) LIKE '%voltage%'
|
||||||
|
AND sensor_divisor = 1
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Divide existing sensor_reading values by 10 to correct historical data
|
||||||
|
execute """
|
||||||
|
UPDATE snmp_sensor_readings
|
||||||
|
SET value = value / 10
|
||||||
|
WHERE sensor_id IN (
|
||||||
|
SELECT id
|
||||||
|
FROM snmp_sensors
|
||||||
|
WHERE sensor_oid LIKE '1.3.6.1.4.1.14988.1.1.3.100.1.3.%'
|
||||||
|
AND sensor_type = 'voltage'
|
||||||
|
AND LOWER(sensor_descr) LIKE '%voltage%'
|
||||||
|
AND sensor_divisor = 10
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
def down do
|
||||||
|
# Revert changes
|
||||||
|
execute """
|
||||||
|
UPDATE snmp_sensors
|
||||||
|
SET sensor_type = 'temperature',
|
||||||
|
sensor_unit = '',
|
||||||
|
sensor_divisor = 1
|
||||||
|
WHERE sensor_oid LIKE '1.3.6.1.4.1.14988.1.1.3.100.1.3.%'
|
||||||
|
AND sensor_type = 'voltage'
|
||||||
|
AND LOWER(sensor_descr) LIKE '%voltage%'
|
||||||
|
AND sensor_divisor = 10
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Multiply sensor readings back by 10
|
||||||
|
execute """
|
||||||
|
UPDATE snmp_sensor_readings
|
||||||
|
SET value = value * 10
|
||||||
|
WHERE sensor_id IN (
|
||||||
|
SELECT id
|
||||||
|
FROM snmp_sensors
|
||||||
|
WHERE sensor_oid LIKE '1.3.6.1.4.1.14988.1.1.3.100.1.3.%'
|
||||||
|
AND sensor_type = 'temperature'
|
||||||
|
AND LOWER(sensor_descr) LIKE '%voltage%'
|
||||||
|
AND sensor_divisor = 1
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Reference in a new issue