}
else {
my $stanza = undef;
try {
$stanza = from_json( $line );
debug sprintf '[%s] external credentials stanza added',
$
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;
ToJSON});
# this replacement will avoid the issue of relation names which override
# field names, causing TO_JSON to return object instances, breaking to_json
*DBIx::Class::Helper::Row::ToJSON:
:TO_JSON = sub {
my $self = shift;
my $columns_info = $self->columns_info($self->serializable_columns);
my $columns_data = { $self->get_columns };
return {
map +($_ =>
$columns_data->{$_}), keys %$columns_info
};
};
}
# for DBIx::Class::Helper::Row::ToJSON
# to allow text columns to be included in results
sub unserializable_data_types {
return {
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)
pec::Functions qw/splitdir catdir catfile/;
use MIME::Base64 'decode_base64';
use SNMP::Info;
use JSON::PP ();
use base 'Exporter';
our @EXPORT = ();
our @EXPORT_OK = qw/
get_communities
snmp_com
Base64 encoded,
decodes it and then munge to handle data format, before finally pretty
render in JSON format.
=cut
sub get_code_info { return ($_[0]) =~ m/^(.+)::(.*?)$/ }
sub sub_name { retur
ength $encoded;
my $json = JSON::PP->new->utf8->pretty->allow_nonref->allow_unknown->canonical;
$json->sort_by( sub { sortable_oid($JSON::PP::a) cmp sortable_oid($JSON::PP::b) } );
retur
_actions';
use App::Netdisco::Backend::Job;
use App::Netdisco::DB::ExplicitLocking ':modes';
use JSON::PP ();
use Try::Tiny;
use base 'Exporter';
our @EXPORT = ();
our @EXPORT_OK = qw/
jq_warm_thr
}
die 'failed to find row for custom field update' unless $row;
my $coder = JSON::PP->new->utf8(0)->allow_nonref(1)->allow_unknown(1);
$spec->{subaction} = $coder->enco
row->make_column_dirty('custom_fields');
$row->update({
custom_fields => \['jsonb_set(custom_fields, ?, ?)'
=> (qq{{$spec->{action}}}, $spec->{subac
Netdisco::DB::ResultSet::Device;
use App::Netdisco::DB::ResultSet::DevicePort;
my %device_fields_json = ();
my @inline_device_actions = ();
my @inline_device_port_actions = ();
foreach my $config (@
'name'};
push @inline_device_actions, $config->{'name'};
++$device_fields_json{ $config->{'name'} } if $config->{'json_list'};
}
foreach my $config (@{ setting('custom_fields')->{'device_port'} |
map {( ('cf_'. $_) => \[
($device_fields_json{$_} ? q{ARRAY(SELECT json_array_elements_text((me.custom_fields ->> ?) ::json))::text[]}
: 'me.cu
search({ -or => [
-bool => \q{ array_length(oid_parts, 1) IS NULL },
-bool => \q{ jsonb_typeof(value) != 'array' }, ] })->count) {
my @rows = $device->oids->search({},{
],
})->hri->all;
$oids{$_->{oid}} = {
%{ $_ },
value => (@{ from_json($_->{value}) })[0],
} for @rows;
}
# or we have an snmpwalk file on disk
elsif (-f $
=> $oid,
oid_parts => [], # not needed temporarily
value => to_json([ ((defined $type and $type eq 'BASE64') ? $value
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
]} @results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/search/device.tt', { results => $json }, { layout => 'noop' };;
}
else {
hea
_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);
@results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/nodemultiips.tt', { results => $json }, { layout => 'noop' };
}
else {
h
sults;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/devicednsmismatch.tt', { results => $json }, { layout => 'noop' };
}
else {
tered = $rs->get_datatables_filtered_count($exp_params);
content_type 'application/json';
return to_json(
{ draw => int( param('draw') ),
recordsTotal => i
results;
if ( request->is_ajax ) {
my $json = to_json (\@results);
template 'ajax/report/portmultinodes.tt', { results => $json }, { layout => 'noop' };
}
else {
h
tered = $rs->get_datatables_filtered_count($exp_params);
content_type 'application/json';
return to_json(
{ draw => int( param('draw') ),
recordsTotal => i
}
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/moduleinventory.tt',
{ results => $json, opt => $has_opt },
{ layout =>
>hri->all;
if (request->is_ajax) {
my $json = to_json (\@results);
template 'ajax/report/portutilization.tt', { results => $json }, { layout => 'noop' };
}
else {
tered = $rs->get_datatables_filtered_count($exp_params);
content_type 'application/json';
return to_json(
{ draw => int( param('draw') ),
recordsTotal => i
}
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/netbios.tt',
{ results => $json, opt => $domain },
{ layout => 'noop
results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/apchanneldist.tt', { results => $json }, { layout => 'noop' };
}
else {
h
results;
if ( request->is_ajax ) {
my $json = to_json (\@results);
template 'ajax/report/deviceaddrnodns.tt', { results => $json }, { layout => 'noop' };
}
else {