diff options
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Status.pm | 70 | ||||
-rw-r--r-- | templates/web/base/status/index.html | 19 |
2 files changed, 89 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Status.pm b/perllib/FixMyStreet/App/Controller/Status.pm new file mode 100755 index 000000000..907fe5456 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Status.pm @@ -0,0 +1,70 @@ +package FixMyStreet::App::Controller::Status; +use Moose; +use namespace::autoclean; + +use HTTP::Negotiate; +use JSON; + +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::Status - Catalyst Controller + +=head1 DESCRIPTION + +Status page Catalyst Controller. + +=head1 METHODS + +=cut + +sub index_json : Path('/status.json') : Args(0) { + my ($self, $c) = @_; + $c->forward('index', [ 'json' ]); +} + +sub index : Path : Args(0) { + my ($self, $c, $format) = @_; + + # Fetch summary stats from admin front page + $c->forward('/admin/index'); + + # Fetch git version + $c->forward('/admin/config_page'); + + my $chosen = $format; + unless ($chosen) { + my $variants = [ + ['html', undef, 'text/html', undef, undef, undef, undef], + ['json', undef, 'application/json', undef, undef, undef, undef], + ]; + $chosen = HTTP::Negotiate::choose($variants, $c->req->headers); + $chosen = 'html' unless $chosen; + } + + # TODO Perform health checks here + + if ($chosen eq 'json') { + $c->res->content_type('application/json; charset=utf-8'); + my $data = { + version => $c->stash->{git_version}, + reports => $c->stash->{total_problems_live}, + updates => $c->stash->{comments}{confirmed}, + alerts_confirmed => $c->stash->{alerts}{1}, + alerts_unconfirmed => $c->stash->{alerts}{0}, + questionnaires_sent => $c->stash->{questionnaires}{total}, + questionnaires_answered => $c->stash->{questionnaires}{1}, + bodies => $c->stash->{total_bodies}, + contacts => $c->stash->{contacts}{total}, + }; + my $body = JSON->new->utf8(1)->pretty->encode($data); + $c->res->body($body); + } + + return 1; +} + +__PACKAGE__->meta->make_immutable; + +1; diff --git a/templates/web/base/status/index.html b/templates/web/base/status/index.html new file mode 100644 index 000000000..9ed4292b7 --- /dev/null +++ b/templates/web/base/status/index.html @@ -0,0 +1,19 @@ +[% INCLUDE 'header.html' title=loc('Summary') bodyclass='fullwidthpage' %] + +<h1>[% loc('Summary') %]</h1> + +<dl> + <dt>Version</dt> + <dd>[% git_version || 'unknown' %]</dd> +</dl> + +<ul> + <li>[% tprintf( loc('<strong>%d</strong> live problems'), total_problems_live ) %]</li> + <li>[% tprintf( loc('%d live updates'), comments.confirmed || 0 ) %]</li> + <li>[% tprintf( loc('%d confirmed alerts, %d unconfirmed'), alerts.1, alerts.0) %]</li> + <li>[% tprintf( loc('%d questionnaires sent – %d answered (%s%%)'), questionnaires.total, questionnaires.1, questionnaires_pc) %]</li> + <li>[% tprintf( '%d bodies', total_bodies) %], + [% tprintf( loc('%d council contacts – %d confirmed, %d unconfirmed'), contacts.total, contacts.1, contacts.0) %]</li> +</ul> + +[% INCLUDE 'footer.html' %] |