Receives webhooks from MikroTik RouterOS when devices come online, extracts MAC/IP data, and reconciles with Gaiia inventory.
63 lines
2.2 KiB
Elixir
63 lines
2.2 KiB
Elixir
defmodule Towerops.Repo.Migrations.CreateMikrotikWebhookTables do
|
|
use Ecto.Migration
|
|
|
|
def change do
|
|
create table(:mikrotik_events, primary_key: false) do
|
|
add :id, :binary_id, primary_key: true
|
|
|
|
add :organization_id,
|
|
references(:organizations, type: :binary_id, on_delete: :delete_all),
|
|
null: false
|
|
|
|
add :source, :string, null: false
|
|
add :event_type, :string, null: false
|
|
add :router, :string
|
|
add :mac, :string
|
|
add :ip, :string
|
|
add :username, :string
|
|
add :host, :string
|
|
add :server, :string
|
|
add :remote_id, :string
|
|
add :raw_payload, :map, null: false
|
|
add :resolved_account_id, :string
|
|
add :resolved_via, :string
|
|
add :received_at, :utc_datetime_usec, null: false
|
|
|
|
timestamps(type: :utc_datetime, updated_at: false)
|
|
end
|
|
|
|
create index(:mikrotik_events, [:organization_id, :received_at])
|
|
create index(:mikrotik_events, [:organization_id, :ip])
|
|
create index(:mikrotik_events, [:organization_id, :mac])
|
|
create index(:mikrotik_events, [:organization_id, :username])
|
|
|
|
create table(:mikrotik_ip_assignments, primary_key: false) do
|
|
add :id, :binary_id, primary_key: true
|
|
|
|
add :organization_id,
|
|
references(:organizations, type: :binary_id, on_delete: :delete_all),
|
|
null: false
|
|
|
|
add :ip, :string, null: false
|
|
add :mac, :string
|
|
add :source, :string, null: false
|
|
add :router, :string
|
|
add :username, :string
|
|
add :host, :string
|
|
add :gaiia_account_id, :string
|
|
add :gaiia_inventory_item_id, :string
|
|
add :account_name, :string
|
|
add :resolved_via, :string
|
|
add :first_seen_at, :utc_datetime_usec, null: false
|
|
add :last_seen_at, :utc_datetime_usec, null: false
|
|
add :is_active, :boolean, default: true, null: false
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
create unique_index(:mikrotik_ip_assignments, [:organization_id, :ip])
|
|
create index(:mikrotik_ip_assignments, [:organization_id, :mac])
|
|
create index(:mikrotik_ip_assignments, [:organization_id, :gaiia_account_id])
|
|
create index(:mikrotik_ip_assignments, [:organization_id, :is_active])
|
|
end
|
|
end
|