Change-Id: I944792343afee9352520d0b89f9648a12b0a085echanges/76/7276/5
parent
8985f4a7ad
commit
d086b7979f
@ -0,0 +1,46 @@
|
|||||||
|
package NGCP::Panel::Controller::Grafana;
|
||||||
|
use NGCP::Panel::Utils::Generic qw(:all);
|
||||||
|
use Sipwise::Base;
|
||||||
|
|
||||||
|
use parent 'Catalyst::Controller';
|
||||||
|
|
||||||
|
use LWP::UserAgent;
|
||||||
|
my $ua = LWP::UserAgent->new(max_redirect => 0);
|
||||||
|
$ua->timeout(3);
|
||||||
|
|
||||||
|
sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) {
|
||||||
|
my ($self, $c) = @_;
|
||||||
|
$c->log->debug(__PACKAGE__ . '::auto');
|
||||||
|
NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub root :Chained('/') :PathPart('grafana') :CaptureArgs() {
|
||||||
|
my ( $self, $c, @fullpath ) = @_;
|
||||||
|
|
||||||
|
my $path = join '/', @fullpath;
|
||||||
|
$path .= '?' . $c->req->uri->query if $c->req->uri->query;
|
||||||
|
my $url = "http://127.0.0.1:3000";
|
||||||
|
$url .= "/".$path if length $path;
|
||||||
|
$c->log->debug("accessing grafana via ngcp-panel proxy, url is $url");
|
||||||
|
|
||||||
|
my $req = HTTP::Request->new($c->req->method => $url);
|
||||||
|
$req->header('Content-Type' => $c->req->header('Content-Type'));
|
||||||
|
$req->header('X-WEBAUTH-USER' => $c->user->login);
|
||||||
|
my $body = $c->request->body ? (do { local $/; $c->request->body->getline }) : '';
|
||||||
|
$req->content($body);
|
||||||
|
my $res = $ua->request($req);
|
||||||
|
$c->res->content_type($res->header('Content-Type') // 'text/plain');
|
||||||
|
if($res->header('Location')) {
|
||||||
|
$c->res->header(Location => $res->header('Location'))
|
||||||
|
}
|
||||||
|
$c->res->status($res->code);
|
||||||
|
$c->res->body($res->decoded_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__PACKAGE__->meta->make_immutable;
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
# vim: set tabstop=4 expandtab:
|
@ -1,63 +0,0 @@
|
|||||||
package NGCP::Panel::Controller::Log;
|
|
||||||
use NGCP::Panel::Utils::Generic qw(:all);
|
|
||||||
use Sipwise::Base;
|
|
||||||
|
|
||||||
use parent 'Catalyst::Controller';
|
|
||||||
|
|
||||||
use LWP::UserAgent;
|
|
||||||
my $ua = LWP::UserAgent->new;
|
|
||||||
$ua->timeout(3);
|
|
||||||
|
|
||||||
# a proxy for kibana/elasticsearch
|
|
||||||
|
|
||||||
sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) {
|
|
||||||
my ($self, $c) = @_;
|
|
||||||
$c->log->debug(__PACKAGE__ . '::auto');
|
|
||||||
NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub root :Chained('/') :PathPart('log') :CaptureArgs(0) {
|
|
||||||
my ( $self, $c ) = @_;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub static :Chained('root') :PathPart('') :Args() {
|
|
||||||
my ($self, $c, @fullpath) = @_;
|
|
||||||
my $path = join '/', @fullpath;
|
|
||||||
$path ||= 'index.html';
|
|
||||||
$path = 'kibana/'.$path;
|
|
||||||
|
|
||||||
$c->stash(template => $path);
|
|
||||||
$c->forward($c->view('TT'));
|
|
||||||
|
|
||||||
if($path eq "kibana/config.js") {
|
|
||||||
my $defp = '/dashboard/file/NGCP-Summary.json';
|
|
||||||
my $eurl = $c->uri_for_action('/log/elastic')->as_string;
|
|
||||||
my $body = $c->res->body;
|
|
||||||
$body =~ s/(\s*elasticsearch:\s*)"[^,]+"/$1"$eurl"/g;
|
|
||||||
$body =~ s/(\s*default_route\s*:\s*)'[^,]+'/$1'$defp'/g;
|
|
||||||
$c->res->body($body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub elastic :Chained('root') :PathPart('ngcpelastic') :Args() {
|
|
||||||
my ($self, $c, @fullpath) = @_;
|
|
||||||
my $path = join '/', @fullpath;
|
|
||||||
$path .= '?' . $c->req->uri->query if $c->req->uri->query;
|
|
||||||
|
|
||||||
my $req = HTTP::Request->new($c->req->method => 'http://' . $c->config->{elasticsearch}->{host} . ':' . $c->config->{elasticsearch}->{port} . '/'.$path);
|
|
||||||
$req->header('Content-Type' => $c->req->header('Content-Type'));
|
|
||||||
my $body = $c->request->body ? (do { local $/; $c->request->body->getline }) : '';
|
|
||||||
$req->content($body);
|
|
||||||
my $res = $ua->request($req);
|
|
||||||
$c->res->content_type($res->header('Content-Type') // 'text/plain');
|
|
||||||
$c->res->status($res->code);
|
|
||||||
$c->res->body($res->decoded_content);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__PACKAGE__->meta->make_immutable;
|
|
||||||
|
|
||||||
1;
|
|
||||||
|
|
||||||
# vim: set tabstop=4 expandtab:
|
|
Loading…
Reference in new issue