working worker

This commit is contained in:
Oliver Gorwits
2017-12-14 19:15:21 +00:00
parent ebadebe69a
commit 61a3a9e06d
4 changed files with 49 additions and 30 deletions

View File

@@ -29,21 +29,23 @@ ajax '/ajax/data/device/netmap' => require_login sub {
})->all;
my %id_for = ();
my %data = ( nodes => [], links => [] );
my %v3data = ( nodes => {}, links => [] );
my %v4data = ( nodes => [], links => [] );
my $domain = quotemeta( setting('domain_suffix') || '' );
foreach my $device (@devices) {
$id_for{$device->{ip}} = $device->{'row_number'};
(my $name = ($device->{dns} || lc($device->{name}) || $device->{ip})) =~ s/$domain$//;
push @{$data{'nodes'}}, {
$v3data{nodes}->{ ($device->{row_number} - 1) } = {
ID => $device->{row_number},
SIZEVALUE => 3000,
COLORVALUE => 10,
LABEL => $name,
};
push @{$v4data{'nodes'}}, { index => ($device->{row_number} - 1) };
$data{'centernode'} = $device->{row_number}
$v3data{'centernode'} = $device->{row_number}
if $qdev and $qdev->in_storage and $device->{ip} eq $qdev->ip;
}
@@ -62,14 +64,19 @@ ajax '/ajax/data/device/netmap' => require_login sub {
}
while (my $l = $rs->next) {
push @{$data{'links'}}, {
push @{$v3data{'links'}}, {
FROMID => $id_for{$l->{left_ip}},
TOID => $id_for{$l->{right_ip}},
fixed => 1,
};
push @{$v4data{'links'}}, {
source => ($id_for{$l->{left_ip}} - 1),
target => ($id_for{$l->{right_ip}} - 1),
};
}
content_type('application/json');
to_json({data => \%data});
to_json({ v3 => \%v3data, v4 => \%v4data});
};
true;