
#                                      Copyright 2024 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

package Whostmgr::360Monitoring::Agent::Plugins::Mysql;

use cPstrict;
use Types::Common::Numeric qw(PositiveInt);
use Types::Common::String  qw(NonEmptyStr);
use Moo;
use Whostmgr::360Monitoring::Moo;

extends 'Whostmgr::360Monitoring::Agent::Plugins';

conf_has 'database' => (
    isa     => NonEmptyStr,
    default => 'mysql',
);

conf_has 'socket' => (
    isa => PositiveInt,
);

conf_has 'username' => (
    isa     => NonEmptyStr,
    default => 'root',
);

conf_has 'password' => (
    isa => NonEmptyStr,
);

conf_has 'host' => (
    isa     => NonEmptyStr,
    default => '127.0.0.1',
);

conf_has 'port' => (
    isa     => PositiveInt,
    default => 3306,
);

around 'BUILDARGS' => sub ( $orig, $class, @args ) {
    my $args = $args[0];
    if ( defined $args->{socket} and defined $args->{host} || defined $args->{port} ) {
        die "Do not supply a socket (udp) if also supplying tcp credentials";
    }
    return $class->$orig(@args);
};

1;

__END__

=head1 NAME

Whostmgr::360Monitoring::Agent::Plugins::Mysql - A class for the Mysql plugin

=head1 DESCRIPTION

A child class of L<Whostmgr::360Monitoring::Agent::Plugins>. More information can be found at L<Agent360 Plugin Documentation|https://docs.360monitoring.com/docs/mysql-plugin>. The upstream implementation can be found at the L<Agent360 Repository on Github|https://github.com/plesk/agent360/tree/master/agent360/plugins/mysql.py>.

Usage for plugin configuration changes can be found in the L<Agent|Whostmgr::360Monitoring::Agent> class.

=head1 ROLES

=over 15

=item L<Serializable|Whostmgr::360Monitoring::Agent::Plugins::Roles::Serializable>

=item L<Enableable|Whostmgr::360Monitoring::Agent::Plugins::Roles::Enableable>

=item L<Runnable|Whostmgr::360Monitoring::Agent::Plugins::Roles::Runnable>


=back

=head1 ATTRIBUTES

=over 15

=item database

An attribute representing database as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.

=item socket

An attribute representing socket as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.

=item username

An attribute representing username as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.

=item password

An attribute representing password as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.

=item host

An attribute representing host as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.

=item port

An attribute representing port as defined in the GitHub repo linked in the SEE ALSO. Sourced from INI. Serializes to INI.


=back

=head1 SEE ALSO

=over 8

=item L<Implementation of Plugin on Github|https://github.com/plesk/agent360/tree/master/agent360/plugins/mysql.py>

=item L<Documentation on Agent360|https://docs.360monitoring.com/docs/mysql-plugin>

=back
