This commit is contained in:
Colin Gagnaire 2019-08-01 17:55:27 +02:00
commit d4e22ad309
5 changed files with 56 additions and 27 deletions

View File

@ -34,18 +34,19 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'config:s' => { name => 'config' },
"config:s" => { name => 'config' }, 'language:s' => { name => 'language', default => 'en' },
"language:s" => { name => 'language', default => 'en' }, 'dfsr' => { name => 'dfsr' },
"dfsr" => { name => 'dfsr' }, 'noeventlog' => { name => 'noeventlog' },
"noeventlog" => { name => 'noeventlog' }, 'nomachineaccount' => { name => 'nomachineaccount' },
"nomachineaccount" => { name => 'nomachineaccount' }, 'timeout:s' => { name => 'timeout', default => 30 },
"timeout:s" => { name => 'timeout', default => 30 }, });
});
$self->{os_is2003} = 0; $self->{os_is2003} = 0;
$self->{os_is2008} = 0; $self->{os_is2008} = 0;
$self->{os_is2012} = 0; $self->{os_is2012} = 0;
$self->{os_is2016} = 0;
$self->{msg} = { global => undef, ok => undef, warning => undef, critical => undef }; $self->{msg} = { global => undef, ok => undef, warning => undef, critical => undef };
return $self; return $self;
@ -71,12 +72,15 @@ sub check_version {
# 5.1, 5.2 => XP/2003 # 5.1, 5.2 => XP/2003
# 6.0, 6.1 => Vista/7/2008 # 6.0, 6.1 => Vista/7/2008
# 6.2, 6.3 => 2012 # 6.2, 6.3 => 2012
# 10.0 => 2016, 2019
if ($ver_major == 5 && ($ver_minor == 1 || $ver_minor == 2)) { if ($ver_major == 5 && ($ver_minor == 1 || $ver_minor == 2)) {
$self->{os_is2003} = 1; $self->{os_is2003} = 1;
} elsif ($ver_major == 6 && ($ver_minor == 0 || $ver_minor == 1)) { } elsif ($ver_major == 6 && ($ver_minor == 0 || $ver_minor == 1)) {
$self->{os_is2008} = 1; $self->{os_is2008} = 1;
} elsif ($ver_major == 6 && ($ver_minor == 2 || $ver_minor == 3)) { } elsif ($ver_major == 6 && ($ver_minor == 2 || $ver_minor == 3)) {
$self->{os_is2012} = 1; $self->{os_is2012} = 1;
} elsif ($ver_major == 10 && $ver_minor == 0) {
$self->{os_is2016} = 1;
} else { } else {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(severity => 'UNKNOWN',
short_msg => 'OS version ' . $ver_major . '.' . $ver_minor . ' not managed.'); short_msg => 'OS version ' . $ver_major . '.' . $ver_minor . ' not managed.');
@ -135,19 +139,21 @@ sub dcdiag {
my $dcdiag_cmd = 'dcdiag /test:services /test:replications /test:advertising /test:fsmocheck /test:ridmanager'; my $dcdiag_cmd = 'dcdiag /test:services /test:replications /test:advertising /test:fsmocheck /test:ridmanager';
$dcdiag_cmd .= ' /test:machineaccount' if (!defined($self->{option_results}->{nomachineaccount})); $dcdiag_cmd .= ' /test:machineaccount' if (!defined($self->{option_results}->{nomachineaccount}));
$dcdiag_cmd .= ' /test:frssysvol' if ($self->{os_is2003} == 1); $dcdiag_cmd .= ' /test:frssysvol' if ($self->{os_is2003} == 1);
$dcdiag_cmd .= ' /test:sysvolcheck' if ($self->{os_is2008} == 1 || $self->{os_is2012} == 1); $dcdiag_cmd .= ' /test:sysvolcheck' if ($self->{os_is2008} == 1 || $self->{os_is2012} == 1 || $self->{os_is2016} == 1);
if (!defined($self->{option_results}->{noeventlog})) { if (!defined($self->{option_results}->{noeventlog})) {
$dcdiag_cmd .= ' /test:frsevent /test:kccevent' if ($self->{os_is2003} == 1); $dcdiag_cmd .= ' /test:frsevent /test:kccevent' if ($self->{os_is2003} == 1);
$dcdiag_cmd .= ' /test:frsevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1) && !defined($self->{option_results}->{dfsr})); $dcdiag_cmd .= ' /test:frsevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1 || $self->{os_is2016} == 1) && !defined($self->{option_results}->{dfsr}));
$dcdiag_cmd .= ' /test:dfsrevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1) && defined($self->{option_results}->{dfsr})); $dcdiag_cmd .= ' /test:dfsrevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1 || $self->{os_is2016} == 1) && defined($self->{option_results}->{dfsr}));
} }
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, my ($stdout) = centreon::plugins::misc::windows_execute(
timeout => $self->{option_results}->{timeout}, output => $self->{output},
command => $dcdiag_cmd, timeout => $self->{option_results}->{timeout},
command_path => undef, command => $dcdiag_cmd,
command_options => undef); command_path => undef,
command_options => undef
);
my $match = 0; my $match = 0;
while ($stdout =~ /$self->{msg}->{global}/imsg) { while ($stdout =~ /$self->{msg}->{global}/imsg) {

View File

@ -37,6 +37,13 @@ sub connect_oracle {
); );
} }
sub check_options {
my ($self, %options) = @_;
$self->{container} = defined($self->{option_results}->{container}[0]) ? $self->{option_results}->{container}[0] : undef;
return $self->SUPER::check_options(%options);
}
sub connect { sub connect {
my ($self, %options) = @_; my ($self, %options) = @_;
my $dontquit = (defined($options{dontquit}) && $options{dontquit} == 1) ? 1 : 0; my $dontquit = (defined($options{dontquit}) && $options{dontquit} == 1) ? 1 : 0;
@ -76,8 +83,11 @@ sub connect {
} }
return (-1, $err_msg); return (-1, $err_msg);
} }
$self->set_version(); $self->set_version();
if (defined($self->{container}) and $self->{container} ne '') {
$self->query(query => "alter session set container=$self->{container}");
}
return 0; return 0;
} }

