App-MBUtiny
view release on metacpan or search on metacpan
lib/App/MBUtiny.pm view on Meta::CPAN
[3, 'TYP'],
[19, 'DATE'],
[4, 'STAT'],
)],
REPORT_HOSTS_HEADERS => [(
[32, 'HOST'],
[4, 'STAT'],
)],
REPORT_COLLECTORS_HEADERS => [(
[95, 'URL'],
[4, 'STAT'],
)],
};
@EXPORT = (qw/
PROJECTNAME PREFIX
/);
my $TTY = 1 if -t STDOUT;
my $hostname = hostname() // 'unknown host';
sub again {
my $self = shift;
$App::MBUtiny::Util::DEBUG = 1 if $self->debugmode;
# Datadir & Tempdir
if ($self->option("datadir")) {
preparedir( $self->datadir() );
} else {
$self->datadir($self->tempdir());
}
preparedir( $self->tempdir() );
# Collector dir
my $dbdir = File::Spec->catdir(sharedstatedir(), PREFIX);
preparedir( $dbdir, 0777 ) unless -e $dbdir;
# Set paths
my $objdir = File::Spec->catdir($self->datadir, OBJECTS_DIR);
my $excdir = File::Spec->catdir($self->datadir, EXCLUDE_DIR);
my $rstdir = File::Spec->catdir($self->datadir, RESTORE_DIR);
$self->{objdir} = $objdir;
$self->{excdir} = $excdir;
$self->{rstdir} = $rstdir;
# Prepare dirs
preparedir({
objdir => $objdir,
excdir => $excdir,
rstdir => $rstdir,
});
# Set VoidFile
$self->{voidfile} = File::Spec->catfile($self->tempdir(), VOIDFILE);
touch($self->{voidfile});
# Set DBI
$self->{_dbi} = undef;
return $self->SUPER::again;
}
sub excdir {shift->{excdir}}
sub objdir {shift->{objdir}}
sub rstdir {shift->{rstdir}}
sub getdbi {shift->{_dbi}}
__PACKAGE__->register_handler(
handler => "configure",
description => sprintf("Configure %s", PROJECTNAME),
code => sub { shift->configure });
__PACKAGE__->register_handler(
handler => "config",
description => "Alias for configure command",
code => sub { shift->configure });
__PACKAGE__->register_handler(
handler => "test",
description => "Testing",
code => sub {
### CODE:
my ($self, $meta, @arguments) = @_;
$self->configure or return 0;
my $status = 1;
if ($self->testmode) {
say("CLI arguments: ", join("; ",@arguments) || 'none' );
say("Meta: ", explain($meta));
say("CTK object: ", explain($self));
say("App handlers: ", join(", ", $self->list_handlers));
return 1;
}
# Get host-list
my @hosts = $self->_getHosts();
unless (scalar(@hosts)) {
$self->log_warn("No enabled <Host> configuration section found");
return 1;
}
# Start
foreach my $pair (sort {(keys(%$a))[0] cmp (keys(%$b))[0]} @hosts) {
my @header;
my @errors;
my $step = '';
my $ostat = 1; # Operation status
#
# Init
#
my $name = _getName($pair); # Backup name
my $host = node($pair, $name); # Config section
my $hostskip = (!@arguments || grep {lc($name) eq lc($_)} @arguments) ? 0 : 1;
my $enabled = value($host, 'enable') ? 1 : 0;
if ($hostskip || !$enabled) {
$self->log_info("Skip testing for \"%s\" backup host section", $name);
next;
}
my $tbl = Text::SimpleTable->new(@{(TEST_HEADERS)});
$self->log_info("Start testing for \"%s\" backup host section", $name);
( run in 0.425 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )