App-MonM

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


1.06 Thu  4 Jul 11:36:05 MSK 2019
    * CTKlib v2.00 adapted

1.07 Mon 15 Jul 08:17:00 MSK 2019
    * Documentation modified
    * Configuration skeleton modified

1.08 Tue 06 Sep 2022 19:41:34 MSK
    * Added new features
    * Added CTK::Timeout to checkits
    * Added -D (daemondir) flag for monm program
    * Added -s (safemode) flag for monmd program
    * Bug fixed: corrected the info method, added condition for SQLite file information
    * Added BasedOn directive to Channel od user context

1.09 Fri 16 Sep 2022 10:31:31 MSK
    * App::MonM::QNotifier: Added the getChanelsBySendTo method
    * Optimized the notify methods

bin/monm_ftp  view on Meta::CPAN

Password for connection

=item B<-P PORTNUMBER, --port=PORTNUMBER>

Port number

Default: 21

=item B<-t SECT, --timeout=SECS>

Timeout value, secs

Default: 120

=item B<-u USERNAME, --user=USERNAME>

Username for connection

=back

=head1 DESCRIPTION

bin/monm_ftp  view on Meta::CPAN

Getopt::Long::Configure("bundling");
GetOptions($options,
    # Information
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page

    # General
    "user|username|login|u=s",  # Username
    "password|passwd|pass|p=s", # Password
    "port|P=i",                 # Port
    "timeout|time|t=i",         # Timeout
    "active|act|a",             # Active mode

) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};

my $host        = shift(@ARGV) || HOST;
my $port        = $options->{port} || PORT;
my $timeout     = $options->{timeout} || TIMEOUT;
my $user        = $options->{user} // "anonymous";
my $password    = $options->{password} // "anonymous\@example.com";
my $passive     = $options->{active} ? 0 : 1;

my $err = '';
my $ftp = Net::FTP->new($host, (
    Port    => $port,
    Timeout => $timeout,
    Passive => $passive,
)) or do {
    $err = sprintf("Can't connect to %s: %s", $host, $@);
};

# Login
unless ($err) {
    $ftp->login($user, $password) or do {
        $err = sprintf("Can't login to %s: %s", $host, $ftp->message);
    };

bin/monm_icmp  view on Meta::CPAN


=item B<-P PORTNUMBER, --port=PORTNUMBER>

The port option is only valid for a udp, tcp or stream ping, and will not do what
you think it does. Ping returns true when we get a "Connection refused"!

Default: echo port

=item B<-t SECT, --timeout=SECS>

Timeout value, secs

Default: 5

=back

=head1 DESCRIPTION

ICMP (Ping) checker for App::MonM (TCP/UDP/ICMP)

=head1 DEPENDENCES

bin/monm_icmp  view on Meta::CPAN


my $options = {};
Getopt::Long::Configure("bundling");
GetOptions($options,
    # Information
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page

    # General
    "protocol|proto|prot|p=s",  # Protocol
    "timeout|time|t=i",         # Timeout
    "port|P=i",                 # Port
    "bytes|byte|b=i",           # Bytes

) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};

my $host        = shift(@ARGV) || HOST;
my $port        = $options->{port} || 0;
my $timeout     = $options->{timeout} || TIMEOUT;

bin/monm_nginx  view on Meta::CPAN

Show long help information and quit

=item B<-q URL, --query=URL>

Request URL

Default: http://localhost/server-status

=item B<-t SECT, --timeout=SECS>

Timeout value, secs

Default: 60

=back

=head1 DESCRIPTION

Nginx checker for App::MonM (http_stub_status_module)

=head2 NAMES

bin/monm_nginx  view on Meta::CPAN


my $options = {};
Getopt::Long::Configure("bundling");
GetOptions($options,
    # Information
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page

    # General
    "url|query|q=s",        # URL
    "timeout|time|t=i",     # Timeout

) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};

my $name        = shift(@ARGV);
my $timeout     = $options->{timeout} || TIMEOUT;
my $url         = $options->{url} // URL;

# Check

bin/monm_pop3  view on Meta::CPAN

Port number

Default: 110

=item B<-s, --ssl, --usessl>

Use SSL (995 protocol)

=item B<-t SECT, --timeout=SECS>

Timeout value, secs