View File

@ -75,6 +75,7 @@ sub init {
'port:s@' => { name => 'port' }, 'port:s@' => { name => 'port' },
'sid:s' => { name => 'sid' }, 'sid:s' => { name => 'sid' },
'servicename:s' => { name => 'servicename' }, 'servicename:s' => { name => 'servicename' },
'container:s' => { name => 'container' },
}); });
$self->{options}->parse_options(); $self->{options}->parse_options();
@ -99,9 +100,11 @@ sub init {
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';service_name=' . $options_result->{servicename}; $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';service_name=' . $options_result->{servicename};
$self->{sqldefault}->{sqlpluscmd}[$i]->{service_name} = $options_result->{servicename}; $self->{sqldefault}->{sqlpluscmd}[$i]->{service_name} = $options_result->{servicename};
} }
$self->{sqldefault}->{dbi}[$i]->{container} = $options_result->{container};
$self->{sqldefault}->{sqlpluscmd}[$i]->{container} = $options_result->{container};
} }
} }
$self->SUPER::init(%options); $self->SUPER::init(%options);
} }
1; 1;
@ -130,6 +133,10 @@ Database SID.
Database Service Name. Database Service Name.
=item B<--container>
Change container (does an alter session set container command).
=back =back
=cut =cut

View File

@ -109,12 +109,13 @@ sub check_options {
# return 1 = ok still data_source # return 1 = ok still data_source
# return 0 = no data_source left # return 0 = no data_source left
$self->{sid} = defined($self->{option_results}->{sid}[0]) ? $self->{option_results}->{sid}[0]: $self->{option_results}->{tnsnames_sid}; $self->{sid} = defined($self->{option_results}->{sid}[0]) ? $self->{option_results}->{sid}[0] : $self->{option_results}->{tnsnames_sid};
$self->{service_name} = defined($self->{option_results}->{service_name}[0]) ? $self->{option_results}->{service_name}[0]: $self->{option_results}->{tnsnames_servicename}; $self->{service_name} = defined($self->{option_results}->{service_name}[0]) ? $self->{option_results}->{service_name}[0] : $self->{option_results}->{tnsnames_servicename};
$self->{oracle_home} = defined($self->{option_results}->{oracle_home}) ? $self->{option_results}->{oracle_home} : $ENV{'ORACLE_HOME'}; $self->{oracle_home} = defined($self->{option_results}->{oracle_home}) ? $self->{option_results}->{oracle_home} : $ENV{'ORACLE_HOME'};
$self->{tnsadmin_home} = defined($self->{option_results}->{tnsadmin_home}) ? $self->{option_results}->{tnsadmin_home} : $ENV{'TNSADMIN'}; $self->{tnsadmin_home} = defined($self->{option_results}->{tnsadmin_home}) ? $self->{option_results}->{tnsadmin_home} : $ENV{'TNSADMIN'};
$self->{local_connexion} = $self->{option_results}->{local_connexion}; $self->{local_connexion} = $self->{option_results}->{local_connexion};
$self->{sqlplus_cmd} = $self->{option_results}->{sqlplus_cmd}; $self->{sqlplus_cmd} = $self->{option_results}->{sqlplus_cmd};
$self->{container} = defined($self->{option_results}->{container}[0]) ? $self->{option_results}->{container}[0] : undef;
$self->{output}->output_add(long_msg => "*** DEBUG MODE****\n", debug => 1); $self->{output}->output_add(long_msg => "*** DEBUG MODE****\n", debug => 1);
$self->{output}->output_add(long_msg => Data::Dumper::Dumper($self->{option_results}), debug => 1); $self->{output}->output_add(long_msg => Data::Dumper::Dumper($self->{option_results}), debug => 1);
@ -286,8 +287,10 @@ sub connect {
} }
$self->{version} = $self->fetchrow_array(); $self->{version} = $self->fetchrow_array();
$self->{output}->output_add(long_msg => "VERSION: " . $self->{version}, debug => 1); $self->{output}->output_add(long_msg => "VERSION: " . $self->{version}, debug => 1);
if (defined($self->{container}) and $self->{container} ne '') {
$self->query(query => "alter session set container=$self->{container}");
}
return 0; return 0;
} }

View File

@ -75,10 +75,10 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"ok-status:s" => { name => 'ok_status', default => '%{status} =~ /ok/' }, 'ok-status:s' => { name => 'ok_status', default => '%{status} =~ /ok/' },
"unknown-status:s" => { name => 'unknown_status', default => '' }, 'unknown-status:s' => { name => 'unknown_status', default => '' },
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /.*/' }, 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /.*/' },
"critical-status:s" => { name => 'critical_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '' },
}); });
return $self; return $self;
@ -121,7 +121,10 @@ sub manage_selection {
my $instance = $1; my $instance = $1;
# 16 bits value # 16 bits value
my $value = unpack('S', $result->{$_}); my $value = unpack('S', $result->{$_});
if (!defined($value)) {
$value = ord($result->{$_});
}
$self->{printer}->{$instance} = { display => $instance, errors => {} }; $self->{printer}->{$instance} = { display => $instance, errors => {} };
my $i = 0; my $i = 0;
foreach my $key (keys %errors_printer) { foreach my $key (keys %errors_printer) {