« blib/lib/App/Netdisco/SSHCollector/Platform/Linux.pm
↑ Summary
blib/lib/App/Netdisco/Worker/Plugin/PortControl.pm »
| 1 | package App::Netdisco::Web::Statistics; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use File::Spec::Functions qw/catfile catdir/; | ||
| 5 | use Dancer::Plugin::DBIC; | ||
| 6 | use Dancer::Plugin::Auth::Extensible; | ||
| 7 | |||
| 8 | use App::Netdisco::Util::PostgresFloor '$POSTGRES_FLOOR_MAJOR'; | ||
| 9 | |||
| 10 | sub mib_bundle_version { | ||
| 11 | my $home = setting('mibhome') | ||
| 12 | || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs'); | ||
| 13 | open my $fh, '<', catfile($home, 'VERSION') or return undef; | ||
| 14 | my $version = <$fh>; | ||
| 15 | close $fh; | ||
| 16 | return undef unless defined $version; | ||
| 17 | $version =~ s/^\s+|\s+$//g; | ||
| 18 | return ($version =~ /\A[0-9]+(?:\.[0-9]+)+\z/ ? $version : undef); | ||
| 19 | } | ||
| 20 | |||
| 21 | get '/ajax/content/statistics' => require_login sub { | ||
| 22 | |||
| 23 | my $stats = schema(vars->{'tenant'})->resultset('Statistics') | ||
| 24 | ->search(undef, { order_by => { -desc => 'day' }, rows => 1 }); | ||
| 25 | |||
| 26 | $stats = ($stats->count ? $stats->first : undef); | ||
| 27 | |||
| 28 | var( nav => 'statistics' ); | ||
| 29 | template 'ajax/statistics.tt', | ||
| 30 | { stats => $stats, netdisco_version => $App::Netdisco::VERSION, | ||
| 31 | mib_bundle_version => mib_bundle_version(), | ||
| 32 | pg_floor => $POSTGRES_FLOOR_MAJOR }, | ||
| 33 | { layout => 'noop' }; | ||
| 34 | }; | ||
| 35 | |||
| 36 | true; |