Merge pull request #388 from Sims24/master

+ Add connection netasq and refactor oracle tablespace
This commit is contained in:
qgarnier 2016-05-04 17:19:47 +02:00
commit 507ac9eebf
4 changed files with 241 additions and 72 deletions

View File

@ -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}));

View File

@ -20,11 +20,97 @@
package database::oracle::mode::tablespaceusage;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
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 => '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,
}
},
];
}
sub custom_usage_perfdata {
my ($self, %options) = @_;
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';
$value_perf = $self->{result_values}->{free};
}
my $extra_label = '';
$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};
$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 => '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});
}
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_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->{option_results}->{free}));
}
$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->{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_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
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}->{prct_used} = $options{new_datas}->{$self->{instance} . '_prct_used'};
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -33,39 +119,33 @@ 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' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"skip" => { name => 'skip' },
});
return $self;
}
sub prefix_tablespace_output {
my ($self, %options) = @_;
return "Tablespace '" . $options{instance_value}->{display} . "' ";
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%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();
}
$instance_mode = $self;
}
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,20 +356,26 @@ sub run {
$self->{sql}->query(query => $query);
my $result = $self->{sql}->fetchall_arrayref();
$self->{tablespace} = {};
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);
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($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;
}
if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') {
$self->{output}->output_add(long_msg => "Skipping '" . $name . "': tbs is offline", 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;
@ -307,44 +393,14 @@ sub run {
$free = $bytes_free + ($bytes_max - $bytes);
$used = $size - $free;
}
$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);
}
$self->{tablespace}->{$name} = { used => $used,
free => $free,
total => $size,
prct_used => $percent_used,
display => lc $name };
}
$self->{output}->display();
$self->{output}->exit();
}
1;
@ -357,26 +413,30 @@ 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<--units>
Default is '%', can be 'B'
=item B<--free>
Perfdata show free space
=item B<--skip>
Skip offline tablespaces.
=item B<--free>
Check free space instead of used space.
=back
=cut

View File

@ -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

View File

@ -34,11 +34,12 @@ 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',
'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',