App-MonM
view release on metacpan or search on metacpan
lib/App/MonM.pm view on Meta::CPAN
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.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;
lib/App/MonM.pm view on Meta::CPAN
$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};
lib/App/MonM.pm view on Meta::CPAN
},
-vars => {
PROJECT => PROJECTNAME,
PROJECTNAME => PROJECTNAME,
PREFIX => PREFIX,
},
-debug => $self->verbosemode,
);
printf("Installing configuration to \"%s\"...\n", $dir);
if ($skel->build("config")) {
say green("Done. Configuration has been installed");
} else {
return $self->raise("Can't install configuration");
}
return 1;
});
__PACKAGE__->register_handler(
handler => "checkit",
description => "Checkit",
lib/App/MonM.pm view on Meta::CPAN
} else {
$status = 0; # General status
}
# Show resulsts
print $result ? green(MARKER_OK) : red(MARKER_FAIL);
printf(" %s (%s >>> %s)\n", $name, $checker->source, $checker->message);
if ($self->verbosemode) {
printf "%sStatus=%s; Code=%s\n", TAB9,
$checker->status || 0, $checker->code // '';
say TAB9, $checker->note;
if (defined($checker->content) && length($checker->content)) {
$Text::Wrap::columns = SCREENWIDTH - 10;
say TAB9, "-----BEGIN CONTENT-----";
say wrap(TAB9, TAB9, lf_normalize($checker->content));
say TAB9, "-----END CONTENT-----";
}
}
if ($result && !$checker->status) {
wow("%s", $checker->error);
} elsif (!$result) {
nope("%s", $checker->error);
}
# Save data to database
my %data = (
lib/App/MonM.pm view on Meta::CPAN
$ostat = 0;
$status = 0;
}
$tbl->row($name, $info->{type} || 'http',
$last ? dtf(DATE_FORMAT, $last) : "",
$ostat ? $ostat > 0 ? 'PASSED' : 'UNKNOWN' : 'FAILED',
);
unless ($ostat) {
push @errors, sprintf("%s (%s >>> %s)", $name, $info->{source} || '', $info->{message} || ''), "";
}
#say(explain($info));
}
$tbl->hr;
}
$tbl->row('SUMMARY', "", "", $noc ? $status ? 'PASSED' : 'FAILED' : 'UNKNOWN');
# Get SendMail config
my $sendmail = hash($self->config('channel'), "SendMail");
# Get output file
my $outfile = $self->option("outfile");
lib/App/MonM.pm view on Meta::CPAN
lvalue(\%chckts, $v->{name} // '__default', "target") // 'status',
variant_stf($v->{source} // '', $src_len),
$v->{"time"} ? dtf(DATE_FORMAT, $v->{"time"}) : '',
lvalue(\%chckts, $v->{name} // '__default', "interval") || 0,
$ostat ? $ostat > 0 ? 'PASSED' : 'UNKNOWN' : 'FAILED'
);
}
$tbl->hr;
$tbl->row('SUMMARY', "", "", "", "", "", $status ? 'PASSED' : 'FAILED');
say $tbl->draw();
return $status;
});
sub trigger {
my $self = shift;
my %args = @_;
my $name = $args{name} || 'virtual';
my $message = $args{message} // "";
my $source = $args{source} // "";
lib/App/MonM.pm view on Meta::CPAN
STATUS => $args{status} ? 'OK' : 'ERROR',
RESULT => $args{result} ? 'PASSED' : 'FAILED',
NOTE => $args{note} // '',
});
my $exe_err = '';
my $exe_out = execute($cmd, undef, \$exe_err);
my $exe_stt = ($? >> 8) ? 0 : 1;
if ($exe_stt) {
my $msg = sprintf("# %s", $cmd);
print cyan MARKER_INFO;
say " ", $msg;
$self->log_info($msg);
if (defined($exe_out) && length($exe_out) && $self->verbosemode) {
say $exe_out if IS_TTY;
$self->log_info($exe_out);
}
} else {
my $msg = sprintf("Can't execute trigger %s", $cmd);
print red MARKER_FAIL;
say " ", $msg;
$self->log_error($msg);
push @errs, $msg;
if ($exe_err) {
chomp($exe_err);
nope($exe_err);
$self->log_error($exe_err);
push @errs, $exe_err;
}
}
}
lib/App/MonM.pm view on Meta::CPAN
}
sub notify {
my $self = shift;
my %args = @_;
my $name = $args{name} || 'virtual';
my $sendto = $args{sendto} || [];
my $subject = $args{subject};
my @errors;
my $errs = $args{errors};
push @errors, @$errs if is_array($errs);
#say(explain(\%args));
# Header
my @header;
push @header, (
["Checkit", $name], # Checkit name
["Type", $args{type} || 'http'], # Checkit type
["Result", $args{result} ? 'PASSED' : 'FAILED'], # Checkit result
["Source", $args{source} || "UNKNOWN"], # Source string
["Status", $args{status} ? 'OK' : 'ERROR'], # Checkit status (NO RESULT!!);
["Code", $args{code} // "UNKNOWN"], # Checkit code value
lib/App/MonM.pm view on Meta::CPAN
$self->log_error($this->error);
}
# Check sending status
if ($sent) {
my $msg = $this->channel->error
? sprintf("Message was not sent to %s: %s", $message->recipient, $this->channel->error)
: sprintf("Message has been sent to %s", $message->recipient);
if ($this->channel->error) { print red MARKER_FAIL }
else { print cyan MARKER_INFO }
say " ", $msg;
$self->log_debug($msg);
} else {
my $err = sprintf("Message was not sent to %s: %s", $message->recipient, $this->channel->error || "unknown error");
print red MARKER_FAIL;
print " ";
nope($err);
$self->log_warning($err);
}
return 1;
lib/App/MonM/Channel/Email.pm view on Meta::CPAN
Defaults to 25 for non-SSL, 465 for 'ssl', 587 for 'starttls'
Set timeout TIMEOUT
Maximum time in secs to wait for server
Default: 120
Set helo HELOSTRING
SMTP attribute. What to say when saying HELO. Optional
No default
Set sasl_username USERNAME
This is sasl_username SMTP attribute. Optional
Contains the username to use for auth
Set sasl_password PASSWORD
( run in 1.931 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )