#834 VLAN Mismatch report - add sysname, port comment, and vlan diff

This commit is contained in:
Oliver Gorwits
2022-08-16 18:12:35 +01:00
parent 79f7febc16
commit dd468efdd5
3 changed files with 41 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
use List::MoreUtils qw/listcmp sort_by/;
register_report(
{ category => 'Port',
@@ -24,6 +25,22 @@ get '/ajax/content/report/portvlanmismatch' => require_login sub {
})
->hri->all;
# note that the generated list is rendered without HTML escape,
# so we MUST sanitise here with the grep
foreach my $res (@results) {
my @left = grep {m/^(?:n:)?\d+$/} map {s/\s//g; $_} split ',', $res->{left_vlans};
my @right = grep {m/^(?:n:)?\d+$/} map {s/\s//g; $_} split ',', $res->{right_vlans};
my %new = (0 => [], 1 => []);
my %cmp = listcmp @left, @right;
foreach my $vlan (keys %cmp) {
map { push @{ $new{$_} }, ( (2 == scalar @{ $cmp{$vlan} }) ? $vlan : "<strong>$vlan</strong>" ) } @{ $cmp{$vlan} };
}
$res->{left_vlans} = join ', ', sort_by { (my $a = $_) =~ s/\D//g; sprintf "%04d", $a } @{ $new{0} };
$res->{right_vlans} = join ', ', sort_by { (my $a = $_) =~ s/\D//g; sprintf "%04d", $a } @{ $new{1} };
}
if (request->is_ajax) {
my $json = to_json (\@results);
template 'ajax/report/portvlanmismatch.tt', { results => $json }, { layout => 'noop' };