App-MonM-Notifier
view release on metacpan or search on metacpan
lib/App/MonM/Notifier/Monotifier.pm view on Meta::CPAN
=head1 SEE ALSO
L<App::MonM>
=head1 AUTHOR
Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved
=head1 LICENSE
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
See C<LICENSE> file and L<https://dev.perl.org/licenses/>
=cut
use vars qw/$VERSION/;
$VERSION = '1.00';
use feature qw/say/;
use Encode;
use Encode::Locale;
use File::stat qw//;
use Text::SimpleTable;
use CTK::ConfGenUtil;
use CTK::TFVals qw/ :ALL /;
use CTK::Util qw/dtf tz_diff variant_stf/;
use App::MonM::Const;
use App::MonM::Util qw/
blue green red yellow cyan magenta gray
yep nope skip wow
getExpireOffset getTimeOffset explain explain
/;
use App::MonM::Notifier::Store;
use parent qw/CTK::App/;
use constant {
NODE_NAME => 'notifier',
NODE_NAME_ALIAS => 'monotifier',
ROWS_LIMIT => 1000,
DATE_FORMAT => '%YYYY-%MM-%DD %hh:%mm:%ss',
TABLE_INFO => [(
[12, 'NAME'],
[68, 'VALUE'],
)],
};
sub again {
my $self = shift;
$self->SUPER::again(); # CTK::App again first!!
# Store
my $store_conf = hash($self->conf(NODE_NAME) || $self->conf(NODE_NAME_ALIAS));
$store_conf->{expires} = getExpireOffset(lvalue($store_conf, "expires") || lvalue($store_conf, "expire") || 0);
$store_conf->{maxtime} = getExpireOffset(lvalue($store_conf, "maxtime") || 0);
my $store = App::MonM::Notifier::Store->new(%$store_conf);
$self->{store} = $store;
#print App::MonM::Util::explain($store);
return $self; # CTK requires!
}
sub store {
my $self = shift;
return $self->{store};
}
sub raise {
my $self = shift;
say STDERR red(@_);
return 0;
}
__PACKAGE__->register_handler(
handler => "info",
description => "Show statistic information",
code => sub {
### CODE:
my ($self, $meta, @arguments) = @_;
my $store = $self->store;
# General info
printf("Hostname : %s\n", HOSTNAME);
printf("Monotifier version : %s\n", $self->VERSION);
printf("Monotifier enabled : %s\n", lvalue($self->config("usemonotifier")) ? green("Yes") : magenta("No"));
printf("Date : %s\n", _fdate());
printf("Data dir : %s\n", $self->datadir);
printf("Config file : %s\n", $self->configfile);
printf("Config status : %s\n", $self->conf("loadstatus") ? green("OK") : magenta("ERROR: not loaded"));
$self->raise($self->configobj->error) if !$self->configobj->status and length($self->configobj->error);
#$self->debug(explain($self->config)) if $self->conf("loadstatus") && $self->verbosemode;
# DB status
printf("DB DSN : %s\n", $store->dsn);
printf("DB status : %s\n", $store->error ? red("ERROR") : green("OK"));
my $db_is_ok = $store->error ? 0 : 1;
if ($db_is_ok && $store->{file} && -e $store->{file}) {
my $s = File::stat::stat($store->{file})->size;
printf("DB file : %s\n", $store->{file});
printf("DB size : %s\n", sprintf("%s (%d bytes)", _fbytes($s), $s));
printf("DB modified : %s\n", _fdate(File::stat::stat($store->{file})->mtime || 0));
}
$self->raise($store->error) unless $db_is_ok;
return 1;
});
__PACKAGE__->register_handler(
handler => "show",
description => "Show table data",
code => sub {
### CODE:
( run in 0.828 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )