App-MonM

 view release on metacpan or  search on metacpan

bin/monm_dbi  view on Meta::CPAN


monm_dbi - tiny DBI checker for App::MonM

=head1 VERSION

Version 1.01

=head1 SYNOPSIS

    monm_dbi [ --dsn=DSN | --sid=SID ] [ --user=DB_USERNAME ]
             [ --password=DB_PASSWORD ] [ --sql=SQL ]
             [-a "DBI_ATTR_1=Value"] [-a "DBI_ATTR_n=Value"]

    monm_dbi -n "DBI:mysql:database=test;host=192.0.0.1"
             -u user -p password -q "SELECT * FROM mytable"
             -a "mysql_enable_utf8=1" -a "PrintError=0"

=head1 OPTIONS

=over 4

=item B<-a "DBI_Attribute=Value">

    -a "DBI_Attribute=Value"
    -a "DBI_Attribute Value"

bin/monm_dbi  view on Meta::CPAN

See also L<DBI>

=item B<-h, --help>

Show short help information and quit

=item B<-H, --longhelp>

Show long help information and quit

=item B<-p DB_PASSWORD, --password=DB_PASSWORD>

DB password

=item B<-q SQL, --sql=SQL>

SQL query string

=item B<-s SID, --sid=SID>

Oracle SID (Service Name)

B<NOTE!> For Oracle only!

bin/monm_dbi  view on Meta::CPAN

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

    # General
    "dsn|n=s",              # DSN
    "sid|orasid|s=s",       # SID
    "user|username|login|u=s",  # DB Login
    "password|passwd|pass|p=s", # DB Password
    "sql|query|q=s",        # SQL
    "attr|attribute|a=s@",  # List of attributes

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

my $sw = (SCREENWIDTH() - 9);
my $status = 1;

bin/monm_dbi  view on Meta::CPAN

    my $s = shift // '';
    my $l = length($s);
    return $s.($l<$sw?('.'x($sw-$l)):'').' '
}

my $ctk = CTK->new();
my $sid         = $options->{sid} || "";
my $default_dsn = sprintf("DBI:Oracle:%s", $sid) if $sid;
my $dsn         = $options->{dsn} || $default_dsn || DSN;
my $user        = $options->{user} // '';
my $password    = $options->{password} // '';
my $sql         = $options->{sql} || SQL;
my $attr_src    = $options->{attr} || DBI_ATTRIBUTES;
my $attr        = [];
foreach my $v (@$attr_src) {
    $v =~ s/\=/ /;
    push @$attr, $v;
}
START: printf("START TRANSACTION [$$] {TimeStamp: %s}\n", $ctk->tms);

# Connect
print _start(sprintf("> 1/7 Connecting to \"%s\"", $dsn));
my $ora = DBI->connect($dsn, $user, $password, set2attr($attr));
if ($ora) {
    print IS_TTY ? green(PASSED) : PASSED, "\n";
} else {
    print IS_TTY ? red(FAILED) : FAILED, "\n";
    print STDERR $DBI::errstr, "\n";
    $status = 0;
    goto FINISH;
}

# Prepare

bin/monm_ftp  view on Meta::CPAN

=head1 NAME

monm_ftp - FTP checker for App::MonM

=head1 VERSION

Version 1.01

=head1 SYNOPSIS

    monm_ftp [ --user=USERNAME ] [ --password=PASSWORD ]
             [ --port=PORTNUMBER ] [-t SECS] [-a] HOST

=head1 OPTIONS

=over 4

=item B<-a, --active>

Switch to ACTIVE mode

Default: off (passive mode)

=item B<-h, --help>

Show short help information and quit

=item B<-H, --longhelp>

Show long help information and quit

=item B<-p PASSWORD, --password=PASSWORD>

Password for connection

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

Port number

Default: 21

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

bin/monm_ftp  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
    "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);
    };
}

# Get list
unless ($err) {
    my @ls = $ftp->ls();
    foreach my $l (@ls) {
        next unless defined $l;
        printf "# %s\n", $l if IS_TTY;

bin/monm_pop3  view on Meta::CPAN

=head1 NAME

monm_pop3 - POP3 checker for App::MonM

=head1 VERSION

Version 1.01

=head1 SYNOPSIS

    monm_pop3 [ --user=USERNAME ] [ --password=PASSWORD ]
              [ --port=PORTNUMBER ] [ -s ]  [-t SECS] HOST

=head1 OPTIONS

=over 4

=item B<-h, --help>

Show short help information and quit

=item B<-H, --longhelp>

Show long help information and quit

=item B<-p PASSWORD, --password=PASSWORD>

Password for connection

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

Port number

Default: 110

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

bin/monm_pop3  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
    "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} // '';
my $password    = $options->{password} // '';
my $ssl         = $options->{ssl} ? 1 : 0;

my $err = '';
try {
    my $pop = Mail::POP3Client->new(
        USER     => $user,
        PASSWORD => $password,
        HOST     => $host,
        PORT     => $port,
        TIMEOUT  => $timeout,
        USESSL   => $ssl,
    );
    unless ($pop->Connect()) {
        $err = $pop->Message() || sprintf("Can't connect to POP3 server: %s", $host);
    }
    $pop->Close();
}

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>

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

<Checkit "ext-dbi">
    Enable      on

    Type        command
    Command     "monm_dbi -n "DBI:mysql:database=test;host=192.168.0.1" -u user -p password"

</Checkit>

eg/checkit-http-ok.conf  view on Meta::CPAN

<Checkit "http-ok">
    Enable      on
    URL         http://user:password@localhost/ok.txt
    Target      content
    IsTrue      !!perl/regexp (?--xsm:^(Ok))
</Checkit>

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

        #    Path        ./payment.pdf
        #</Attachment>

        # SMTP options
        # If there are requirements to the case sensitive of parameter
        # names, use the "Set" directives
        # By default will use <Channel SendMail> section of general config file
        Set host 192.168.0.1
        Set port 25
        #Set sasl_username TestUser
        #Set sasl_password MyPassword
        Set timeout 20

    </Channel>

=head1 DESCRIPTION

This module provides email method

=over 4

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

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

This is sasl_password SMTP attribute. Optional

    Set ssl 1

This is ssl SMTP attribute: if 'starttls', use STARTTLS;
if 'ssl' (or 1), connect securely; otherwise, no security.

Default: undef

See L<Email::Sender::Transport::SMTP>

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


Defines the timeout of DBI requests

Default: off

=item B<Username>, B<Password>

    User        USER
    Password    PASSWORD

Defines database credential: username and password

Default: no specified

=back

=head1 HISTORY

See C<Changes> file

=head1 TO DO

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

    my $type = $self->type;
    return $self->maybe::next::method() unless $type && ($type eq 'dbi' or $type eq 'db');

    # Init
    my $dsn = lvalue($self->config, 'dsn') || DEFAULT_DSN;
       $self->source($dsn);
    my $timeout = getTimeOffset(lvalue($self->config, 'timeout') || DEFAULT_TIMEOUT);
    my $attr = set2attr($self->config);
    my $sql = lvalue($self->config, 'sql') // lvalue($self->config, 'content') // DEFAULT_SQL;
    my $user = lvalue($self->config, 'user');
    my $password = lvalue($self->config, 'password');

    # DB
    my $db = CTK::DBI->new(
        -dsn    => $dsn,
        -debug  => 0,
        -username => $user,
        -password => $password,
        -attr     => $attr,
        $timeout ? (
            -timeout_connect => $timeout,
            -timeout_request => $timeout,
        ) : (),
    );
    my $dbh = $db->connect if $db;

    # Connect
    my @resa = ();

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

=item B<URL>

    URL     https://www.example.com

Defines the URL for HTTP/HTTPS requests

Default: http://localhost

Examples:

    URL     https://user:password@www.example.com
    URL     https://www.example.com

=back

=head1 HISTORY

See C<Changes> file

=head1 TO DO

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

#    DSN "dbi:SQLite:dbname=/tmp/monm/monm.db"
#    Set RaiseError     0
#    Set PrintError     0
#    Set sqlite_unicode 1
# </Store>
#
# MySQL example:
# <Store>
#    DSN "DBI:mysql:database=monm;host=mysql.example.com"
#    User username
#    Password password
#    Set RaiseError          0
#    Set PrintError          0
#    Set mysql_enable_utf8   1
#    Set mysql_auto_reconnect 1
# </Store>
#

#
# REQUIRED channel (SendMail) that defines default options for sending
# email-notifications and email-reports

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

    #    Disposition attachment
    #    Path        ./payment.pdf
    #</Attachment>

    # SMTP options
    # If there are requirements to the case sensitive of parameter
    # names, use the "Set" directives
    Set host 192.168.0.1
    Set port 25
    #Set sasl_username TestUser
    #Set sasl_password MyPassword
    Set timeout 20
</Channel>

#
# OPTIONAL channel (SMSGW) that defines default options for sending
# SMS-notifications
#
<Channel SMSGW>
    Type    Command
    Enable  on

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


    ###################################
    ## For HTTP requests (Type http) ##
    ###################################

    #
    # Defines the URL for HTTP/HTTPS requests
    #
    # Default: http://localhost
    #
    #URL   https://user:password@www.example.com
    URL    https://www.example.com

    #
    # Defines the HTTP method: GET, POST, PUT, HEAD, PATCH, DELETE, and etc.
    #
    # Default: GET
    #
    #Method    GET

    #

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

    #DSN     DBI:mysql:database=DATABASE;host=HOSTNAME

    #
    # Specifies the SQL query string (content)
    #
    # Default: "SELECT 'OK' AS OK FROM DUAL"
    #
    #SQL "SELECT 'OK' AS OK FROM DUAL"

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

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

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


Version 1.01

=head1 SYNOPSIS

    use App::MonM::Store;

    my $store = App::MonM::Store->new(
        dsn => "DBI:mysql:database=monm;host=mysql.example.com",
        user => "username",
        password => "password",
        set => [
            "RaiseError        0",
            "PrintError        0",
            "mysql_enable_utf8 1",
        ],
    );
    die($store->error) if $store->error;

=head1 DESCRIPTION

DBI interface for checkit's data storing. This module provides store methods

=head2 new

    my $store = App::MonM::Store->new(
        dsn => "DBI:mysql:database=monm;host=mysql.example.com",
        user => "username",
        password => "password",
        set => [
            "RaiseError        0",
            "PrintError        0",
            "mysql_enable_utf8 1",
        ],
    );

Creates DBI object

=head2 add

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


use App::MonM::Const;
use App::MonM::Util qw/ set2attr /;

use constant {
    DB_FILENAME         => 'monm.db',
    DEFAULT_DSN_MASK    => 'dbi:SQLite:dbname=%s',
    DEFAULT_DBI_ATTR    => {
            dsn         => '', # See DEFAULT_DSN_MASK
            user        => '',
            password    => '',
            set         => [
                    'RaiseError 0',
                    'PrintError 0',
                    'sqlite_unicode 1',
                ],
        },
};

use constant CHECKIT_DDL => <<'DDL';
CREATE TABLE IF NOT EXISTS monm (

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

        }
    }
    my $file = $args{file} || DB_FILENAME;
    my $dsn = $args{dsn} || sprintf(DEFAULT_DSN_MASK, $file);

    # DB
    my $db = CTK::DBI->new(
        -dsn    => $dsn,
        -debug  => 0,
        -username => $args{'user'},
        -password => $args{'password'},
        -attr     => set2attr($args{'set'}),
        $args{timeout} ? (
            -timeout_connect => $args{timeout},
            -timeout_request => $args{timeout},
        ) : (),
    );
    my $dbh = $db->connect if $db;

    # SQLite
    my $fnew = 0;



( run in 0.696 second using v1.01-cache-2.11-cpan-49f99fa48dc )