Fix mySQL Partitioning

This commit is contained in:
ASCE002 2015-02-23 15:53:53 +01:00
parent da2c18192a
commit c91cbcaa13
1 changed files with 47 additions and 2 deletions

View File

@ -37,10 +37,11 @@ package apps::centreon::mysql::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
use base qw(centreon::plugins::script_sql);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
# $options->{options} = options object
@ -50,16 +51,60 @@ sub new {
'partitioning' => 'apps::centreon::mysql::mode::partitioning',
'pollerdelay' => 'apps::centreon::mysql::mode::pollerdelay',
);
$self->{sql_modes}{mysqlcmd} = 'database::mysql::mysqlcmd';
return $self;
}
sub init {
my ($self, %options) = @_;
$self->{options}->add_options(
arguments => {
'host:s@' => { name => 'db_host' },
'port:s@' => { name => 'db_port' },
}
);
$self->{options}->parse_options();
my $options_result = $self->{options}->get_options();
$self->{options}->clean();
if (defined($options_result->{db_host})) {
@{$self->{sqldefault}->{dbi}} = ();
@{$self->{sqldefault}->{mysqlcmd}} = ();
for (my $i = 0; $i < scalar(@{$options_result->{db_host}}); $i++) {
$self->{sqldefault}->{dbi}[$i] = { data_source => 'mysql:host=' . $options_result->{db_host}[$i] };
$self->{sqldefault}->{mysqlcmd}[$i] = { host => $options_result->{db_host}[$i] };
if (defined($options_result->{db_port}[$i])) {
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $options_result->{db_port}[$i];
$self->{sqldefault}->{mysqlcmd}[$i]->{port} = $options_result->{db_port}[$i];
}
}
}
$self->SUPER::init(%options);
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Specific Centreon Indicators.
Check MySQL Server.
=over 8
You can use following options or options from 'sqlmode' directly.
=item B<--host>
Hostname to query.
=item B<--port>
Database Server Port.
=back
=cut