view release on metacpan or search on metacpan
bin/netdisco-backend-fg view on Meta::CPAN
FindBin::again();
use Path::Class 'dir';
BEGIN {
# stuff useful locations into @INC
unshift @INC,
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
dir($FindBin::RealBin, 'lib')->stringify;
unshift @INC,
split m/:/, ($ENV{NETDISCO_INC} || '');
}
use App::Netdisco;
use Dancer qw/:moose :script/;
BEGIN {
warning sprintf "App::Netdisco %s backend", ($App::Netdisco::VERSION || 'HEAD');
# this can take a few seconds - only do it once
use Net::Domain 'hostfqdn';
bin/netdisco-sshcollector view on Meta::CPAN
BEGIN {
use Path::Class;
# stuff useful locations into @INC and $PATH
unshift @INC,
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
dir($FindBin::RealBin, 'lib')->stringify;
unshift @INC,
split m/:/, ($ENV{NETDISCO_INC} || '');
use Config;
$ENV{PATH} = $FindBin::RealBin . $Config{path_sep} . $ENV{PATH};
}
use App::Netdisco;
use App::Netdisco::Util::Node qw/check_mac store_arp/;
use App::Netdisco::Util::FastResolver 'hostnames_resolve_async';
use Dancer ':script';
bin/netdisco-web-fg view on Meta::CPAN
FindBin::again();
use Path::Class 'dir';
BEGIN {
# stuff useful locations into @INC
unshift @INC,
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
dir($FindBin::RealBin, 'lib')->stringify;
unshift @INC,
split m/:/, ($ENV{NETDISCO_INC} || '');
}
use App::Netdisco;
use Dancer;
BEGIN {
warning sprintf "App::Netdisco %s web", ($App::Netdisco::VERSION || 'HEAD');
}
set plack_middlewares => [
['Plack::Middleware::ReverseProxy'],
lib/App/Netdisco/SSHCollector/Platform/Aruba.pm view on Meta::CPAN
my ($self, $hostlabel, $ssh, $args) = @_;
debug "$hostlabel $$ arpnip()";
my @data = $ssh->capture("show arp");
chomp @data;
my @arpentries;
# 172.16.20.15 00:24:b2:69:86:7d vlan interface state
foreach my $line (@data) {
my @fields = split m/\s+/, $line;
push @arpentries, { mac => $fields[1], ip => $fields[0] };
}
return @arpentries;
}
1;
lib/App/Netdisco/SSHCollector/Platform/IOS.pm view on Meta::CPAN
debug "$hostlabel $$ arpnip()";
my @data = $ssh->capture("show ip arp");
chomp @data;
my @arpentries;
# Internet 172.16.20.15 13 0024.b269.867d ARPA FastEthernet0/0.1
foreach my $line (@data) {
next unless $line =~ m/^Internet/;
my @fields = split m/\s+/, $line;
push @arpentries, { mac => $fields[3], ip => $fields[1] };
}
return @arpentries;
}
sub macsuck {
my ($self, $hostlabel, $ssh, $args) = @_;
lib/App/Netdisco/SSHCollector/Platform/VOSS.pm view on Meta::CPAN
my @arpentries;
my $ipregex = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
my $macregex = '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}';
# IP Address MAC Address VLAN Port Type TTL Tunnel
# 172.16.20.15 0024.b269.867d 100 1/1 DYNAMIC 999 device-name
foreach my $line (@lines) {
next unless $line =~ m/^\s*$ipregex\s+$macregex/;
my @fields = split m/\s+/, $line;
debug "[$hostlabel] arpnip - mac $fields[1] ip $fields[0]";
push @arpentries, { mac => $fields[1], ip => $fields[0] };
}
$expect->send("exit\n");
$expect->soft_close();
return @arpentries;
}
lib/App/Netdisco/Util/SNMP.pm view on Meta::CPAN
C<< $seglen >>, which defaults to 6.
=cut
# take oid and make comparable
sub sortable_oid {
my ($oid, $seglen) = @_;
$seglen ||= 6;
return $oid if $oid !~ m/^[0-9.]+$/;
$oid =~ s/^(\.)//; my $leading = $1;
$oid = join '.', map { sprintf("\%0${seglen}d", $_) } (split m/\./, $oid);
return (($leading || '') . $oid);
}
true;
lib/App/Netdisco/Util/Snapshot.pm view on Meta::CPAN
my $value = (defined $oids{$k}->{value} ? $oids{$k}->{value} : q{});
#Â always a JSON array of single element
if (ref {} eq ref $value) {
$oids{$k}->{value} = to_json([{ map {($_ => encode_base64(trim($value->{$_}), ''))} keys %{ $value } }]);
}
else {
$oids{$k}->{value} = to_json([encode_base64(trim($value), '')]);
}
$oids{$k}->{oid_parts} = [ grep {length} (split m/\./, $oids{$k}->{oid}) ];
}
#Â store the device cache for real, now
schema('netdisco')->txn_do(sub {
$device->oids->delete;
$device->oids->populate([map {
{ oid => $_->{oid}, oid_parts => $_->{oid_parts}, value => $_->{value} }
} values %oids]);
debug sprintf 'replaced %d browsable oids in db', scalar keys %oids;
});
lib/App/Netdisco/Util/Snapshot.pm view on Meta::CPAN
=cut
sub resolve_enums {
my %oids = @_;
return () unless scalar keys %oids;
foreach my $oid (keys %oids) {
next unless $oids{$oid}->{enum};
my $value = $oids{$oid}->{value};
my %emap = map { reverse split m/\(/ }
map { s/\)//; $_ }
@{ $oids{$oid}->{enum} };
if (ref q{} eq ref $value) {
$oids{$oid}->{value} = $emap{$value} if exists $emap{$value};
}
elsif (ref {} eq ref $value) {
foreach my $k (keys %$value) {
$oids{$oid}->{value}->{$k} = $emap{ $value->{$k} }
if exists $emap{ $value->{$k} };
lib/App/Netdisco/Web.pm view on Meta::CPAN
send_file( join '/', 'swagger-ui', @{ (splat())[0] } );
};
# remove empty lines from CSV response
# this makes writing templates much more straightforward!
hook 'after' => sub {
my $r = shift; # a Dancer::Response
if ($r->content_type and $r->content_type eq 'text/comma-separated-values') {
my @newlines = ();
my @lines = split m/\n/, $r->content;
foreach my $line (@lines) {
push @newlines, $line if $line !~ m/^\s*$/;
}
$r->content(join "\n", @newlines);
}
};
#Â support for tenancies
lib/App/Netdisco/Web/Plugin/Device/SNMP.pm view on Meta::CPAN
my $items = _get_snmp_data($device->ip, $base);
to_json $items;
};
ajax '/ajax/data/snmp/typeahead' => require_login sub {
my $term = param('term') or return to_json [];
my $device = param('ip');
my $deviceonly = param('deviceonly');
my ($mib, $leaf) = split m/::/, $term;
my @found = schema(vars->{'tenant'})->resultset('SNMPObject')
->search({ -or => [ 'me.oid' => $term,
'me.oid' => { -like => ($term .'.%') },
-and => [(($mib and $leaf) ? ('me.mib' => $mib, 'me.leaf' => { -ilike => ($leaf .'%') })
: ('me.leaf' => { -ilike => ('%'. $term .'%') }))] ],
(($device and $deviceonly) ? ('device_browser.ip' => $device, 'device_browser.value' => { -not => undef }) : ()) },
{ select => [\q{ me.mib || '::' || me.leaf }],
as => ['qleaf'],
join => 'device_browser',
lib/App/Netdisco/Web/Plugin/Device/SNMP.pm view on Meta::CPAN
content_type 'application/json';
to_json [ sort @found ];
};
ajax '/ajax/data/snmp/nodesearch' => require_login sub {
my $to_match = param('str') or return to_json [];
my $partial = param('partial');
my $device = param('ip');
my $deviceonly = param('deviceonly');
my ($mib, $leaf) = split m/::/, $to_match;
my $found = undef;
if ($partial) {
$found = schema(vars->{'tenant'})->resultset('SNMPObject')
->search({ -or => [ 'me.oid' => $to_match,
'me.oid' => { -like => ($to_match .'.%') },
-and => [(($mib and $leaf) ? ('me.mib' => $mib, 'me.leaf' => { -ilike => ($leaf .'%') })
: ('me.leaf' => { -ilike => ($to_match .'%') }))] ],
(($device and $deviceonly) ? ('device_browser.ip' => $device, 'device_browser.value' => { -not => undef }) : ()),
}, { rows => 1, join => 'device_browser', order_by => 'oid_parts' })->first;
lib/App/Netdisco/Web/Plugin/Device/SNMP.pm view on Meta::CPAN
: (-or => ['me.oid' => $to_match, 'me.leaf' => $to_match])),
(($device and $deviceonly) ? ('device_browser.ip' => $device, 'device_browser.value' => { -not => undef }) : ()),
},{ rows => 1, join => 'device_browser', order_by => 'oid_parts' })->first;
}
return to_json [] unless $found;
$found = $found->oid;
$found =~ s/^\.1\.?//;
my @results = ('.1');
foreach my $part (split m/\./, $found) {
my $last = $results[-1];
push @results, "${last}.${part}";
}
content_type 'application/json';
to_json \@results;
};
ajax '/ajax/content/device/:ip/snmpnode/:oid' => require_login sub {
my $device = try { schema(vars->{'tenant'})->resultset('Device')
lib/App/Netdisco/Web/Plugin/Device/SNMP.pm view on Meta::CPAN
->search({},{ distinct => 1, order_by => 'subname' })
->get_column('subname')->all;
template 'ajax/device/snmpnode.tt',
{ node => \%data, munge => $munge, mungers => \@mungers },
{ layout => 'noop' };
};
sub _get_snmp_data {
my ($ip, $base, $recurse) = @_;
my @parts = grep {length} split m/\./, $base;
my %meta = map { ('.'. join '.', @{$_->{oid_parts}}) => $_ }
schema(vars->{'tenant'})->resultset('Virtual::FilteredSNMPObject')
->search({}, { bind => [
$ip,
(scalar @parts + 1),
(scalar @parts + 1),
$base,
] })->hri->all;
lib/App/Netdisco/Web/Plugin/Inventory.pm view on Meta::CPAN
tag => 'inventory',
path => '/inventory',
label => 'Inventory',
});
get '/inventory' => require_login sub {
my $platforms = schema(vars->{'tenant'})->resultset('Virtual::DevicePlatforms');
my $releases = schema(vars->{'tenant'})->resultset('Device')->get_releases();
my %release_version_map = (
map { (join '', map {sprintf '%05s', $_} split m/(\D)/, ($_->{os_ver} || '')) => $_ }
$releases->hri->all
);
my %release_map = ();
map { push @{ $release_map{ $release_version_map{$_}->{os} } }, $release_version_map{$_} }
grep { $release_version_map{$_}->{os} }
grep { $_ }
sort {(lc($release_version_map{$a}->{os} || '') cmp lc($release_version_map{$b}->{os} || '')) || ($a cmp $b)}
keys %release_version_map;
lib/App/Netdisco/Web/Search.pm view on Meta::CPAN
# if all else fails
params->{'tab'} ||= 'node';
}
# used in the device search sidebar to populate select inputs
my $model_list = [ grep { defined } $s->resultset('Device')->get_distinct_col('model') ];
my $os_list = [ grep { defined } $s->resultset('Device')->get_distinct_col('os') ];
my $vendor_list = [ grep { defined } $s->resultset('Device')->get_distinct_col('vendor') ];
my %os_vermap = (
map { $_ => (join '', map {sprintf '%05s', $_} split m/(\D)/) }
grep { defined }
$s->resultset('Device')->get_distinct_col('os_ver')
);
my $os_ver_list = [ sort {$os_vermap{$a} cmp $os_vermap{$b}} keys %os_vermap ];
template 'search', {
search => params->{'tab'},
model_list => $model_list,
os_list => $os_list,
os_ver_list => $os_ver_list,
lib/App/Netdisco/Worker/Plugin/Discover/PortPower.pm view on Meta::CPAN
# 1463 sometimes see second entry for the same port
next if $seen_pp{$port};
if (!defined $device_ports->{$port}) {
debug sprintf ' [%s] power - local port %s already skipped, ignoring',
$device->ip, $port;
next;
}
my ($module) = split m/\./, $entry;
push @portpower, {
port => $port,
module => $module,
admin => $p_admin->{$entry},
status => $p_pstatus->{$entry},
class => $p_class->{$entry},
power => $p_power->{$entry},
};
++$seen_pp{$port};
lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm view on Meta::CPAN
else {
push @report, read_lines( catfile( $reports, $_ ), 'latin-1' )
for (qw(rfc_oids net-snmp_oids cisco_oids), @maps);
}
my @browser = ();
my %children = ();
my %seenoid = ();
foreach my $line (@report) {
my ($oid, $qual_leaf, $type, $access, $index, $status, $enum, $descr) = split m/,/, $line, 8;
next unless defined $oid and defined $qual_leaf;
next if ++$seenoid{$oid} > 1;
my ($mib, $leaf) = split m/::/, $qual_leaf;
my @oid_parts = grep {length} (split m/\./, $oid);
++$children{ join '.', '', @oid_parts[0 .. (@oid_parts - 2)] }
if scalar @oid_parts > 1;
push @browser, {
oid => $oid,
oid_parts => [ @oid_parts ],
mib => $mib,
leaf => $leaf,
type => $type,
access => $access,
index => [($index ? (split m/:/, $index) : ())],
status => $status,
enum => [($enum ? (split m/:/, $enum ) : ())],
descr => $descr,
};
}
foreach my $row (@browser) {
$row->{num_children} = $children{ $row->{oid} } || 0;
}
debug sprintf "loadmibs - loaded %d objects from netdisco-mibs",
scalar @browser;
lib/App/Netdisco/Worker/Plugin/Show.pm view on Meta::CPAN
register_worker({ phase => 'main', driver => 'snmp' }, sub {
my ($job, $workerconf) = @_;
my ($device, $class, $object) = map {$job->$_} qw/device port extra/;
$class = 'SNMP::Info::'.$class if $class and $class !~ m/^SNMP::Info::/;
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device, $class);
$object ||= 'interfaces';
my $orig_object = $object;
my ($mib, $leaf) = split m/::/, $object;
SNMP::loadModules($mib) if $mib and $leaf and $mib ne $leaf;
$object =~ s/[-:]/_/g;
my $result = sub { eval { $snmp->$object() } };
if ($ENV{ND2_DO_QUIET}) {
my $coder = JSON::PP->new->utf8(1)
->allow_nonref(1)
->allow_unknown(1)
->allow_blessed(1)