From fe13d63571da473da29d8b94597024368b030596 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Fri, 25 Mar 2016 09:20:26 +0100 Subject: [PATCH 01/10] + Change plugin.pm to use BSD memory check --- centreon-plugins/network/netasq/snmp/plugin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/netasq/snmp/plugin.pm b/centreon-plugins/network/netasq/snmp/plugin.pm index 773b0f4e7..ba2e8517c 100644 --- a/centreon-plugins/network/netasq/snmp/plugin.pm +++ b/centreon-plugins/network/netasq/snmp/plugin.pm @@ -38,7 +38,7 @@ sub new { 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'load' => 'snmp_standard::mode::loadaverage', 'ha-status' => 'network::netasq::snmp::mode::hastatus', - 'memory' => 'snmp_standard::mode::memory', + 'memory' => 'os::freebsd::snmp::mode::memory', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'snmp_standard::mode::swap', 'vpn-status' => 'network::netasq::snmp::mode::vpnstatus', From f588f9613a39bcd49ab69211a73c765bfe089c71 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Fri, 25 Mar 2016 11:24:43 +0100 Subject: [PATCH 02/10] + Add UDP/TCP connections mode for Netasq https://github.com/centreon/centreon-plugins/issues/99 --- .../network/netasq/snmp/mode/connections.pm | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 centreon-plugins/network/netasq/snmp/mode/connections.pm diff --git a/centreon-plugins/network/netasq/snmp/mode/connections.pm b/centreon-plugins/network/netasq/snmp/mode/connections.pm new file mode 100644 index 000000000..1215cbc5c --- /dev/null +++ b/centreon-plugins/network/netasq/snmp/mode/connections.pm @@ -0,0 +1,108 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::netasq::snmp::mode::connections; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'udp', set => { + key_values => [ { name => 'udp', diff => 1 } ], + per_second => 1, + output_template => 'UDP : %d connections/s', + perfdatas => [ + { label => 'udp', value => 'udp_per_second', template => '%d', + min => 0, unit => 'con' }, + ], + } + }, + { label => 'tcp', set => { + key_values => [ { name => 'tcp', diff => 1 } ], + per_second => 1, + output_template => 'TCP : %d connections/s', + perfdatas => [ + { label => 'tcp', value => 'tcp_per_second', template => '%d', + min => 0, unit => 'con' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + $self->{cache_name} = "fw_netasq_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . md5_hex('all'); + + my $oid_ntqASQStatsStatefulUdpConn = '.1.3.6.1.4.1.11256.1.12.1.33.0'; + my $oid_ntqASQStatsStatefulTcpConn = '.1.3.6.1.4.1.11256.1.12.1.23.0'; + + my $result = $options{snmp}->get_leef(oids => [ $oid_ntqASQStatsStatefulUdpConn, $oid_ntqASQStatsStatefulTcpConn ], + nothing_quit => 1); + $self->{global} = { + udp => $result->{$oid_ntqASQStatsStatefulUdpConn}, + tcp => $result->{$oid_ntqASQStatsStatefulTcpConn}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check connections setup rate on Netasq Firewall equipments. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'tcp', 'udp' + +=item B<--critical-*> + +Threshold critical. +Can be: 'tcp', 'udp' + +=back + +=cut From aa2392ce79de763e59af62b830a7946e6c35b450 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Fri, 25 Mar 2016 11:25:57 +0100 Subject: [PATCH 03/10] + add connection mode https://github.com/centreon/centreon-plugins/issues/99 --- centreon-plugins/network/netasq/snmp/plugin.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon-plugins/network/netasq/snmp/plugin.pm b/centreon-plugins/network/netasq/snmp/plugin.pm index ba2e8517c..751fb4acf 100644 --- a/centreon-plugins/network/netasq/snmp/plugin.pm +++ b/centreon-plugins/network/netasq/snmp/plugin.pm @@ -34,6 +34,7 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'snmp_standard::mode::cpu', 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'connections' => 'network::netasq::snmp::mode::connections', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'load' => 'snmp_standard::mode::loadaverage', From e73da47373e84db808fa796f5e2be4bb6387bff7 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 27 Apr 2016 22:41:17 +0200 Subject: [PATCH 04/10] + enhance tablespaceusage.pm mode + return used and free (use --filter-perfdata if needed) + add possibility to use regex as tablespace filter + counter template used https://github.com/centreon/centreon-plugins/issues/387 --- .../database/oracle/mode/tablespaceusage.pm | 162 ++++++++---------- 1 file changed, 73 insertions(+), 89 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index f751d6d67..f3b2042d9 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -20,11 +20,48 @@ package database::oracle::mode::tablespaceusage; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}); + + my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, + $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used_absolute}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'tablespace', type => 1, cb_prefix_output => 'prefix_tablespace_output', message_multiple => 'All tablespaces are OK' }, + ]; + + $self->{maps_counters}->{tablespace} = [ + { label => 'tablespace', set => { + key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'max' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_usage_output'), + threshold_use => 'prct_used_absolute', + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%s', + unit => 'B', min => 0, max => 'max_absolute', label_extra_instance => 1, instance_use => 'display_absolute' }, + { label => 'free', value => 'free_absolute', template => '%s', + unit => 'B', min => 0, max => 'max_absolute', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -33,39 +70,24 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "filter:s" => { name => 'filter', }, - "skip:s" => { name => 'skip', }, - "free" => { name => 'free', }, + "filter-tablespace:s" => { name => 'filter_tablespace' }, + "skip" => { name => 'skip' }, }); - return $self; } -sub check_options { +sub prefix_tablespace_output { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } + return "Tablespace '" . $options{instance_value}->{display} . "' "; } -sub run { +sub manage_selection { my ($self, %options) = @_; # $options{sql} = sqlmode object $self->{sql} = $options{sql}; - - $self->{output}->output_add(severity => 'OK', - short_msg => "All tablespaces are ok."); - $self->{sql}->connect(); + my $query; if ($self->{sql}->is_version_minimum(version => '11')) { $query = q{ @@ -276,75 +298,41 @@ sub run { $self->{sql}->query(query => $query); my $result = $self->{sql}->fetchall_arrayref(); - foreach my $row (@$result) { - my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; - next if (defined($self->{option_results}->{filter}) && $name !~ /$self->{option_results}->{filter}/); - next if (defined($self->{option_results}->{skip}) && $status =~ /offline/i); + $self->{tablespace} = {}; + foreach my $row (@$result) { + my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max) = @$row; + my $bytes_free = defined($bytes_max) ? $bytes_max - $bytes : -1; if (!defined($bytes)) { # seems corrupted, cannot get value - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("tbs '%s' cannot get data", $name)); + $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); next; } - $status = lc $status; - $type = lc $type; - my ($percent_used, $percent_free, $used, $free, $size); - if ($self->{sql}->is_version_minimum(version => '11')) { - $percent_used = $bytes / $bytes_max * 100; - $size = $bytes_max; - $free = $bytes_max - $bytes; - $used = $bytes; - } elsif ((!defined($bytes_max)) || ($bytes_max == 0)) { - $percent_used = ($bytes - $bytes_free) / $bytes * 100; - $size = $bytes; - $free = $bytes_free; - $used = $size - $free; - } else { - $percent_used = ($bytes - $bytes_free) / $bytes_max * 100; - $size = $bytes_max; - $free = $bytes_free + ($bytes_max - $bytes); - $used = $size - $free; + if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && + $name !~ /$self->{option_results}->{filter_tablespace}/) { + $self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter.", debug => 1); + next; } - $percent_free = 100 - $percent_used; - my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used); - my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $free); - my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $size); - $self->{output}->output_add(long_msg => sprintf("tbs '%s' Used: %.2f%s (%.2f%%) Free: %.2f%s (%.2f%%) Size: %.2f%s", - $name, $used_value, $used_unit, $percent_used, $free_value, $free_unit, $percent_free, $size_value, $size_unit)); - - if (defined($self->{option_results}->{free})) { - my $exit_code = $self->{perfdata}->threshold_check(value => $percent_free, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("tbs '%s' Free: %.2f%s (%.2f%%) Size: %.2f%s", $name, $free_value, $free_unit, $percent_free, $size_value, $size_unit)); - } - $self->{output}->perfdata_add(label => sprintf("tbs_%s_free",lc $name), - unit => 'B', - value => $free, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), - min => 0, - max => $size); - } else { - my $exit_code = $self->{perfdata}->threshold_check(value => $percent_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("tbs '%s' Used: %.2f%s (%.2f%%) Size: %.2f%s", $name, $used_value, $used_unit, $percent_used, $size_value, $size_unit)); - } - $self->{output}->perfdata_add(label => sprintf("tbs_%s_usage",lc $name), - unit => 'B', - value => $used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), - min => 0, - max => $size); + if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { + $self->{output}->output_add(long_msg => "Skipping '" . $name . "': tbs is offline", debug => 1); + next; } + $self->{output}->output_add(long_msg => sprintf("tbs '%s' status '%s' type '%s' extent '%s' used:'%i' max:'%i'", + $name, $status, $type, $extentmgmt, $bytes, $bytes_max), + debug => 1); + if (!defined($bytes)) { + # seems corrupted, cannot get value + $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); + next; + } + $self->{tablespace}->{$name} = { used => $bytes, + free => $bytes_free, + max => defined($bytes_max) ? $bytes_max : 0, + prct_used => ($bytes/$bytes_max*100), + display => $name }; } - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -357,26 +345,22 @@ Check Oracle tablespaces usage. =over 8 -=item B<--warning> +=item B<--warning-tablespace> Threshold warning. -=item B<--critical> +=item B<--critical-tablespace> Threshold critical. -=item B<--filter> +=item B<--filter-tablespace> -Filter tablespace. +Filter tablespace by name. Can be a regex =item B<--skip> Skip offline tablespaces. -=item B<--free> - -Check free space instead of used space. - =back =cut From 3e7ff67e2dc91ec9daf570917ad38074c36854cc Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 2 May 2016 18:12:23 +0200 Subject: [PATCH 05/10] + fix little mistype on filters https://github.com/centreon/centreon-plugins/issues/383 --- centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm index 29bb881e2..b80f8309e 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm @@ -406,7 +406,7 @@ sub manage_selection { my $bssid = join('.', unpack('C*', $result2->{nUserApBSSID})); next if (defined($self->{option_results}->{filter_ip_address}) && $self->{option_results}->{filter_ip_address} ne '' && $map_ap{$bssid}->{ip} !~ /$self->{option_results}->{filter_ip_address}/); - next if (defined($self->{option_results}->{filter_ip_address}) && $self->{option_results}->{filter_ip_address} ne '' && + next if (defined($self->{option_results}->{filter_essid}) && $self->{option_results}->{filter_essid} ne '' && $map_ap{$bssid}->{essid} !~ /$self->{option_results}->{filter_essid}/); $self->{ap_selected}->{$bssid} = { users => 0, bssid => $bssid } if (!defined($self->{ap_selected}->{$bssid})); From 90d2141c8829360082f083245e7222ec9fd587a2 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 2 May 2016 21:43:12 +0200 Subject: [PATCH 06/10] + Add possibilities to tablespaceusage mode --- .../database/oracle/mode/tablespaceusage.pm | 148 ++++++++++++++---- 1 file changed, 117 insertions(+), 31 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index f3b2042d9..724ba843f 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -25,19 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -sub custom_usage_output { - my ($self, %options) = @_; - - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max_absolute}); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}); - - my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, - $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used_absolute}); - return $msg; -} +my $instance_mode; sub set_counters { my ($self, %options) = @_; @@ -62,6 +50,77 @@ sub set_counters { ]; } +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = $self->{result_values}->{display} . '_used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = $self->{result_values}->{display} . '_free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label = + critical => $self->{perfdata}->get_perfdata_for_output(label + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_resul + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{opt + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { labe}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self-> + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self-> + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self-> + my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_us + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_fr + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; + + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}-> + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + # snapshot can be over 100% + if ($self->{result_values}->{free} < 0) { + $self->{result_values}->{free} = 0; + $self->{result_values}->{prct_free} = 0; + } + + return 0; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -71,6 +130,8 @@ sub new { $options{options}->add_options(arguments => { "filter-tablespace:s" => { name => 'filter_tablespace' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, "skip" => { name => 'skip' }, }); return $self; @@ -82,6 +143,13 @@ sub prefix_tablespace_output { return "Tablespace '" . $options{instance_value}->{display} . "' "; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + sub manage_selection { my ($self, %options) = @_; # $options{sql} = sqlmode object @@ -301,35 +369,45 @@ sub manage_selection { $self->{tablespace} = {}; foreach my $row (@$result) { - my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max) = @$row; - my $bytes_free = defined($bytes_max) ? $bytes_max - $bytes : -1; - if (!defined($bytes)) { - # seems corrupted, cannot get value - $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); - next; - } + my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && $name !~ /$self->{option_results}->{filter_tablespace}/) { $self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter.", debug => 1); next; } - if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { - $self->{output}->output_add(long_msg => "Skipping '" . $name . "': tbs is offline", debug => 1); - next; - } - $self->{output}->output_add(long_msg => sprintf("tbs '%s' status '%s' type '%s' extent '%s' used:'%i' max:'%i'", - $name, $status, $type, $extentmgmt, $bytes, $bytes_max), - debug => 1); if (!defined($bytes)) { # seems corrupted, cannot get value $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); next; } - $self->{tablespace}->{$name} = { used => $bytes, - free => $bytes_free, - max => defined($bytes_max) ? $bytes_max : 0, - prct_used => ($bytes/$bytes_max*100), + if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { + $self->{output}->output_add(long_msg => "Skipping '" . $name . "': tbs is offline", debug => 1); + next; + } + + my ($percent_used, $percent_free, $used, $free, $size); + if ($self->{sql}->is_version_minimum(version => '11')) { + $percent_used = $bytes / $bytes_max * 100; + $size = $bytes_max; + $free = $bytes_max - $bytes; + $used = $bytes; + } elsif ((!defined($bytes_max)) || ($bytes_max == 0)) { + $percent_used = ($bytes - $bytes_free) / $bytes * 100; + $size = $bytes; + $free = $bytes_free; + $used = $size - $free; + } else { + $percent_used = ($bytes - $bytes_free) / $bytes_max * 100; + $size = $bytes_max; + $free = $bytes_free + ($bytes_max - $bytes); + $used = $size - $free; + } + + $self->{tablespace}->{$name} = { used => $used, + free => $free, + total => $size, + prct_used => $percent_used, display => $name }; } @@ -357,6 +435,14 @@ Threshold critical. Filter tablespace by name. Can be a regex +=item B<--units> + +Default is '%', can be 'B' + +=item B<--free> + +Perfdata show free space + =item B<--skip> Skip offline tablespaces. From d1b0292f68e9725f6c10dfcac5afcd36fd8d256f Mon Sep 17 00:00:00 2001 From: Sims24 Date: Tue, 3 May 2016 16:18:36 +0200 Subject: [PATCH 07/10] + fix copy/paste deletion --- .../database/oracle/mode/tablespaceusage.pm | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 724ba843f..ef5c1bda1 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -36,15 +36,11 @@ sub set_counters { $self->{maps_counters}->{tablespace} = [ { label => 'tablespace', set => { - key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'max' }, { name => 'display' } ], - closure_custom_output => $self->can('custom_usage_output'), - threshold_use => 'prct_used_absolute', - perfdatas => [ - { label => 'used', value => 'used_absolute', template => '%s', - unit => 'B', min => 0, max => 'max_absolute', label_extra_instance => 1, instance_use => 'display_absolute' }, - { label => 'free', value => 'free_absolute', template => '%s', - unit => 'B', min => 0, max => 'max_absolute', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_calc => \&custom_usage_calc, + closure_custom_output => \&custom_usage_output, + closure_custom_perfdata => \&custom_usage_perfdata, + closure_custom_threshold_check => \&custom_usage_threshold, } }, ]; @@ -60,7 +56,7 @@ sub custom_usage_perfdata { $value_perf = $self->{result_values}->{free}; } my $extra_label = ''; - $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (); if ($instance_mode->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; @@ -69,8 +65,8 @@ sub custom_usage_perfdata { $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label = - critical => $self->{perfdata}->get_perfdata_for_output(label + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), min => 0, max => $self->{result_values}->{total}); } @@ -79,25 +75,25 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_resul + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); if ($instance_mode->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{opt + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { labe}, exit_litteral => 'warning' } ]); + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); return $exit; } sub custom_usage_output { my ($self, %options) = @_; - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self-> - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self-> - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self-> + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_us - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_fr + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); return $msg; } @@ -109,8 +105,8 @@ sub custom_usage_calc { $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result - $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}-> + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; # snapshot can be over 100% if ($self->{result_values}->{free} < 0) { From 322ef6f46ffc9d462adeb3c9a71ff27f389d0e2f Mon Sep 17 00:00:00 2001 From: Sims24 Date: Tue, 3 May 2016 16:40:19 +0200 Subject: [PATCH 08/10] + preserve perfdata format --- centreon-plugins/database/oracle/mode/tablespaceusage.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index ef5c1bda1..5c417f5b1 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -49,10 +49,10 @@ sub set_counters { sub custom_usage_perfdata { my ($self, %options) = @_; - my $label = $self->{result_values}->{display} . '_used'; + my $label = 'tbs_' . $self->{result_values}->{display} . '_used'; my $value_perf = $self->{result_values}->{used}; if (defined($instance_mode->{option_results}->{free})) { - $label = $self->{result_values}->{display} . '_free'; + $label = 'tbs_' . $self->{result_values}->{display} . '_free'; $value_perf = $self->{result_values}->{free}; } my $extra_label = ''; @@ -404,7 +404,7 @@ sub manage_selection { free => $free, total => $size, prct_used => $percent_used, - display => $name }; + display => lc $name }; } } From 3d5fbdc2cab2e712c9885a09e9b0afd62a01eae6 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 4 May 2016 16:37:07 +0200 Subject: [PATCH 09/10] + correct few things after quentin feeback thanks Quentin --- centreon-plugins/database/oracle/mode/tablespaceusage.pm | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 5c417f5b1..840c313be 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -49,7 +49,7 @@ sub set_counters { sub custom_usage_perfdata { my ($self, %options) = @_; - my $label = 'tbs_' . $self->{result_values}->{display} . '_used'; + my $label = 'tbs_' . $self->{result_values}->{display} . '_usage'; my $value_perf = $self->{result_values}->{used}; if (defined($instance_mode->{option_results}->{free})) { $label = 'tbs_' . $self->{result_values}->{display} . '_free'; @@ -108,12 +108,7 @@ sub custom_usage_calc { $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - # snapshot can be over 100% - if ($self->{result_values}->{free} < 0) { - $self->{result_values}->{free} = 0; - $self->{result_values}->{prct_free} = 0; - } - + return 0; } From e298239ec64775c3a83cb169c86e41e9f50168d1 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 4 May 2016 17:15:30 +0200 Subject: [PATCH 10/10] + Fix useless operations --- centreon-plugins/database/oracle/mode/tablespaceusage.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 840c313be..0c5ce8ef3 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -103,10 +103,9 @@ sub custom_usage_calc { $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; - $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; + $self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_prct_used'}; + $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; - $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; return 0;