-
Notifications
You must be signed in to change notification settings - Fork 0
/
pm.pl
executable file
·54 lines (48 loc) · 1.29 KB
/
pm.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl
use Mojolicious::Lite;
use FindBin qw/$RealBin/;
use lib "$RealBin/lib";
use PM;
my $pm = PM->new('app_dir' => $RealBin);
get '/' => sub {
my ($c) = @_;
$c->render(
'pmname' => $pm->config()->get('pm_name'),
'elimit' => $pm->config()->get('pm_max_entries'),
'tlimit' => $pm->config()->get('pm_max_time'),
'rinterval' => $pm->config()->get('pm_refresh'),
);
} => 'index';
websocket '/whats_up' => sub {
my ($c) = @_;
$c->on('json' => sub {
my ($c, $req) = @_;
my $tail;
if ($req->{'after'}) {
eval {
$tail = $pm->log_handle()->whats_up(
'after' => $req->{'after'}
);
};
if ($@) {
if (ref($@) eq 'PM::Log::Exception::BadAfterOpt') {
return $c->send({'json' => {
'ok' => \0,
'error' => 'bad "after" opt',
}});
}
else {
die $@;
}
}
}
else {
$tail = $pm->log_handle()->whats_up();
}
$c->send({'json' => {
'ok' => \1,
'tail' => $tail,
}});
});
};
app->start();