Skip to main content

Overview

The NMISNG module is the central library for NMIS network management operations. It provides access to nodes, events, inventory, and database operations. This is the main entry point for interacting with the NMIS system. Version: 9.6.5 Location: lib/NMISNG.pm

Constructor

new()

Creates a new NMISNG object instance.
config
hash
required
Configuration hash containing NMIS configuration
log
NMISNG::Log
required
NMISNG::Log object for logging
db
MongoDB::Database
MongoDB database object. If not provided, automatically connects to database using configuration
drop_unwanted_indices
boolean
default:"0"
Whether to drop unwanted database indices during initialization
existing_timed_collections
hash
List of existing timed collections (created dynamically). Hash of collection name => 1
tests
hash
Test collection names for running tests. Specify with keys like nodes_test_collection, events_test_collection
use NMISNG;
use NMISNG::Log;

my $config = NMISNG::Util::loadConfTable();
my $log = NMISNG::Log->new(level => "info");

my $nmisng = NMISNG->new(
    config => $config,
    log => $log,
    drop_unwanted_indices => 0
);
nmisng
NMISNG
Returns NMISNG object on success, dies on error

Core Methods

config()

Returns the configuration hash.
my $config = $nmisng->config();
my $db_name = $config->{db_name};
config
hash
Configuration hash reference

log()

Returns the log object.
$nmisng->log->info("Starting operation");
$nmisng->log->error("Failed to connect: $error");
log
NMISNG::Log
NMISNG::Log object

Node Operations

get_nodes_model()

Retrieves nodes based on filter criteria.
filter
hash
Filter criteria (e.g., {"activated.NMIS" => 1, group => "Distribution"})
fields_hash
hash
Specify which fields to return (e.g., {uuid => 1, name => 1})
sort
hash
Sort criteria (e.g., {name => 1} for ascending)
skip
integer
Number of records to skip (pagination)
limit
integer
Maximum number of records to return
# Get all active nodes
my $nodes_model = $nmisng->get_nodes_model(
    filter => {"activated.NMIS" => 1}
);

if (my $error = $nodes_model->error) {
    die "Failed to get nodes: $error";
}

foreach my $node_data (@{$nodes_model->data}) {
    print "Node: $node_data->{name}\n";
}
model
NMISNG::ModelData
ModelData object containing node records. Check ->error for errors, ->count for number of results, ->data for array of records

node()

Retrieve or create a node object.
uuid
string
Node UUID (for existing node)
name
string
Node name (alternative to UUID)
filter
hash
Filter criteria to find node
# Get node by UUID
my $node = $nmisng->node(uuid => "abc-123-def");

# Get node by name
my $node = $nmisng->node(filter => {name => "router01"});

# Check node exists
if ($node && !$node->is_new) {
    print "Node name: " . $node->name . "\n";
}
node
NMISNG::Node
NMISNG::Node object or undef if not found

get_node_names()

Retrieve node names by UUID.
my $names = $nmisng->get_node_names(uuid => "abc-123");
print "Node name: $names->[0]\n";

expand_node_selection()

Expands multiple node selection filters sequentially (f1 OR f2).
selectors
array
Array of filter hashes
my $nodes = $nmisng->expand_node_selection(
    {group => "Core"},
    {roleType => "distribution"}
);
modeldata
NMISNG::ModelData
ModelData object with matching active nodes

Inventory Operations

get_inventory_model()

Retrieve inventory items with filtering.
cluster_id
string
Cluster ID to filter by
node_uuid
string
Node UUID to filter by
concept
string
Inventory concept (e.g., “interface”, “service”, “catchall”)
filter
hash
Additional filter criteria (e.g., {historic => 0, enabled => 1})
class_name
hash
Specify class instantiation mapping (e.g., {concept => \&NMISNG::Inventory::get_inventory_class})
# Get all enabled interfaces for a node
my $inv_model = $nmisng->get_inventory_model(
    node_uuid => $node->uuid,
    concept => "interface",
    filter => {enabled => 1, historic => 0}
);

if (my $error = $inv_model->error) {
    die "Failed: $error";
}

print "Found " . $inv_model->count . " interfaces\n";
model
NMISNG::ModelData
ModelData object with inventory records

Event Operations

events()

Returns the events manager object.
my $events = $nmisng->events();
events
NMISNG::Events
NMISNG::Events object for event operations

get_events_model()

Retrieve events based on filter criteria.
filter
hash
Filter criteria (e.g., {node_uuid => $uuid, historic => 0, active => 1})
my $events_model = $nmisng->get_events_model(
    filter => {
        node_uuid => $node->uuid,
        historic => 0,
        active => 1
    }
);

foreach my $event (@{$events_model->data}) {
    print "Event: $event->{event}, Level: $event->{level}\n";
}
model
NMISNG::ModelData
ModelData object with event records

Threshold and Metrics

compute_thresholds()

Computes thresholds for a node.
sys
NMISNG::Sys
required
Sys object for the node
running_independently
boolean
default:"0"
Whether running standalone (affects saving behavior)
force
boolean
default:"0"
Force threshold computation even if node is down
my $S = NMISNG::Sys->new(nmisng => $nmisng);
$S->init(node => $node, snmp => 0);

$nmisng->compute_thresholds(
    sys => $S,
    running_independently => 1
);

compute_all_thresholds()

Computes thresholds for all active nodes.
$nmisng->compute_all_thresholds();

compute_metrics()

Computes overall network metrics for all nodes/groups.
my $result = $nmisng->compute_metrics();
if ($result->{success}) {
    print "Metrics computed successfully\n";
}
result
hash
Hash with success (boolean) and optional error (string)

Database Maintenance

dbcleanup()

Removes orphaned database records.
simulate
boolean
default:"0"
Simulate cleanup without actually removing records
my $result = $nmisng->dbcleanup(simulate => 1);
if ($result->{success}) {
    foreach my $msg (@{$result->{info}}) {
        print "$msg\n";
    }
}
result
hash
Hash with success (boolean), error (string if failed), and info (array of messages)

config_backup()

Creates a backup of NMIS configuration.
my $result = $nmisng->config_backup();
if ($result->{success}) {
    print "Backup created: $result->{file}\n";
} else {
    print "Backup failed: $result->{error}\n";
}
result
hash
Hash with success (boolean), optional error (string), and file (backup file path)

Collection Accessors

The following methods return MongoDB collection handles:
  • nodes_collection() - Nodes collection
  • events_collection() - Events collection
  • inventory_collection() - Inventory collection
  • latest_data_collection() - Latest data collection
  • queue_collection() - Job queue collection
  • opstatus_collection() - Operational status collection
  • status_collection() - Status collection
my $nodes_coll = $nmisng->nodes_collection();
my $events_coll = $nmisng->events_collection();

Utility Methods

get_group_names()

Returns list of all group names.
my @groups = $nmisng->get_group_names();
foreach my $group (@groups) {
    print "Group: $group\n";
}

ensure_indexes()

Ensures all database indexes are created.
drop_unwanted
boolean
default:"0"
Whether to drop unwanted indexes
$nmisng->ensure_indexes(drop_unwanted => 0);

Constants

VERSION
string
NMISNG module version

See Also

Build docs developers (and LLMs) love