push @new_dcf, $field;
next;
}
# snmp_object implies JSON content in the field
$field->{'json_list'} = true;
# snmp_object implies user should not edit in the web
type => 'exec',
event => 'discover',
with => {
# get JSON format of the snmp_object
cmd => (sprintf q![%% ndo %%] show -d '[%% ip %%]' -e %s --
if type=="string" then [.] else . end | [ .[] ] | sort'!
# send the JSON output into device custom_field (action inline)
.q! | [%% ndo %%] %s
trict;
use warnings;
use Dancer ':script';
use Moo;
use NetAddr::MAC qw/mac_as_ieee/;
use JSON qw(decode_json);
=head1 PUBLIC METHODS
=over 4
=item B<arpnip($host, $ssh)>
Retrieve ARP entries fro
md_v4 = "show ip arp vrf all | json | no-more\n";
my @out_v4 = $ssh->capture({ stdin_data => $cmd_v4 });
if (!$ssh->error) {
my $data = eval { decode_json(join '', @out_v4) };
"show ipv6 neighbor vrf all | json | no-more\n";
my @out_v6 = $ssh->capture({ stdin_data => $cmd_v6 });
if (!$ssh->error) {
my $data = eval { decode_json(join '', @out_v6) };
r ':syntax';
use App::Netdisco::Worker::Plugin;
use aliased 'App::Netdisco::Worker::Status';
use JSON::PP ();
use Data::Printer ();
use App::Netdisco::Transport::SNMP;
register_worker({ phase => 'ch
my $result = sub { eval { $snmp->$object() } };
if ($ENV{ND2_DO_QUIET}) {
my $coder = JSON::PP->new->utf8(1)
->allow_nonref(1)
_rs = schema('netdisco')
->resultset('DeviceBrowser')
->search({ -bool => \q{ jsonb_typeof(value) != 'array' } });
if ($legacy_rs->count) {
my @rows = $legacy_rs->hri-
data] ) )
foreach my $row (@rows) {
my $value = (@{ thaw( decode_base64( from_json($row->{value}) ) ) })[0];
$value = (ref {} eq ref $value)
? { map {($_
: (defined $value ? encode_base64($value, '') : undef);
$row->{value} = to_json([$value]);
}
schema('netdisco')->resultset('DeviceBrowser')->populate(\@rows);
tset('Device')
->find( params->{ip} ) } or send_error('Bad Device', 404);
return to_json $device->TO_JSON;
};
foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssids
->find( params->{ip} )->$rel } or send_error('Bad Device', 404);
return to_json [ map {$_->TO_JSON} $rows->all ];
};
}
swagger_path {
tags => ['Objects'],
path => setting('api_b
),
( param('backend') ? ( backend => param('backend') ) : () ),
})->delete;
return to_json { deleted => ($gone || 0)};
};
foreach my $rel (qw/nodes active_nodes nodes_with_age active_node
orker::Status';
use App::Netdisco::JobQueue 'jq_insert';
use Dancer::Plugin::DBIC 'schema';
use JSON::PP ();
register_worker({ phase => 'check' }, sub {
my ($job, $workerconf) = @_;
return Sta
');
});
register_worker({ phase => 'main' }, sub {
my ($job, $workerconf) = @_;
my $coder = JSON::PP->new->utf8(0)->allow_nonref(1)->allow_unknown(1);
my $sched = $coder->decode( $job->extra |
schema(vars->{'tenant'})->resultset('DeviceSkip')
->get_distinct_col('backend');
return to_json \@names;
};
swagger_path {
tags => ['Queue'],
path => (setting('api_base') || '').'/queue/jo
=> (param('limit') || setting('jobs_qdepth') || 50),
})->with_times->hri->all;
return to_json \@set;
};
swagger_path {
tags => ['Queue'],
path => (setting('api_base') || '').'/queue/jobs
),
( param('backend') ? ( backend => param('backend') ) : () ),
})->delete;
return to_json { deleted => ($gone || 0)};
};
swagger_path {
tags => ['Queue'],
path => (setting('api_base'
d_parts => [], # intentional, is inflated via make_snmpwalk_browsable()
value => to_json([encode_base64($val, '')]),
};
}
debug sprintf 'walked %d rows', scalar keys %sto
Netdisco::Backend::Role::Scheduler;
use Dancer qw/:moose :syntax :script/;
use NetAddr::IP;
use JSON::PP ();
use Algorithm::Cron;
use App::Netdisco::Util::MCE;
use App::Netdisco::JobQueue qw/jq_ins
ive', $wid;
return debug "sch ($wid): no need for scheduler... quitting"
}
my $coder = JSON::PP->new->utf8(0)->allow_nonref(1)->allow_unknown(1);
while (1) {
# sleep until some poi
_rs({}, {
'+columns' => [
{ router_ip => \q{(SELECT key FROM json_each_text(seen_on_router_last::json) ORDER BY value::timestamp DESC LIMIT 1)} },
{ router_name => \q{COAL
]} @results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/search/device.tt', { results => $json }, { layout => 'noop' };;
}
else {
hea
@results;
if ( request->is_ajax ) {
my $json = to_json (\@results);
template 'ajax/report/vlaninventory.tt', { results => $json }, { layout => 'noop' };
}
else {
h
esults;
if ( request->is_ajax ) {
my $json = to_json (\@results);
template 'ajax/report/vlanmultiplenames.tt', { results => $json }, { layout => 'noop' };
}
else {
) } @results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/search/port.tt', { results => $json }, { layout => 'noop' };
}
else {
heade
tered = $rs->get_datatables_filtered_count($exp_params);
content_type 'application/json';
return to_json(
{ draw => int( param('draw') ),
recordsTotal => i
calar @results;
if (request->is_ajax) {
my $json = to_json( \@results );
template 'ajax/search/vlan.tt', { results => $json }, { layout => 'noop' };
}
else {
heade
,
},
"seen_on_router_first",
{ data_type => "jsonb", is_nullable => 0, default_value => \"{}" },
"seen_on_router_last",
{ data_type => "jsonb", is_nullable => 0, default_value => \"{}" },
"host($args->{foreign_alias}.ip)" => { '=' =>
\q{(SELECT key FROM json_each_text(seen_on_router_last::json) ORDER BY value::timestamp DESC LIMIT 1)} },
};
},
{ join_type => 'LE
with application protocols such as SNMP, NETCONF
(OpenConfig with XML), RESTCONF (OpenConfig with JSON), eAPI, or even CLI
scraping. The combination of transport and protocol is known as a I<driver>.
r @results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/portssid.tt', { results => $json }, { layout => 'noop' };
}
else {
hea
$cf = from_json ($item->custom_fields || '{}');
}
elsif (ref {} eq ref $item and exists $item->{'custom_fields'}) {
$cf = from_json ($item->{'custom
$cf = from_json ($item->custom_fields || '{}');
}
elsif (ref {} eq ref $item and exists $item->{'custom_fields'}) {
$cf = from_json ($item->{'
event_data => dclone (vars->{'hook_data'} || {}) };
# remove scalar references which to_json cannot handle
visit( $extra->{'event_data'}, sub {
my ($key, $valueref) = @_;
$$valuere
' if ref $$valueref eq 'SCALAR';
});
jq_insert({
action => ('hook::'. lc($conf->{'type'})),
extra => encode_base64( encode('UTF-8', to_json( $extra )), '' ),
});
return 1;
}
true;