(plugin) database::oracle::plugin - mode fra-usage add global metrics (#3843)

This commit is contained in:
qgarnier 2022-08-17 11:24:27 +02:00 committed by GitHub
parent f140141206
commit 47190d403b
1 changed files with 54 additions and 26 deletions

View File

@ -25,32 +25,62 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_file_output {
my ($self, %options) = @_;
return "File type '" . $options{instance_value}->{display} . "' recovery area ";
}
sub prefix_global_output {
my ($self, %options) = @_;
return "Recovery area ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'file', type => 1, cb_prefix_output => 'prefix_file_output', message_multiple => 'All recovery areas are ok', skipped_code => { -10 => 1 } }, { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', },
{ name => 'file', type => 1, cb_prefix_output => 'prefix_file_output', message_multiple => 'All recovery areas are ok', skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{file} = [ $self->{maps_counters}->{global} = [
{ label => 'space-usage', nlabel => 'recoveryarea.space.usage.percentage', set => { { label => 'space-usage', nlabel => 'recoveryarea.space.usage.percentage', set => {
key_values => [ { name => 'percent_space_usage' }, { name => 'display' } ], key_values => [ { name => 'percent_space_usage' } ],
output_template => 'used: %.2f %%', output_template => 'used: %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'percent_space_usage', template => '%.2f', min => 0, max => 100, { template => '%.2f', min => 0, max => 100, unit => '%' }
unit => '%', label_extra_instance => 1, instance_use => 'display' }, ]
],
} }
}, },
{ label => 'space-reclaimable', nlabel => 'recoveryarea.space.reclaimable.percentage', set => { { label => 'space-reclaimable', nlabel => 'recoveryarea.space.reclaimable.percentage', set => {
key_values => [ { name => 'percent_space_reclaimable' }, { name => 'display' } ], key_values => [ { name => 'percent_space_reclaimable' } ],
output_template => 'reclaimable: %.2f %%', output_template => 'reclaimable: %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'percent_space_reclaimable', template => '%.2f', min => 0, max => 100, { template => '%.2f', min => 0, max => 100, unit => '%' }
unit => '%', label_extra_instance => 1, instance_use => 'display' }, ]
], }
}
];
$self->{maps_counters}->{file} = [
{ label => 'file-space-usage', nlabel => 'recoveryarea.space.usage.percentage', set => {
key_values => [ { name => 'percent_space_usage' } ],
output_template => 'used: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
} }
}, },
{ label => 'file-space-reclaimable', nlabel => 'recoveryarea.space.reclaimable.percentage', set => {
key_values => [ { name => 'percent_space_reclaimable' } ],
output_template => 'reclaimable: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
}
]; ];
} }
@ -60,18 +90,12 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-type:s' => { name => 'filter_type' }, 'filter-type:s' => { name => 'filter_type' }
}); });
return $self; return $self;
} }
sub prefix_file_output {
my ($self, %options) = @_;
return "File type '" . $options{instance_value}->{display} . "' recovery area ";
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -90,6 +114,7 @@ sub manage_selection {
my $result = $options{sql}->fetchall_arrayref(); my $result = $options{sql}->fetchall_arrayref();
$options{sql}->disconnect(); $options{sql}->disconnect();
$self->{global} = { percent_space_usage => 0, percent_space_reclaimable => 0 };
$self->{file} = {}; $self->{file} = {};
foreach my $row (@$result) { foreach my $row (@$result) {
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
@ -106,6 +131,9 @@ sub manage_selection {
$self->{file}->{ $row->[0] }->{percent_space_usage} = $row->[1] * 100 / $row->[3]; $self->{file}->{ $row->[0] }->{percent_space_usage} = $row->[1] * 100 / $row->[3];
$self->{file}->{ $row->[0] }->{percent_space_reclaimable} = $row->[2] * 100 / $row->[3]; $self->{file}->{ $row->[0] }->{percent_space_reclaimable} = $row->[2] * 100 / $row->[3];
} }
$self->{global}->{percent_space_usage} += $self->{file}->{ $row->[0] }->{percent_space_usage};
$self->{global}->{percent_space_reclaimable} += $self->{file}->{ $row->[0] }->{percent_space_reclaimable};
} }
if (scalar(keys %{$self->{file}}) <= 0) { if (scalar(keys %{$self->{file}}) <= 0) {
@ -135,7 +163,7 @@ Filter file type (can be a regexp).
=item B<--warning-*> B<--critical-*> =item B<--warning-*> B<--critical-*>
Thresholds. Thresholds.
Can be: 'space-usage', 'space-reclaimable'. Can be: 'space-usage', 'space-reclaimable', 'file-space-usage', 'file-space-reclaimable'.
=back =back