Skip to main content

Overview

The NMISNG::Node module represents a single network node in NMIS. It provides methods for node configuration, inventory access, event management, and status reporting. Version: 9.6.5 Location: lib/NMISNG/Node.pm

Constructor

new()

Creates a new Node object.
nmisng
NMISNG
required
NMISNG parent object
uuid
string
required
Node UUID (required for all nodes)
_id
ObjectId
MongoDB _id if loading existing node
use NMISNG::Node;

# Create new node
my $node = NMISNG::Node->new(
    nmisng => $nmisng,
    uuid => "abc-123-def-456"
);

# Load existing node
my $node = NMISNG::Node->new(
    nmisng => $nmisng,
    uuid => "abc-123-def-456",
    _id => $existing_id
);
node
NMISNG::Node
Returns Node object, or undef on error
Password encryption/decryption is handled automatically based on the global_enable_password_encryption configuration setting.

Configuration Methods

configuration()

Get or set node configuration.
newvalue
hash
Optional new configuration hash. If provided, marks node as dirty requiring save()
# Get configuration
my $config = $node->configuration();
print "Node type: $config->{nodeType}\n";
print "Group: $config->{group}\n";

# Set configuration
my $config = $node->configuration();
$config->{group} = "Distribution";
$config->{collect} = 1;
$node->configuration($config);
$node->save();
configuration
hash
Clone of current configuration hash
Common Configuration Properties:
  • active (0/1) - Node is active
  • collect (0/1) - Enable data collection
  • ping (0/1) - Enable ping monitoring
  • snmp (0/1) - Enable SNMP collection
  • nodeType (string) - Node type (router, switch, server)
  • roleType (string) - Node role (core, distribution, access)
  • group (string) - Node group
  • host (string) - Hostname or IP address
  • community (string) - SNMP community string
  • port (integer) - SNMP port (default 161)
  • version (string) - SNMP version (snmpv1, snmpv2c, snmpv3)
  • threshold (0/1) - Enable thresholding
  • polling_policy (string) - Polling policy name

name()

Get node name (read-only after initial set).
my $name = $node->name();
print "Node: $name\n";
name
string
Node name
To rename a node, use the rename() method instead of setting name directly.

uuid()

Get node UUID (read-only).
my $uuid = $node->uuid();
uuid
string
Node UUID

cluster_id()

Get or set cluster ID.
newvalue
string
New cluster ID (marks node as dirty)
my $cluster_id = $node->cluster_id();

# Set cluster ID
$node->cluster_id("cluster-west");
$node->save();
cluster_id
string
Current cluster ID

activated()

Get or set node activation status per product.
newstate
hash
Hash of product names => 0/1 (e.g., {NMIS => 1, opCharts => 1})
# Get activation status
my $activated = $node->activated();
if ($activated->{NMIS}) {
    print "Node is activated for NMIS\n";
}

# Activate for NMIS
$activated->{NMIS} = 1;
$node->activated($activated);
$node->save();
activated
hash
Clone of activation state hash

is_active()

Check if node is configured to be active.
if ($node->is_active) {
    print "Node is active\n";
}
active
boolean
Returns 1 if active, 0 otherwise

Node Status

coarse_status()

Returns overall node status.
catchall_data
hash
Optional catchall inventory data (avoids lookup if provided)
my $status = $node->coarse_status();

if ($status == 1) {
    print "Node is reachable\n";
} elsif ($status == 0) {
    print "Node is unreachable\n";
} elsif ($status == -1) {
    print "Node is degraded\n";
}
status
integer
Returns 1 (reachable), 0 (unreachable), or -1 (degraded)

precise_status()

Returns detailed status information.
my %status = $node->precise_status();

print "Overall: $status{overall}\n";
print "Ping enabled: $status{ping_enabled}\n";
print "Ping status: $status{ping_status}\n" if defined $status{ping_status};
print "SNMP enabled: $status{snmp_enabled}\n";
print "SNMP status: $status{snmp_status}\n" if defined $status{snmp_status};
status
hash
Hash with keys:
  • overall (integer): 1 reachable, 0 down, -1 degraded
  • ping_enabled (0/1)
  • ping_status (0/1/undef)
  • snmp_enabled (0/1)
  • snmp_status (0/1/undef)
  • wmi_enabled (0/1)
  • wmi_status (0/1/undef)
  • failover_status (0/1/undef)
  • primary_ping_status (0/1/undef)
  • failover_ping_status (0/1/undef)

Inventory Operations

inventory()

Find or create inventory object for this node.
concept
string
required
Inventory concept (e.g., “interface”, “service”, “catchall”)
data
hash
Inventory data
path
array
Inventory path
path_keys
array
Keys to use for path construction
create
boolean
default:"0"
Create inventory if not found
# Get catchall inventory
my ($catchall_inv, $error) = $node->inventory(concept => "catchall");
if ($error) {
    die "Failed: $error";
}
my $data = $catchall_inv->data();

# Find or create interface inventory
my ($intf_inv, $error) = $node->inventory(
    concept => "interface",
    data => {index => "1", ifDescr => "GigabitEthernet0/0"},
    path_keys => ['index'],
    create => 1
);
inventory
NMISNG::Inventory
Returns (inventory_object, undef) on success, (undef, error_message) on error, or (undef, undef) if not found and create not specified

get_inventory_model()

Get inventory model for this node.
concept
string
Filter by concept
filter
hash
Additional filter criteria
class_name
hash
Class instantiation mapping
my $inv_model = $node->get_inventory_model(
    concept => "interface",
    filter => {enabled => 1, historic => 0}
);

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

