diff --git a/lib/NGCP/Panel.pm b/lib/NGCP/Panel.pm index 7bbff81fe1..c57cb73ed5 100644 --- a/lib/NGCP/Panel.pm +++ b/lib/NGCP/Panel.pm @@ -2,6 +2,7 @@ package NGCP::Panel; use Moose; use Catalyst::Runtime 5.80; +use File::Slurp qw(); # Set flags and add plugins for the application. # @@ -167,6 +168,7 @@ __PACKAGE__->config( } } }, + ngcp_version => get_ngcp_version(), ); __PACKAGE__->config( default_view => 'HTML' ); @@ -175,6 +177,13 @@ __PACKAGE__->log(Log::Log4perl::Catalyst->new($logger_config)); # Start the application __PACKAGE__->setup(); +sub get_ngcp_version { + my $content = File::Slurp::read_file("/etc/ngcp_version", err_mode => 'quiet'); + $content //= '(unavailable)'; + chomp($content); + return $content; +} + 1; # vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm index 2c061faa84..fe8d44cb9c 100644 --- a/lib/NGCP/Panel/Controller/Root.pm +++ b/lib/NGCP/Panel/Controller/Root.pm @@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller' } use Scalar::Util qw(blessed); use NGCP::Panel::Utils::DateTime qw(); +use NGCP::Panel::Utils::Statistics qw(); use DateTime qw(); use Time::HiRes qw(); use DateTime::Format::RFC3339 qw(); @@ -254,7 +255,10 @@ sub error_page :Private { if($c->request->path =~ /^api\/.+/) { $c->response->content_type('application/json'); - $c->response->body(JSON::to_json({ code => 404, message => 'Path not found' })."\n"); + $c->response->body(JSON::to_json({ + code => 404, + message => 'Path not found', + })."\n"); } else { $c->stash(template => 'notfound_page.tt'); } diff --git a/lib/NGCP/Panel/Controller/Statistics.pm b/lib/NGCP/Panel/Controller/Statistics.pm index 50d0d987d7..29eaab4d52 100644 --- a/lib/NGCP/Panel/Controller/Statistics.pm +++ b/lib/NGCP/Panel/Controller/Statistics.pm @@ -125,6 +125,21 @@ sub rrd : Chained('/') :PathPart('statistics/rrd') :Args() { return; } +sub versions :Chained('/') :PathPart('statistics/versions') :Args() { + my ( $self, $c ) = @_; + my $versions_info = NGCP::Panel::Utils::Statistics::get_dpkg_versions(); + $c->stash(versions_info => $versions_info, + #template => 'statistics/versions.tt', + ); + return; +} + +__PACKAGE__->meta->make_immutable; + +1; + +__END__ + =head1 AUTHOR Andreas Granig,,, @@ -136,8 +151,4 @@ it under the same terms as Perl itself. =cut -__PACKAGE__->meta->make_immutable; - -1; - # vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Utils/Statistics.pm b/lib/NGCP/Panel/Utils/Statistics.pm index 927c72ab68..a1493448c0 100644 --- a/lib/NGCP/Panel/Utils/Statistics.pm +++ b/lib/NGCP/Panel/Utils/Statistics.pm @@ -3,10 +3,11 @@ use strict; use warnings; use DateTime::TimeZone::OffsetOnly; -use Time::Local; -use POSIX; use File::Find::Rule; +use File::Slurp qw(read_file); use List::MoreUtils qw(apply); +use POSIX; +use Time::Local; sub tz_offset { use DateTime::TimeZone::OffsetOnly; @@ -69,6 +70,11 @@ sub get_rrd { return $content; } +sub get_dpkg_versions { + my ($self) = @_; + return `LANG=C dpkg-query -f '\${db:Status-Abbrev} \${Package} \${Version}\\n' -W 2>/dev/null`; +} + 1; # vim: set tabstop=4 expandtab: diff --git a/share/layout/body.tt b/share/layout/body.tt index c06121c7e3..ce78eaf6a9 100644 --- a/share/layout/body.tt +++ b/share/layout/body.tt @@ -83,6 +83,9 @@
+[% versions_info | html %] ++ +[% # vim: set tabstop=4 syntax=html expandtab: -%]