Default: 60

=item B<-u USERNAME, --user=USERNAME>

Username for connection

=back

=head1 DESCRIPTION

bin/monm_pop3  view on Meta::CPAN

Getopt::Long::Configure("bundling");
GetOptions($options,
    # Information
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page

    # General
    "user|username|login|u=s",  # Username
    "password|passwd|pass|p=s", # Password
    "port|P=i",                 # Port
    "timeout|time|t=i",         # Timeout
    "ssl|usessl|s",             # Use SSL

) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};

my $host        = shift(@ARGV) || HOST;
my $port        = $options->{port} || PORT;
my $timeout     = $options->{timeout} || TIMEOUT;
my $user        = $options->{user} // '';

bin/monm_smtp  view on Meta::CPAN

Show long help information and quit

=item B<-P PORTNUMBER, --port=PORTNUMBER>

Port number

Default: 25

=item B<-t SECT, --timeout=SECS>

Timeout value, secs

Default: 60

=back

=head1 DESCRIPTION

SMTP checker for App::MonM

=head1 DEPENDENCES

bin/monm_smtp  view on Meta::CPAN


my $options = {};
Getopt::Long::Configure("bundling");
GetOptions($options,
    # Information
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page

    # General
    "port|P=i",                 # Port
    "timeout|time|t=i",         # Timeout

) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};

my $host        = shift(@ARGV) || HOST;
my $port        = $options->{port} || PORT;
my $timeout     = $options->{timeout} || TIMEOUT;

my $err = '';
try {
    my $smtp = Net::SMTP->new(
        Host    => $host,
        Timeout => $timeout,
        Port    => $port,
    );
    if ($smtp) {
        my $domainresult = $smtp->domain() || ''; # warn $smtp->message();
        $smtp->quit;
        $err = sprintf("SMTP domain not defined (host %s, port: %s)", $host, $port) unless $domainresult;
    } else {
        $err = sprintf("Host %s not reachable on port %s",$host, $port);
    }
}

bin/monm_snmp  view on Meta::CPAN

Default: localhost

=item B<-S, --strict>

Enable strict mode. All OIDs must be only as is long-format strings

    monm_snmp -S .1.3.6.1.2.1.1.1.0

=item B<-t MICROSECS, --timeout=MICROSECS>

Timeout of SNMP requests in microseconds

Default: 1000000

=item B<-T, --table>

Enable table mode

    monm_snmp -T ifTable
    monm_snmp -T IF-MIB::ifTable

bin/monm_snmp  view on Meta::CPAN

Getopt::Long::Configure("bundling");
GetOptions($options,
    # Information
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page

    # General
    "host|server|s=s",      # Host SNMT (default = localhost)
    "strict|S",             # Strict mode: 0/1
    "community|comm|c=s",   # Community (default = public)
    "timeout|time|t=i",     # Timeout (default = 1000000)
    "version|v=s",          # Version (default = 2c)
    "table|astable|tab|T",  # As table
    "mibs|mib|M=s",         # MIBS

) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};

my $host        = $options->{host} || HOST;
my $timeout     = $options->{timeout} || TIMEOUT;

bin/monm_snmp  view on Meta::CPAN

# Loading MIBs
$ENV{'MIBS'} = $options->{mibs} if $options->{mibs};
&SNMP::initMib();

# Create SNMP::Session
my $snmp = SNMP::Session->new(
        DestHost    => $host,
        Version     => $ver,
        Community   => $community,
        Retries     => RETRIES,
        Timeout     => $timeout,
        UseSprintValue => 1,
) or do {
    print STDERR sprintf("Connect failed to %s (%s)\n", $host, $community);
    print ERROR, "\n";
    exit 1;
};

# Test request
my $testval = '';
try {

bin/monm_ssh  view on Meta::CPAN

Show long help information and quit

=item B<-P PORTNUMBER, --port=PORTNUMBER>

Port number

Default: 22

=item B<-t SECT, --timeout=SECS>

Timeout value, secs

Default: 60

=back

=head1 DESCRIPTION

SSH checker for App::MonM

=head1 DEPENDENCES

bin/monm_ssh  view on Meta::CPAN


my $options = {};
Getopt::Long::Configure("bundling");
GetOptions($options,
    # Information
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page

    # General
    "port|P=i",                 # Port
    "timeout|time|t=i",         # Timeout

) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};

