Adding log of recognized actions.
This commit is contained in:
parent
9c1f1a7ecd
commit
09e7d74d2f
|
@ -9,5 +9,6 @@ WriteMakefile(
|
||||||
test => { TESTS => 't/*/*.t' },
|
test => { TESTS => 't/*/*.t' },
|
||||||
PREREQ_PM => {
|
PREREQ_PM => {
|
||||||
'DBD::SQLite' => 0,
|
'DBD::SQLite' => 0,
|
||||||
|
'DateTime' => 0,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,6 +19,12 @@ my @migrations = (
|
||||||
init TEXT,
|
init TEXT,
|
||||||
pidfile TEXT,
|
pidfile TEXT,
|
||||||
binpath TEXT
|
binpath TEXT
|
||||||
|
);',
|
||||||
|
'CREATE TABLE log (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
date_execution TEXT,
|
||||||
|
parameters TEXT,
|
||||||
|
result TEXT
|
||||||
);'
|
);'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ use Carp qw/carp/;
|
||||||
use Params::ValidationCompiler qw/validation_for/;
|
use Params::ValidationCompiler qw/validation_for/;
|
||||||
use Types::Standard qw/Object HashRef Str/;
|
use Types::Standard qw/Object HashRef Str/;
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
|
use DateTime;
|
||||||
|
use JSON;
|
||||||
|
|
||||||
use Cualsea::MessageManager;
|
use Cualsea::MessageManager;
|
||||||
use Cualsea::Server::DB;
|
use Cualsea::Server::DB;
|
||||||
|
@ -23,7 +25,7 @@ sub handle_add {
|
||||||
my $init = $params{init};
|
my $init = $params{init};
|
||||||
my $pidfile = $params{pidfile};
|
my $pidfile = $params{pidfile};
|
||||||
my $binpath = $params{binpath};
|
my $binpath = $params{binpath};
|
||||||
if ( !-e $binpath || $init ne 'sysvinit' || !_validate_init_name($name) ) {
|
if ( $init ne 'sysvinit' || !_validate_init_name($name) ) {
|
||||||
return {
|
return {
|
||||||
is_error => 1,
|
is_error => 1,
|
||||||
desc => "Parameters didn't pass contraints on add",
|
desc => "Parameters didn't pass contraints on add",
|
||||||
|
@ -295,7 +297,7 @@ sub new {
|
||||||
say "Got parameters:";
|
say "Got parameters:";
|
||||||
say Data::Dumper::Dumper $params;
|
say Data::Dumper::Dumper $params;
|
||||||
if ( !exists $COMMANDS{$command} ) {
|
if ( !exists $COMMANDS{$command} ) {
|
||||||
return { is_error => 1, status => 404 };
|
return { is_error => 1, status => 404, desc => 'Command don\'t exists.' };
|
||||||
}
|
}
|
||||||
|
|
||||||
my $command_info = $COMMANDS{$command};
|
my $command_info = $COMMANDS{$command};
|
||||||
|
@ -335,7 +337,12 @@ sub new {
|
||||||
if ( !defined $handle ) {
|
if ( !defined $handle ) {
|
||||||
return { is_error => 1, status => 501 };
|
return { is_error => 1, status => 501 };
|
||||||
}
|
}
|
||||||
return $handle->(%params);
|
my $result = $handle->(%params);
|
||||||
|
my $dbh = Cualsea::Server::DB->dbh();
|
||||||
|
$dbh->do(<<'EOF', undef, DateTime->now().'', encode_json($message), encode_json($result));
|
||||||
|
INSERT INTO log (date_execution, parameters, result) VALUES (?, ?, ?);
|
||||||
|
EOF
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue