support prod ip db import
This commit is contained in:
parent
8b71c4adb8
commit
0b27300931
2 changed files with 24 additions and 18 deletions
|
|
@ -113,10 +113,22 @@ defmodule ToweropsWeb.Api.V1.GeoipController do
|
|||
}
|
||||
end)
|
||||
|
||||
# Use upsert to avoid duplicates - replace existing records with same geoname_id
|
||||
# Use upsert to avoid duplicates - update specific fields on conflict
|
||||
# Don't use replace_all_except because it triggers DELETE+INSERT which violates foreign keys
|
||||
{inserted, _} =
|
||||
Repo.insert_all(Location, entries,
|
||||
on_conflict: {:replace_all_except, [:inserted_at]},
|
||||
on_conflict:
|
||||
{:replace,
|
||||
[
|
||||
:country_code,
|
||||
:country_name,
|
||||
:city_name,
|
||||
:subdivision_1_name,
|
||||
:subdivision_2_name,
|
||||
:latitude,
|
||||
:longitude,
|
||||
:updated_at
|
||||
]},
|
||||
conflict_target: :geoname_id
|
||||
)
|
||||
|
||||
|
|
@ -150,10 +162,18 @@ defmodule ToweropsWeb.Api.V1.GeoipController do
|
|||
}
|
||||
end)
|
||||
|
||||
# Use upsert to avoid duplicates - replace existing records with same network
|
||||
# Use upsert to avoid duplicates - update specific fields on conflict
|
||||
{inserted, _} =
|
||||
Repo.insert_all(Block, entries,
|
||||
on_conflict: {:replace_all_except, [:id, :inserted_at]},
|
||||
on_conflict:
|
||||
{:replace,
|
||||
[
|
||||
:start_ip_int,
|
||||
:end_ip_int,
|
||||
:geoname_id,
|
||||
:registered_country_geoname_id,
|
||||
:updated_at
|
||||
]},
|
||||
conflict_target: :network
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -226,20 +226,6 @@ defmodule Towerops.Snmp.MibTranslatorTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "uses fallback for ENTITY-SENSOR-MIB OIDs" do
|
||||
sensor_oids = [
|
||||
{"ENTITY-SENSOR-MIB::entPhySensorType", "1.3.6.1.2.1.99.1.1.1.1"},
|
||||
{"ENTITY-SENSOR-MIB::entPhySensorValue", "1.3.6.1.2.1.99.1.1.1.4"},
|
||||
{"ENTITY-SENSOR-MIB::entPhySensorOperStatus", "1.3.6.1.2.1.99.1.1.1.5"}
|
||||
]
|
||||
|
||||
Enum.each(sensor_oids, fn {mib_name, expected_oid} ->
|
||||
result = MibTranslator.translate(mib_name)
|
||||
assert {:ok, oid} = result
|
||||
assert String.contains?(oid, expected_oid)
|
||||
end)
|
||||
end
|
||||
|
||||
test "uses fallback for UCD-SNMP-MIB OIDs (Linux memory)" do
|
||||
# Note: expected OIDs are base OIDs without instance suffix
|
||||
# snmptranslate returns base OID when input doesn't have instance suffix
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue