App-MonM
view release on metacpan or search on metacpan
lib/App/MonM.pm view on Meta::CPAN
=cut
use vars qw/ $VERSION /;
$VERSION = '1.09';
use feature qw/ say /;
use Text::SimpleTable;
use File::Spec;
use File::stat qw//;
use Text::ParseWords qw/shellwords quotewords/;
use Text::Wrap qw/wrap/;
use CTK::Skel;
use CTK::Util qw/ preparedir dformat execute dtf tz_diff sendmail variant_stf lf_normalize sharedstatedir /;
use CTK::ConfGenUtil;
use CTK::TFVals qw/ :ALL /;
use App::MonM::Const;
use App::MonM::Util qw/
blue green red yellow cyan magenta gray
yep nope skip wow
getBit setBit
node2anode getCheckitByName
getExpireOffset getTimeOffset explain
slurp spurt
merge
/;
use App::MonM::Store;
use App::MonM::Checkit;
use App::MonM::QNotifier;
use App::MonM::Report;
use parent qw/CTK::App/;
use constant {
TAB9 => " " x 9,
EXPIRES => 24*60*60, # 1 day
SMSSBJ => 'MONM CHECKIT REPORT',
DATE_FORMAT => '%YYYY-%MM-%DD %hh:%mm:%ss',
TABLE_HEADERS => [(
[32, 'NAME'],
[7, 'TYPE'],
[19, 'LAST CHECK DATE'],
[7, 'RESULT'],
)],
# Markers
MARKER_OK => '[ OK ]',
MARKER_FAIL => '[ FAIL ]',
MARKER_SKIP => '[ SKIP ]',
MARKER_INFO => '[ INFO ]',
};
eval { require App::MonM::Notifier };
my $NOTIFIER_LOADED = 1 unless $@;
$NOTIFIER_LOADED = 0 if $NOTIFIER_LOADED && (App::MonM::Notifier->VERSION * 1) < 1.04;
sub again {
my $self = shift;
$self->SUPER::again(); # CTK::App again first!!
# Datadir & Tempdir
if ($self->option("datadir")) {
# Prepare DataDir
preparedir( $self->datadir() ) or do {
$self->status(0);
$self->raise("Can't prepare directory %s", $self->datadir());
};
} elsif ($self->option("daemondir")) {
$self->datadir(File::Spec->catdir(sharedstatedir(), PREFIX));
} else {
$self->datadir($self->tempdir());
}
# Prepare TempDir
preparedir( $self->tempdir() ) or do {
$self->status(0);
$self->raise("Can't prepare directory %s", $self->tempdir());
};
# Store
my $db_file = File::Spec->catfile($self->datadir, App::MonM::Store::DB_FILENAME());
my $store_conf = $self->config("store") || $self->config('dbi') || {file => $db_file};
$store_conf = {file => $db_file} unless is_hash($store_conf);
my %store_args = %$store_conf;
$store_args{file} = $db_file unless ($store_args{file} || $store_args{dsn});
my $store = App::MonM::Store->new(%store_args);
$self->{store} = $store;
#$self->debug(explain($store));
# Notifier object init
my %nargs = (config => $self->configobj);
$self->{notifier} = $NOTIFIER_LOADED && lvalue($self->config("usemonotifier"))
? App::MonM::Notifier->new(%nargs)
: App::MonM::QNotifier->new(%nargs);
#$self->status($self->raise("Test error"));
return $self; # CTK requires!
}
sub raise {
my $self = shift;
say STDERR red(@_);
$self->log_error(sprintf(shift, @_));
return 0;
}
sub store {
my $self = shift;
return $self->{store};
}
sub notifier {
my $self = shift;
return $self->{notifier};
}
__PACKAGE__->register_handler(
handler => "info",
description => "Show statistic information",
code => sub {
### CODE:
my ($self, $meta, @arguments) = @_;
( run in 1.186 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )