Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Database Schema Reference

μNet uses a SQLite database with SeaORM for data persistence. The schema is designed with a clear separation between desired state (user-configured network topology) and derived state (real-time data from SNMP polling).

Overview

The database consists of two main categories of tables:

  • Desired State Tables: Store user-defined network topology and configuration
  • Derived State Tables: Store real-time operational data collected via SNMP

This separation ensures that configuration remains stable while allowing operational data to be updated frequently.

Core Tables

Locations

Physical or logical locations for organizing network devices in a hierarchical structure.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEY, NOT NULLUnique identifier
nameTEXTNOT NULLHuman-readable location name
typeTEXTNOT NULLType of location (datacenter, building, floor, rack, etc.)
pathTEXTNOT NULL, UNIQUEHierarchical path for tree navigation
parent_idTEXTFOREIGN KEYReference to parent location
descriptionTEXTOptional description
addressTEXTPhysical address or location details
coordinatesTEXTGPS coordinates or position data
custom_dataTEXTJSON string for custom attributes
created_atTEXTNOT NULL, DEFAULT CURRENT_TIMESTAMPCreation timestamp
updated_atTEXTNOT NULL, DEFAULT CURRENT_TIMESTAMPLast update timestamp

Indexes:

  • idx_location_path (unique on path)
  • idx_location_parent (on parent_id)

Nodes

Network devices and their static configuration attributes.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEY, NOT NULLUnique identifier
nameTEXTNOT NULLNode name (typically hostname)
fqdnTEXTFully qualified domain name
domainTEXTDNS domain
vendorTEXTNOT NULLDevice vendor (see Vendor enum)
modelTEXTNOT NULLDevice model number
roleTEXTNOT NULLDevice role (see DeviceRole enum)
lifecycleTEXTNOT NULLLifecycle stage (see Lifecycle enum)
serial_numberTEXTDevice serial number
asset_tagTEXTAsset tag for inventory tracking
location_idTEXTFOREIGN KEYReference to location
management_ipTEXTPrimary management IP address
descriptionTEXTOptional description
custom_dataTEXTJSON string for custom attributes
created_atTEXTNOT NULL, DEFAULT CURRENT_TIMESTAMPCreation timestamp
updated_atTEXTNOT NULL, DEFAULT CURRENT_TIMESTAMPLast update timestamp

Indexes:

  • idx_node_name (on name)
  • idx_node_fqdn (on fqdn)
  • idx_node_location (on location_id)
  • idx_node_role (on role)
  • idx_node_lifecycle (on lifecycle)

Network connections between devices, including both internal links and internet circuits.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEY, NOT NULLUnique identifier
nameTEXTNOT NULLHuman-readable link name
node_a_idTEXTNOT NULL, FOREIGN KEYReference to first node (required)
interface_aTEXTNOT NULLInterface name on first node
node_b_idTEXTFOREIGN KEYReference to second node (optional for internet circuits)
interface_bTEXTInterface name on second node
capacityBIGINTLink capacity in bits per second
utilizationREALCurrent utilization as percentage (0.0-1.0)
is_internet_circuitINTEGERNOT NULL, DEFAULT 0Whether this is an internet circuit (1) or internal link (0)
circuit_idTEXTProvider circuit identifier
providerTEXTService provider name
descriptionTEXTOptional description
custom_dataTEXTJSON string for custom attributes
created_atTEXTNOT NULL, DEFAULT CURRENT_TIMESTAMPCreation timestamp
updated_atTEXTNOT NULL, DEFAULT CURRENT_TIMESTAMPLast update timestamp

Indexes:

  • idx_link_name (on name)
  • idx_link_node_a (on node_a_id)
  • idx_link_node_b (on node_b_id)
  • idx_link_circuit_id (on circuit_id)

Vendors

List of supported network equipment vendors.

ColumnTypeConstraintsDescription
nameTEXTPRIMARY KEY, NOT NULLVendor name

Seeded vendors include Cisco, Juniper, Arista, and others. Use the CLI to manage the list:

# List vendors
unet vendors list
# Add vendor
unet vendors add CustomVendor
# Remove vendor
unet vendors delete CustomVendor

Derived State Tables

Node Status

Real-time operational status and metrics for network nodes, populated by SNMP polling.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEY, NOT NULLUnique identifier
node_idTEXTNOT NULL, FOREIGN KEYReference to node table
last_updatedTEXTNOT NULLTimestamp of last status update
reachableBOOLEANNOT NULL, DEFAULT falseWhether node is reachable via SNMP
system_infoTEXTJSON containing system information (uptime, name, description)
performanceTEXTJSON containing performance metrics (CPU, memory)
environmentalTEXTJSON containing environmental data (temperature, fans)
vendor_metricsTEXTJSON containing vendor-specific metrics
raw_snmp_dataTEXTJSON containing raw SNMP response data
last_snmp_successTEXTTimestamp of last successful SNMP poll
last_errorTEXTLast error message encountered during polling
consecutive_failuresINTEGERNOT NULL, DEFAULT 0Number of consecutive failed polling attempts

