mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 08:04:36 +02:00
Improve oracle modes
This commit is contained in:
parent
d9631e2956
commit
d43e849bc9
@ -39,7 +39,7 @@ use base qw(centreon::plugins::mode);
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Time::HiRes;
|
use DateTime;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -51,13 +51,17 @@ sub new {
|
|||||||
{
|
{
|
||||||
"skip-no-backup" => { name => 'skip_no_backup', },
|
"skip-no-backup" => { name => 'skip_no_backup', },
|
||||||
"filter-type:s" => { name => 'filter_type', },
|
"filter-type:s" => { name => 'filter_type', },
|
||||||
"warning-db-incr:s" => { name => 'warning_db_incr', },
|
"timezone:s" => { name => 'timezone', },
|
||||||
"critical-db-incr:s" => { name => 'critical_db_incr', },
|
|
||||||
"warning-db-full:s" => { name => 'warning_db_full', },
|
|
||||||
"critical-db-full:s" => { name => 'critical_db_full', },
|
|
||||||
"warning-archivelog:s" => { name => 'warning_archivelog', },
|
|
||||||
"critical-archivelog:s" => { name => 'critical_archivelog', },
|
|
||||||
});
|
});
|
||||||
|
foreach (('db incr', 'db full', 'archivelog', 'controlfile')) {
|
||||||
|
my $label = $_;
|
||||||
|
$label =~ s/ /-/g;
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
'warning-' . $label . ':s' => { name => 'warning-' . $label },
|
||||||
|
'critical-' . $label . ':s' => { name => 'critical-' . $label },
|
||||||
|
'no-' . $label => { name => 'no-' . $label },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -66,29 +70,19 @@ sub check_options {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::init(%options);
|
$self->SUPER::init(%options);
|
||||||
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning_db_incr', value => $self->{option_results}->{warning_db_incr})) == 0) {
|
foreach (('db incr', 'db full', 'archivelog', 'controlfile')) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-db-incr threshold '" . $self->{option_results}->{warning_db_incr} . "'.");
|
my $label = $_;
|
||||||
|
$label =~ s/ /-/g;
|
||||||
|
foreach my $threshold (('warning', 'critical')) {
|
||||||
|
if (($self->{perfdata}->threshold_validate(label => $threshold . '-' . $label, value => $self->{option_results}->{$threshold . '-' . $label})) == 0) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Wrong " . $threshold . '-' . $label . " threshold '" . $self->{option_results}->{warning_db_incr} . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'critical_db_incr', value => $self->{option_results}->{critical_db_incr})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-db-incr threshold '" . $self->{option_results}->{critical_db_incr} . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
}
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning_db_full', value => $self->{option_results}->{warning_db_full})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-db-full threshold '" . $self->{option_results}->{warning_db_full} . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
}
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'critical_db_full', value => $self->{option_results}->{critical_db_full})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-db-full threshold '" . $self->{option_results}->{critical_db_full} . "'.");
|
if (defined($self->{option_results}->{timezone})) {
|
||||||
$self->{output}->option_exit();
|
$ENV{TZ} = $self->{option_results}->{timezone};
|
||||||
}
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning_archivelog', value => $self->{option_results}->{warning_archivelog})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-archivelog threshold '" . $self->{option_results}->{warning_archivelog} . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'critical_archivelog', value => $self->{option_results}->{critical_archivelog})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-archivelog threshold '" . $self->{option_results}->{critical_archivelog} . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +93,7 @@ sub run {
|
|||||||
|
|
||||||
$self->{sql}->connect();
|
$self->{sql}->connect();
|
||||||
my $query = q{SELECT object_type, count(*) as num,
|
my $query = q{SELECT object_type, count(*) as num,
|
||||||
((max(start_time) - date '1970-01-01')*24*60*60 - TO_NUMBER(SUBSTR(TZ_OFFSET(DBTIMEZONE),1,3))*3600 - TO_NUMBER(SUBSTR(TZ_OFFSET(DBTIMEZONE),1,1) || SUBSTR(TZ_OFFSET(DBTIMEZONE),5,2))*60) as last_time
|
((max(start_time) - date '1970-01-01')*24*60*60) as last_time
|
||||||
FROM v$rman_status
|
FROM v$rman_status
|
||||||
WHERE operation='BACKUP'
|
WHERE operation='BACKUP'
|
||||||
GROUP BY object_type};
|
GROUP BY object_type};
|
||||||
@ -110,49 +104,57 @@ sub run {
|
|||||||
short_msg => sprintf("Rman backup age are ok."));
|
short_msg => sprintf("Rman backup age are ok."));
|
||||||
|
|
||||||
my $count_backups = 0;
|
my $count_backups = 0;
|
||||||
|
foreach (('db incr', 'db full', 'archivelog', 'controlfile')) {
|
||||||
|
my $executed = 0;
|
||||||
|
my $label = $_;
|
||||||
|
$label =~ s/ /-/g;
|
||||||
foreach my $row (@$result) {
|
foreach my $row (@$result) {
|
||||||
my ($type, $count, $last_time) = @$row;
|
next if ($$row[0] !~ /$_/i);
|
||||||
$last_time = sprintf("%i", $last_time);
|
|
||||||
next if (defined($self->{option_results}->{filter_type}) && $type !~ /$self->{option_results}->{filter_type}/);
|
|
||||||
$count_backups++;
|
$count_backups++;
|
||||||
my $now = sprintf("%i",time());
|
$executed = 1;
|
||||||
my $backup_age = $now - $last_time;
|
my ($type, $count, $last_time) = @$row;
|
||||||
|
next if (defined($self->{option_results}->{filter_type}) && $type !~ /$self->{option_results}->{filter_type}/);
|
||||||
|
|
||||||
|
my @values = localtime($last_time);
|
||||||
|
my $dt = DateTime->new(
|
||||||
|
year => $values[5] + 1900,
|
||||||
|
month => $values[4] + 1,
|
||||||
|
day => $values[3],
|
||||||
|
hour => $values[2],
|
||||||
|
minute => $values[1],
|
||||||
|
second => $values[0],
|
||||||
|
time_zone => 'UTC',
|
||||||
|
);
|
||||||
|
my $offset = $last_time - $dt->epoch;
|
||||||
|
$last_time = $last_time + $offset;
|
||||||
|
|
||||||
|
my $backup_age = time() - $last_time;
|
||||||
|
|
||||||
my $backup_age_convert = centreon::plugins::misc::change_seconds(value => $backup_age);
|
my $backup_age_convert = centreon::plugins::misc::change_seconds(value => $backup_age);
|
||||||
my $type_perfdata = $type;
|
my $type_perfdata = $type;
|
||||||
$type_perfdata =~ s/\s+/_/;
|
$type_perfdata =~ s/ /_/g;
|
||||||
$self->{output}->output_add(long_msg => sprintf("Last Rman '%s' backups : %s", $type, $backup_age_convert));
|
$self->{output}->output_add(long_msg => sprintf("Last Rman '%s' backups : %s", $type, $backup_age_convert));
|
||||||
my $exit_code;
|
|
||||||
if ($type =~ /incr/i) {
|
|
||||||
$self->{output}->perfdata_add(label => sprintf('%s_backup_age',$type_perfdata),
|
$self->{output}->perfdata_add(label => sprintf('%s_backup_age',$type_perfdata),
|
||||||
value => $backup_age,
|
value => $backup_age,
|
||||||
unit => 's',
|
unit => 's',
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_db_incr'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $label),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_db_incr'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $label),
|
||||||
min => 0);
|
min => 0);
|
||||||
$exit_code = $self->{perfdata}->threshold_check(value => $backup_age, threshold => [ { label => 'critical_db_incr', 'exit_litteral' => 'critical' }, { label => 'warning_db_incr', exit_litteral => 'warning' } ]);
|
my $exit_code = $self->{perfdata}->threshold_check(value => $backup_age, threshold => [ { label => 'critical-' . $label, 'exit_litteral' => 'critical' }, { label => 'warning-' . $label, exit_litteral => 'warning' } ]);
|
||||||
} elsif ($type =~ /full/i) {
|
|
||||||
$self->{output}->perfdata_add(label => sprintf('%s_backup_age',$type_perfdata),
|
|
||||||
value => $backup_age,
|
|
||||||
unit => 's',
|
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_db_full'),
|
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_db_full'),
|
|
||||||
min => 0);
|
|
||||||
$exit_code = $self->{perfdata}->threshold_check(value => $backup_age, threshold => [ { label => 'critical_db_full', 'exit_litteral' => 'critical' }, { label => 'warning_db_full', exit_litteral => 'warning' } ]);
|
|
||||||
} elsif ($type =~ /archive/i) {
|
|
||||||
$self->{output}->perfdata_add(label => sprintf('%s_backup_age',$type_perfdata),
|
|
||||||
value => $backup_age,
|
|
||||||
unit => 's',
|
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_archivelog'),
|
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_archivelog'),
|
|
||||||
min => 0);
|
|
||||||
$exit_code = $self->{perfdata}->threshold_check(value => $backup_age, threshold => [ { label => 'critical_archivelog', 'exit_litteral' => 'critical' }, { label => 'warning_archivelog', exit_litteral => 'warning' } ]);
|
|
||||||
}
|
|
||||||
if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
$self->{output}->output_add(severity => $exit_code,
|
||||||
short_msg => sprintf("Last Rman '%s' backups : %s", $type, $backup_age_convert));
|
short_msg => sprintf("Last Rman '%s' backups : %s", $type, $backup_age_convert));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($executed == 0 && !defined($self->{option_results}->{'no-' . $label})) {
|
||||||
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
|
short_msg => sprintf("Rman '%s' backups never executed", uc($_)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (($count_backups == 0) && (!defined($self->{option_results}->{skip_no_backup}))) {
|
if (($count_backups == 0) && (!defined($self->{option_results}->{skip_no_backup}))) {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
short_msg => sprintf("Rman backups never executed."));
|
short_msg => sprintf("Rman backups never executed."));
|
||||||
@ -172,39 +174,34 @@ Check Oracle rman backup age.
|
|||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
=item B<--warning-db-incr>
|
=item B<--warning-*>
|
||||||
|
|
||||||
Threshold warning of DB INCR backups in seconds.
|
Threshold warning in seconds.
|
||||||
|
Can be: 'db-incr', 'db-full', 'archivelog', 'controlfile'.
|
||||||
|
|
||||||
=item B<--critical-db-incr>
|
=item B<--critical-*>
|
||||||
|
|
||||||
Threshold critical of DB INCR backups in seconds.
|
Threshold critical in seconds.
|
||||||
|
Can be: 'db-incr', 'db-full', 'archivelog', 'controlfile'.
|
||||||
|
|
||||||
=item B<--warning-db-full>
|
=item B<--no-*>
|
||||||
|
|
||||||
Threshold warning of DB FULL backups in seconds.
|
Skip error if never executed.
|
||||||
|
Can be: 'db-incr', 'db-full', 'archivelog', 'controlfile'.
|
||||||
=item B<--critical-db-full>
|
|
||||||
|
|
||||||
Threshold critical of DB FULL backups in seconds.
|
|
||||||
|
|
||||||
=item B<--warning-archivelog>
|
|
||||||
|
|
||||||
Threshold warning of ARCHIVELOG backups in seconds.
|
|
||||||
|
|
||||||
=item B<--critical-archivelog>
|
|
||||||
|
|
||||||
Threshold critical of ARCHIVELOG backups in seconds.
|
|
||||||
|
|
||||||
=item B<--filter-type>
|
=item B<--filter-type>
|
||||||
|
|
||||||
Filter backup type.
|
Filter backup type.
|
||||||
(type can be : 'DB INCR', 'DB FULL', 'ARCHIVELOG')
|
(type can be : 'DB INCR', 'DB FULL', 'ARCHIVELOG')
|
||||||
|
|
||||||
=item B<--skip-bo-backup>
|
=item B<--skip-no-backup>
|
||||||
|
|
||||||
Return ok if no backup found.
|
Return ok if no backup found.
|
||||||
|
|
||||||
|
=item B<--timezone>
|
||||||
|
|
||||||
|
Timezone of oracle server (If not set, we use current server execution timezone)
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
@ -77,7 +77,7 @@ sub run {
|
|||||||
|
|
||||||
$self->{sql}->connect();
|
$self->{sql}->connect();
|
||||||
my $retention = $self->{option_results}->{retention};
|
my $retention = $self->{option_results}->{retention};
|
||||||
my $query = q{SELECT COUNT(*) FROM v$rman_status WHERE status != 'COMPLETED' AND status != 'RUNNING' AND start_time > sysdate-} . $retention;
|
my $query = q{SELECT COUNT(*) FROM v$rman_status WHERE operation = 'BACKUP' AND status != 'COMPLETED' AND status != 'RUNNING' AND start_time > sysdate-} . $retention;
|
||||||
$self->{sql}->query(query => $query);
|
$self->{sql}->query(query => $query);
|
||||||
my $rman_backup_problems = $self->{sql}->fetchrow_array();
|
my $rman_backup_problems = $self->{sql}->fetchrow_array();
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ use base qw(centreon::plugins::mode);
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Time::HiRes;
|
use DateTime;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -49,9 +49,9 @@ sub new {
|
|||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments =>
|
||||||
{
|
{
|
||||||
"skip-no-backup" => { name => 'skip_no_backup', },
|
|
||||||
"warning:s" => { name => 'warning', },
|
"warning:s" => { name => 'warning', },
|
||||||
"critical:s" => { name => 'critical', },
|
"critical:s" => { name => 'critical', },
|
||||||
|
"timezone:s" => { name => 'timezone', },
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
@ -69,6 +69,10 @@ sub check_options {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defined($self->{option_results}->{timezone})) {
|
||||||
|
$ENV{TZ} = $self->{option_results}->{timezone};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
@ -77,7 +81,7 @@ sub run {
|
|||||||
$self->{sql} = $options{sql};
|
$self->{sql} = $options{sql};
|
||||||
|
|
||||||
$self->{sql}->connect();
|
$self->{sql}->connect();
|
||||||
my $query = q{SELECT min(((time - date '1970-01-01') * 86400) - TO_NUMBER(SUBSTR(TZ_OFFSET(DBTIMEZONE),1,3))*3600 - TO_NUMBER(SUBSTR(TZ_OFFSET(DBTIMEZONE),1,1) || SUBSTR(TZ_OFFSET(DBTIMEZONE),5,2))*60 ) as last_time
|
my $query = q{SELECT min(((time - date '1970-01-01') * 86400)) as last_time
|
||||||
FROM v$backup
|
FROM v$backup
|
||||||
WHERE STATUS='ACTIVE'
|
WHERE STATUS='ACTIVE'
|
||||||
};
|
};
|
||||||
@ -85,36 +89,35 @@ sub run {
|
|||||||
my $result = $self->{sql}->fetchall_arrayref();
|
my $result = $self->{sql}->fetchall_arrayref();
|
||||||
|
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(severity => 'OK',
|
||||||
short_msg => sprintf("Rman online backup age are ok."));
|
short_msg => sprintf("Backup online modes are ok."));
|
||||||
|
|
||||||
my $count_backups = 0;
|
|
||||||
foreach my $row (@$result) {
|
foreach my $row (@$result) {
|
||||||
next if (!defined($$row[0]));
|
next if (!defined($$row[0]));
|
||||||
my $last_time = $$row[0];
|
my $last_time = $$row[0];
|
||||||
$last_time = sprintf("%i", $last_time);
|
|
||||||
$count_backups++;
|
my @values = localtime($last_time);
|
||||||
my $now = sprintf("%i",time());
|
my $dt = DateTime->new(
|
||||||
my $backup_age = $now - $last_time;
|
year => $values[5] + 1900,
|
||||||
my $backup_age_convert = centreon::plugins::misc::change_seconds(value => $backup_age);
|
month => $values[4] + 1,
|
||||||
$self->{output}->output_add(long_msg => sprintf("Last Rman online backup : %s", $backup_age_convert));
|
day => $values[3],
|
||||||
$self->{output}->perfdata_add(label => 'online_backup_age',
|
hour => $values[2],
|
||||||
value => $backup_age,
|
minute => $values[1],
|
||||||
unit => 's',
|
second => $values[0],
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
time_zone => 'UTC',
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
);
|
||||||
min => 0);
|
my $offset = $last_time - $dt->epoch;
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $backup_age, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
$last_time = $last_time + $offset;
|
||||||
|
|
||||||
|
my $launched = time() - $last_time;
|
||||||
|
my $launched_convert = centreon::plugins::misc::change_seconds(value => $launched);
|
||||||
|
$self->{output}->output_add(long_msg => sprintf("backup online mode since %s (%s)", $launched_convert, locatime($last_time)));
|
||||||
|
my $exit_code = $self->{perfdata}->threshold_check(value => $launched, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
$self->{output}->output_add(severity => $exit_code,
|
||||||
short_msg => sprintf("Last Rman online backup : %s", $backup_age_convert));
|
short_msg => sprintf("backup online mode since %s (%s)", $launched_convert, locatime($last_time)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($count_backups == 0) && (!defined($self->{option_results}->{skip_no_backup}))) {
|
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
|
||||||
short_msg => sprintf("Rman online backups never executed."));
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
@ -125,7 +128,7 @@ __END__
|
|||||||
|
|
||||||
=head1 MODE
|
=head1 MODE
|
||||||
|
|
||||||
Check Oracle rman online backup age.
|
Check Oracle backup online mode.
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
@ -137,9 +140,9 @@ Threshold warning in seconds.
|
|||||||
|
|
||||||
Threshold critical in seconds.
|
Threshold critical in seconds.
|
||||||
|
|
||||||
=item B<--skip-bo-backup>
|
=item B<--timezone>
|
||||||
|
|
||||||
Return ok if no backup found.
|
Timezone of oracle server (If not set, we use current server execution timezone)
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user