my $host        = shift(@ARGV) || HOST;
my $port        = $options->{port} || PORT;
my $timeout     = $options->{timeout} || TIMEOUT;

my $err = '';
try {
    my $t = Net::Telnet->new(
        Timeout => $timeout,
        Host    => $host,
        Port    => $port,
    );
    my $banner = $t->getline;
    if ($banner && $banner =~ /SSH/i) {
        # OK
    } else {
        $err = $banner || sprintf("Host %s not reachable on port %s", $host, $port);
    }
}

eg/checkit-dbi.conf  view on Meta::CPAN

<Checkit "dbi">
    Enable      on

    Type        dbi
    DSN         DBI:mysql:database=test;host=192.168.0.1
    SQL         "SELECT 'OK' AS OK FROM DUAL" # By default
    User        user
    Password    password
    Timeout     15 # Connect and request timeout, secs
    Set RaiseError 0
    Set PrintError 0
    Set mysql_enable_utf8 1

    Target      content
    IsTrue      OK
</Checkit>

lib/App/MonM/Channel/Command.pm  view on Meta::CPAN


        # Command mask
        #Command curl -d "[MESSAGE]" "https://sms.com/?[MSISDN]"
        Command "echo "[NUMBER]; [SUBJECT]; [MESSAGE]" >> /tmp/fakesms.txt"

        # Schedule
        #At Sun-Sat[00:00-23:59]

        # Command Options
        Content body
        Timeout 20s

    </Channel>

=head1 DESCRIPTION

This module provides command method that send the content
of the message to an external program

=over 4

lib/App/MonM/Channel/Command.pm  view on Meta::CPAN

    Content none

Suppress sending content to command STDIN (no content - no problems)

Default: body

=item B<To>

Recipient address (email) or name

=item B<Timeout>

    Timeout 20s

Sets timeout for command running

    Timeout off
    Timeout 0

Disable timeout

Default: 20 sec

See also description of format for the timeout values L<App::MonM::Util/getTimeOffset>

=item B<Type>

    Type    Command

lib/App/MonM/Checkit/Command.pm  view on Meta::CPAN

Or with STDIN pipe:

    <Checkit "foo">

        Enable   yes
        Type     command
        Command  perl
        Content  "print q/Oops/"
        Target   content
        IsTrue   Oops
        Timeout  5s

        # . . .

    </Checkit>

=head1 DESCRIPTION

Checkit Command subclass

=head2 check

lib/App/MonM/Checkit/Command.pm  view on Meta::CPAN

Default: none

=item B<Content>

    Content     "print q/Blah-Blah-Blah/"

Sets the content for command STDIN

Default: no content

=item B<Timeout>

    Timeout    1m

Defines the execute timeout

Default: off

=back

=head1 HISTORY

See C<Changes> file

lib/App/MonM/Checkit/Command.pm  view on Meta::CPAN

use CTK::Util qw/ execute /;
use CTK::ConfGenUtil;
use App::MonM::Util qw/getTimeOffset run_cmd/;

