App-Netsync
view release on metacpan or search on metacpan
lib/App/Netsync.pm view on Meta::CPAN
}
# Search for network devices and interfaces that were not identified in the database.
foreach my $ip (sort keys %$nodes) {
my $node = $nodes->{$ip};
foreach my $serial (sort keys %{$node->{'devices'}}) {
my $device = $node->{'devices'}{$serial};
unless ($device->{'identified'}) {
note ($config{'ConflictLog'},device_string ($device).' unidentified');
next;
}
foreach my $ifName (sort keys %{$device->{'interfaces'}}) {
my $interface = $device->{'interfaces'}{$ifName};
unless ($interface->{'identified'}) {
note ($config{'ConflictLog'},interface_string ($interface).' unidentified');
next;
}
}
}
}
}
################################################################################
=head2 update
push information to interfaces
B<Arguments>
I<( \%nodes )>
=over 3
=item nodes
the nodes to update
=back
B<Example>
C<update $nodes;>
Table
---------------------------------------------------------
| DeviceField | InterfaceField | InfoFields... |
--------------------------------------------------------- =============
| (serial) | (ifName) |(interface-specific)| --> || SyncOID ||
| ... | =============
--------------------------------------------------------- (device)
=cut
sub update {
warn 'too few arguments' if @_ < 1;
warn 'too many arguments' if @_ > 1;
my ($nodes) = @_;
unless ($config{'Quiet'}) {
print 'updating';
print ' (using '.$config{'SyncOID'}.')...';
print (($config{'Verbose'}) ? "\n" : (' 'x$config{'DeviceOrder'}).'0');
}
my ($successful_update_count,$failed_update_count) = (0,0);
foreach my $ip (keys %$nodes) {
my $node = $nodes->{$ip};
foreach my $serial (keys %{$node->{'devices'}}) {
my $device = $node->{'devices'}{$serial};
next unless $device->{'identified'}; # Only update identified devices.
foreach my $ifName (keys %{$device->{'interfaces'}}) {
my $interface = $device->{'interfaces'}{$ifName};
next unless $interface->{'identified'}; # Only update identified interfaces.
# Format the info to be pushed.
my $update = '';
my $empty = 1;
foreach my $field (sort keys %{$interface->{'info'}}) {
$update .= "," unless $update eq '';
$update .= $field.':'.$interface->{'info'}{$field};
$empty = 0 if defined $interface->{'info'}{$field} and $interface->{'info'}{$field} =~ /[\S]+/;
}
$update = '' if $empty;
my $note = interface_string ($interface).' ('.$interface->{'IID'}.')';
my $error = App::Netsync::SNMP::set ($config{'SyncOID'},$interface->{'IID'},$update,$node->{'session'});
unless ($error) { # Log a successful update.
$update =~ s/\n/,/g;
$update =~ s/\s+//g;
$update =~ s/:,/:(empty),/g;
note ($config{'UpdateLog'},$note.' '.$update);
++$successful_update_count;
unless ($config{'Quiet'}) {
if ($config{'Verbose'}) {
interface_dump $interface;
}
else {
print "\b"x$config{'DeviceOrder'};
printf ('%'.$config{'DeviceOrder'}.'d',$successful_update_count);
}
}
}
else { # Log a failed update.
note ($config{'UpdateLog'},$note.' error: '.$error);
++$failed_update_count;
if ($config{'Verbose'}) {
say interface_string ($interface).' failed';
say ((' 'x$config{'Indent'}).$error);
}
}
}
( run in 1.040 second using v1.01-cache-2.11-cpan-2398b32b56e )