Indexes:

  • idx_node_status_node_id (unique on node_id)
  • idx_node_status_last_updated (on last_updated)

Interface Status

Per-interface operational data and statistics from SNMP interface tables.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEY, NOT NULLUnique identifier
node_status_idTEXTNOT NULL, FOREIGN KEYReference to node_status table
indexINTEGERNOT NULLInterface index from SNMP ifTable
nameTEXTNOT NULLInterface name or description
typeINTEGERNOT NULLInterface type code from SNMP ifType
mtuINTEGERMaximum transmission unit in bytes
speedBIGINTInterface speed in bits per second
physical_addressTEXTPhysical MAC address of the interface
admin_statusTEXTNOT NULL, DEFAULT 'unknown'Administrative status (up/down/testing)
oper_statusTEXTNOT NULL, DEFAULT 'unknown'Operational status (up/down/testing/unknown/dormant/notPresent/lowerLayerDown)
last_changeINTEGERTime when interface last changed state
input_statsTEXTNOT NULLJSON containing input statistics (packets, bytes, errors)
output_statsTEXTNOT NULLJSON containing output statistics (packets, bytes, errors)

Indexes:

  • idx_interface_status_node_status_id (on node_status_id)
  • idx_interface_status_index (unique on node_status_id, index)

Polling Tasks

Configuration for SNMP polling tasks that collect operational data.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEY, NOT NULLUnique identifier
node_idTEXTNOT NULL, FOREIGN KEYReference to node table
targetTEXTNOT NULLSNMP target address or hostname
oidsTEXTNOT NULLJSON array of OIDs to poll
interval_secondsBIGINTNOT NULLPolling interval in seconds
session_configTEXTNOT NULLJSON containing SNMP session configuration
prioritySMALLINTNOT NULL, DEFAULT 128Task priority for scheduling
enabledBOOLEANNOT NULL, DEFAULT trueWhether task is currently enabled
created_atTEXTNOT NULLTask creation timestamp
last_successTEXTTimestamp of last successful poll
last_errorTEXTLast error message from polling
consecutive_failuresINTEGERNOT NULL, DEFAULT 0Number of consecutive failed polls

Indexes:

  • idx_polling_tasks_node_id (on node_id)
  • idx_polling_tasks_enabled (on enabled)

Enumerations

Device Role

Defines the network function of a device:

  • router - Network router
  • switch - Network switch
  • firewall - Firewall device
  • loadbalancer - Load balancer
  • accesspoint - Wireless access point
  • securityappliance - Network security appliance
  • monitor - Network monitoring device
  • server - Generic server
  • storage - Storage device
  • other - Other/unspecified device type

Lifecycle

Defines the operational state of a device:

  • planned - Device is planned but not yet deployed
  • implementing - Device is currently being implemented/deployed
  • live - Device is live and operational
  • decommissioned - Device is being decommissioned or is decommissioned

Vendor

Supported network equipment vendors:

  • cisco - Cisco Systems
  • juniper - Juniper Networks
  • arista - Arista Networks
  • paloalto - Palo Alto Networks
  • fortinet - Fortinet
  • hpe - HPE/Hewlett Packard Enterprise
  • dell - Dell Technologies
  • extreme - Extreme Networks
  • mikrotik - Mikrotik
  • ubiquiti - Ubiquiti
  • generic - Generic/unknown vendor

Schema Design Patterns

Primary Keys

All tables use text-based UUIDs as primary keys to ensure global uniqueness and enable distributed scenarios.

JSON Storage

Complex or flexible data is stored as JSON strings in columns like custom_data, system_info, and statistics fields. This allows for extensibility without schema changes.

Timestamps

All timestamps are stored as text in ISO 8601 format for consistency and readability.

Foreign Key Relationships

The schema maintains referential integrity through foreign key relationships:

  • Nodes → Locations (optional)
  • Links → Nodes (A-side required, B-side optional)
  • Node Status → Nodes (one-to-one)
  • Interface Status → Node Status (one-to-many)
  • Polling Tasks → Nodes (one-to-many)

Indexing Strategy

Indexes are created on:

  • Foreign key columns for efficient joins
  • Frequently queried columns (names, roles, status)
  • Unique constraints where needed

Usage Considerations

Data Separation

The schema enforces separation between:

  • Configuration data (locations, nodes, links) - changes infrequently
  • Operational data (status tables) - updated frequently via SNMP

Extensibility

Custom fields can be added via:

  • custom_data JSON columns on core entities
  • Additional OIDs in polling tasks
  • Vendor-specific metrics in status tables

Performance

  • Derived state tables are optimized for frequent updates
  • Indexes support common query patterns
  • JSON storage provides flexibility without normalization overhead

Missing Fields?

If you need additional fields for your network automation use case, consider:

  1. Custom Data Fields: Use the custom_data JSON columns for entity-specific extensions
  2. New Enums: Extend the vendor, role, or lifecycle enums if needed
  3. Additional Tables: For complex relationships not covered by existing schema
  4. SNMP Extensions: Add new OIDs to polling tasks for additional metrics

Open a pull request with your proposed schema changes and use cases to help expand μNet's capabilities.