foreach my $inv_data (@{$inv_model->data}) {
    print "Interface: $inv_data->{data}{ifDescr}\n";
}
model
NMISNG::ModelData
ModelData object with inventory records

get_inventory_ids()

Get list of inventory IDs for this node.
concept
string
Filter by concept
my $inv_ids = $node->get_inventory_ids(concept => "interface");
foreach my $id (@$inv_ids) {
    print "Inventory ID: $id\n";
}
ids
array
Array reference of inventory IDs (may be empty)

inventory_concepts()

Get list of all inventory concepts for this node.
my ($concepts, $error) = $node->inventory_concepts();
if ($error) {
    die "Failed: $error";
}

foreach my $concept (@$concepts) {
    print "Concept: $concept\n";
}
concepts
array
Returns (arrayref, undef) on success, (undef, error) on failure

Event Operations

event()

Create an event object for this node.
event
string
Event name
element
string
Event element (optional)
level
string
Event level (Normal, Warning, Minor, Major, Critical, Fatal)
details
string
Event details
my $event = $node->event(
    event => "Node Down",
    level => "Major",
    details => "Node not responding to ping"
);
event
NMISNG::Event
NMISNG::Event object

eventAdd()

Add an event for this node.
my $error = $node->eventAdd(
    event => "Interface Down",
    element => "GigabitEthernet0/0",
    level => "Major",
    details => "Interface operationally down"
);

if ($error) {
    print "Failed to add event: $error\n";
}
error
string
Returns undef on success, error message on failure

eventExist()

Check if an event exists for this node.
event
string
required
Event name
element
string
Event element (optional)
if ($node->eventExist("Node Down")) {
    print "Node Down event is active\n";
}

if ($node->eventExist("Interface Down", "GigabitEthernet0/0")) {
    print "Interface is down\n";
}
exists
mixed
Returns event record (hashref) if exists and is active, 0/undef otherwise

eventLoad()

Load detailed event information.
my ($error, $event) = $node->eventLoad(
    event => "Node Down",
    element => ""
);

if (!$error && $event) {
    print "Event started: " . localtime($event->startdate) . "\n";
}
result
tuple
Returns (error, event_object)

get_events_model()

Get events model for this node.
filter
hash
Additional filter criteria (e.g., {historic => 0, active => 1})
my $events_model = $node->get_events_model(
    filter => {historic => 0, active => 1}
);

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

print "Active events: " . $events_model->count . "\n";
model
NMISNG::ModelData
ModelData object with event records

eventsClean()

Clean all events for this node.
caller
string
Caller identifier for logging
my $error = $node->eventsClean("admin_cleanup");
if ($error) {
    print "Failed to clean events: $error\n";
}
error
string
Returns undef on success, error message on failure

Node Lifecycle

save()

Save node configuration to database.
my ($op, $error) = $node->save();

if ($op > 0) {
    print "Node saved successfully\n";
} elsif ($op == 0) {
    print "Node unchanged\n";
} else {
    print "Save failed: $error\n";
}
result
tuple
Returns (operation_count, error_message). operation_count is 1 for success, 0 for no changes, -1 for error

delete()

Delete node and clean up all associated data.
keep_rrd
boolean
default:"0"
Keep RRD files (don’t delete them)
meta
hash
Metadata for audit logging (who, where, how, details)
my ($success, $message) = $node->delete(
    keep_rrd => 0,
    meta => {
        who => "admin",
        where => "web_ui",
        how => "delete_button",
        details => "Decommissioned device"
    }
);

if ($success) {
    print "Node deleted\n";
} else {
    print "Delete failed: $message\n";
}
result
tuple
Returns (success, message) or (0, error_message)
Deletes node configuration, all inventories, timed data, events, opstatus entries, and optionally RRD files. Deactivates node first if active.

rename()

Rename node and update all file references.
new_name
string
required
New node name
server
string
Server name for remote nodes
is_local
boolean
default:"1"
Whether this is a local node
my ($success, $message) = $node->rename(
    new_name => "router01-new",
    is_local => 1
);

if ($success) {
    print "Node renamed successfully\n";
} else {
    print "Rename failed: $message\n";
}
result
tuple
Returns (success, message) or (0, error_message)
Renames node, relocates RRD files, updates inventories. Cannot rename if name contains ’/’ or doesn’t match node_name_rule regex. Events are deleted (cannot be renamed sensibly).

is_new()

Check if node is new (not yet saved to database).
if ($node->is_new) {
    print "Node hasn't been saved yet\n";
}
is_new
boolean
Returns 1 if new, 0 if exists in database

Additional Methods

aliases()

Get or set node aliases.
my $aliases = $node->aliases();
# Returns array of hashes: [{alias => "router-backup"}, ...]

$node->aliases([{alias => "rtr01-pri"}, {alias => "router-main"}]);
$node->save();

addresses()

Get or set node addresses.
my $addresses = $node->addresses();
# Returns array of hashes: [{address => "10.1.1.1"}, ...]

comments()

Get or set node comments.
my $comments = $node->comments();
# Returns array of arrays: [[timestamp, user, comment], ...]

$comments = $node->comments();
push @$comments, [time, "admin", "Updated configuration"];
$node->comments($comments);
$node->save();

overrides()

Get or set configuration overrides.
my $overrides = $node->overrides();
$overrides->{ifSpeed_eth0} = 1000000000;
$node->overrides($overrides);
$node->save();

lastupdate()

Get last update timestamp.
my $timestamp = $node->lastupdate();
print "Last updated: " . localtime($timestamp) . "\n";
timestamp
integer
Unix timestamp of last update

See Also

Build docs developers (and LLMs) love