blib/lib/App/Netdisco/Worker/Plugin/CheckEncoding.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 52 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Worker::Plugin::CheckEncoding;
2  
3 use Dancer ':syntax';
4 use Dancer::Plugin::DBIC 'schema';
5 use App::Netdisco::Worker::Plugin;
6 use aliased 'App::Netdisco::Worker::Status';
7  
8 use App::Netdisco::Util::SNMPText
9 qw/ scan_config_encoding scan_stored_encoding /;
10  
11 my $LIMIT_PER_COLUMN = 50;
12  
13 register_worker({ phase => 'main' }, sub {
14 my @config_findings = scan_config_encoding(config());
15 my @stored_findings = scan_stored_encoding(schema('netdisco'), $LIMIT_PER_COLUMN);
16 my $devices = schema('netdisco')->resultset('Device')->count;
17  
18 my $total = scalar @config_findings
19 + scalar grep { not exists $_->{more} } @stored_findings;
20  
21 if (! $total) {
22 return Status->done(sprintf
23 'Checked %d device%s and the configuration, nothing to report.',
24 $devices, ($devices == 1 ? '' : 's'));
25 }
26  
27 print "\n";
28 foreach my $finding (@config_findings) {
29 printf "configuration %s\n %s\n looks like: %s\n\n",
30 $finding->{path}, $finding->{value},
31 (defined $finding->{suggestion} ? $finding->{suggestion} : '(not recoverable)');
32 }
33  
34 foreach my $finding (@stored_findings) {
35 if (exists $finding->{more}) {
36 printf "%s: and %d more\n\n", $finding->{column}, $finding->{more};
37 }
38 elsif (defined $finding->{suggestion}) {
39 printf "%s %s\n %s\n looks like: %s\n\n", $finding->{ip},
40 $finding->{column}, $finding->{value}, $finding->{suggestion};
41 }
42 else {
43 printf "%s %s\n %s\n re-read on next discover, original bytes not recoverable\n\n",
44 $finding->{ip}, $finding->{column}, $finding->{value};
45 }
46 }
47  
48 return Status->done(sprintf '%d finding%s.', $total, ($total == 1 ? '' : 's'));
49 });
50  
51 true;