sub check {
    my $self = shift;
    my $type = $self->type;
    return $self->maybe::next::method() unless $type && $type eq 'command';

    # Init
    my $to = CTK::Timeout->new(); # Create the timeout object
    my $command = lvalue($self->config, 'command') || '';
    my $content = lvalue($self->config, 'content') // '';
       $content = undef unless length $content;
    my $timeout = getTimeOffset(lvalue($self->config, 'timeout') || 0);
    unless (length($command)) {
        $self->status(0);
        $self->source("NOOP");
        $self->message('Command not specified');
        return;
    }

lib/App/MonM/Checkit/DBI.pm  view on Meta::CPAN

=head1 SYNOPSIS

    <Checkit "foo">

        Enable  yes
        Type    dbi
        DSN     DBI:mysql:database=DBNAME;host=127.0.0.1
        SQL     "SELECT 'OK' AS OK FROM DUAL"
        User    USER
        Password PASSWORD
        Timeout 15s
        Set RaiseError  0
        Set PrintError     0
        Set mysql_enable_utf8   0

        # . . .

    </Checkit>

=head1 DESCRIPTION

lib/App/MonM/Checkit/DBI.pm  view on Meta::CPAN

Defines DBI Attributes. This directive allows you set case sensitive DBI Attributes.
There can be several such directives.

Examples:

    Set sqlite_unicode      1
    Set mysql_enable_utf8   0

Default: no specified

=item B<Timeout>

    Timeout    1m

Defines the timeout of DBI requests

Default: off

=item B<Username>, B<Password>

    User        USER
    Password    PASSWORD

lib/App/MonM/Checkit/HTTP.pm  view on Meta::CPAN


Defines HTTP request headers. This directive allows you set case sensitive HTTP headers.
There can be several such directives.

Examples:

    Set User-Agent  "MyAgent/1.00"
    Set X-Token     "mdffltrtkmdffltrtk"


=item B<Timeout>

    Timeout    1m

Defines the timeout of HTTP request

Default: 180

=item B<URL>

    URL     https://www.example.com

Defines the URL for HTTP/HTTPS requests

lib/App/MonM/ConfigSkel.pm  view on Meta::CPAN

<Channel SMSGW>
    Type    Command
    Enable  on

    #At Sun-Sat[08:00-19:00]

    # Default phone number (MSISDN)
    To +1-424-254-5300

    # SMS Gateway timeout (to SMDP server, eg.)
    Timeout 10s

    # Command for sending
    #Command "echo "[MSISDN]; [SUBJECT]; [MESSAGE]" >> /tmp/fakesms.txt"
    #Command "sendalertsms "[MSISDN]" "[SUBJECT]" "[MESSAGE]""
    #Command "monm_dbi -s SIDNAME -u USER -p PASSWORD -q "SELECT SMS_FUNCTION('[MSISDN]', '[MESSAGE]') FROM DUAL" [MSISDN]"
    #Command "smsbox -D /tmp/smsbox create [MSISDN] "[MESSAGE]""
    #Command curl -d "[MESSAGE]" "https://sms.com/?[MSISDN]"
    Command "echo "[MSISDN];[MESSAGE]" >> /tmp/fakesms.txt"

    #

lib/App/MonM/ConfigSkel.pm  view on Meta::CPAN

    #
    # Default: GET
    #
    #Method    GET

    #
    # Defines the timeout of HTTP requests
    #
    # Default: 180
    #
    #Timeout    180

    #
    # Defines HTTP request headers.
    # This directive allows you set case sensitive HTTP headers.
    # There can be several such directives.
    #
    # Set User-Agent  "MyAgent/1.00"
    # Set X-Token     "mdffltrtkmdffltrtk"

    #

lib/App/MonM/ConfigSkel.pm  view on Meta::CPAN

    # Defines database credential: username and password
    #
    #User        USER
    #Password    PASSWORD

    #
    # Defines the timeout of DBI requests
    #
    # Default: off
    #
    #Timeout    20s

    #
    # Defines DBI Attributes.
    # This directive allows you set case sensitive DBI Attributes.
    # There can be several such directives.
    #
    #Set sqlite_unicode 1
    #
    #Set RaiseError     0
    #Set PrintError     0

lib/App/MonM/ConfigSkel.pm  view on Meta::CPAN

    #
    # Default: no content
    #
    Content     "print q/Blah-Blah-Blah/"

    #
    # Defines the execute timeout
    #
    # Default: off
    #
    #Timeout    1m

</Checkit>

-----END FILE-----

-----BEGIN FILE-----
Name: checkit-foo.conf
File: conf.d/checkit-foo.conf
Mode: 644

lib/App/MonM/Util.pm  view on Meta::CPAN

        message => $r->{exit_code} ? 'ERROR' : 'OK',
    );
    chomp($ret{stderr});
    chomp($ret{stdout});

    # Time outed
    if ($r->{killed_by_signal}) {
        $ret{status} = 0;
        $ret{message} = 'ERROR';
        $ret{code} = -1;
        $ret{stderr} = sprintf("Timeouted: killed by signal [%s]", $r->{killed_by_signal});
    }

    # Exitval
    if ($ret{code} && !length($ret{stderr})) {
        $ret{stderr} = sprintf("Exitval=%d", $ret{code});
    }

    return {%ret};
}



( run in 0.376 second using v1.01-cache-2.11-cpan-4d50c553e7e )