Overview
TheNMISNG::Inventory module is the base class for managing network device inventory in NMIS. It handles storage, time-series data, datasets, and provides specialized subclasses for different inventory types.
Version: 1.1.0
Location: lib/NMISNG/Inventory.pm
Inventory Types
NMIS uses different inventory classes for different concepts:- DefaultInventory - Generic inventory items (most concepts)
- InterfaceInventory - Network interface specific operations
- ServiceInventory - Service monitoring inventory
Constructor
new()
Creates a new inventory object. Typically called via$node->inventory() rather than directly.
Inventory concept (e.g., “interface”, “service”, “catchall”, “storage”)
NMISNG parent object
Node UUID this inventory belongs to
Cluster ID
Inventory data
Inventory path (unique identifier)
Keys used to construct path from data
Whether inventory is enabled for collection
Whether inventory is historic (no longer present on device)
Storage paths by subconcept (e.g.,
{interface => "/nodes/router01/interface-eth0.rrd"})Human-readable description
Returns inventory object or undef on error
Data Access Methods
data()
Get or set inventory data.New data hash (marks inventory as dirty)
Clone of inventory data hash
Returns a clone of the data - modifications must be saved back using
data($modified) then save().data_live()
Get direct reference to data (not a clone).Direct reference to data hash (not cloned)
Use
data_live() when making multiple changes or for read-only access to avoid cloning overhead. Once called, the object automatically tracks changes and marks itself dirty.description()
Get or set inventory description.Current description
Property Accessors
concept()
Get inventory concept (read-only).Inventory concept
node_uuid()
Get owning node UUID (read-only).Node UUID
cluster_id()
Get cluster ID (read-only).Cluster ID
id()
Get inventory MongoDB ID (read-only).MongoDB _id, or undef if not saved
enabled()
Get or set enabled status.New enabled status (0 or 1)
Returns 1 if enabled, 0 if disabled
historic()
Get or set historic status.New historic status (0 or 1)
Returns 1 if historic, 0 if current
is_new()
Check if inventory is new (not yet saved).Returns 1 if new, 0 if saved
lastupdate()
Get last update timestamp.Unix timestamp or undef if not saved
Time-Series Data
add_timed_data()
Add point-in-time data for this inventory.Data hash with dataset values
Derived/calculated data hash
Subconcept name (required if datasets not provided)
Dataset structure:
{subconcept => {dataset1 => 1, dataset2 => 1}}Unix timestamp (defaults to current time)
Delay database insert until save() called
Returns undef on success, error message on failure
Data is automatically stored in both timed collection (for historical queries) and latest_data collection (for current state lookups).
get_newest_timed_data()
Retrieve the most recent timed data.Get from timed collection instead of latest_data cache
Hash with:
success(boolean)data(hash) - Data by subconceptderived_data(hash) - Derived data by subconcepttime(integer) - Timestamperror(string) - Error message if failed
Dataset Management
dataset_info()
Get or set dataset information for a subconcept.Subconcept name
Hash of dataset names => 1
Hash of dataset names (keys) with value 1, or empty hash
data_info()
Get or set data display information for a subconcept.Subconcept name
Whether subconcept display is enabled
Array of data keys to display
Hash with
enabled (boolean) and display_keys (array), or error stringStorage Management
storage()
Get or set storage paths.Hash of subconcept => storage_info
Clone of storage structure
find_subconcept_type_storage()
Look up storage path for a specific subconcept and type.Subconcept name
Storage type
Storage path or undef if not found
set_subconcept_type_storage()
Set storage path for a subconcept and type.Subconcept name
Storage type
Storage path (undef to delete)
Path Management
path()
Get or recalculate inventory path.Force path recalculation
Returns arrayref on success, error string on failure
path_keys()
Get or set path keys.New path keys array
Clone of path keys array
Inventory Lifecycle
save()
Save inventory to database.Node object (required for new inventory)
Returns (operation_count, error_message). operation_count is 1 for success, 0 for no changes, -1 for error
delete()
Delete inventory and associated data.Keep RRD files (don’t delete them)
Returns (success, message) or (0, error_message)
Deletes inventory record, all timed data, latest data, and RRD files (unless keep_rrd is true).
reload()
Reload inventory from database.Returns undef on success, error message on failure
Interface Inventory
TheInterfaceInventory class provides additional methods for network interfaces.
Interface-Specific Accessors
Interface Speed Methods
Service Inventory
TheServiceInventory class is used for service monitoring.
Service-Specific Features
ServiceInventory automatically generates a deterministic UUID from the service name and node UUID.
Utility Functions
get_inventory_class()
Get the appropriate inventory class for a concept (class method).Perl class name for the concept
See Also
- NMISNG - Core NMISNG library
- NMISNG::Node - Node operations
- NMISNG::Sys - System operations and SNMP