Merge pull request #3 from centreon/master

Keep up to date with original repo
This commit is contained in:
Bertrand Cournaud 2016-01-08 00:39:20 +01:00
commit f4ea651909
39 changed files with 1720 additions and 2779 deletions

View File

@ -91,7 +91,7 @@ sub check_options {
alarm($self->{option_results}->{timeout});
}
if (!defined($self->{option_results}->{scenario})) {
$self->{output}->add_option_msg(short_msg => "Please specify a scenario name" . $self->{option_results}->{scenario} . ".");
$self->{output}->add_option_msg(short_msg => "Please specify a scenario name.");
$self->{output}->option_exit();
}
}
@ -124,6 +124,7 @@ sub run {
my $step = $listActionNode->get_nodelist;
my $temp_step = 0;
my $stepOk = 0;
my ($last_echo_msg, $last_cmd);
my $exit1 = 'UNKNOWN';
foreach my $actionNode ($listActionNode->get_nodelist) {
($action, $filter, $value) = $xp->find('./td', $actionNode)->get_nodelist;
@ -142,11 +143,18 @@ sub run {
sleep($sleepTime / 1000);
$stepOk++;
$self->{output}->output_add(long_msg => "Step " . $temp_step . " - Pause : " . $sleepTime . "ms");
# It's an echo command => do not send it to Selenium server
# and store the associated string so that it can be displayed
# in case of a failure as an info message
} elsif ($trim_action eq 'echo'){
next;
$last_echo_msg = $trim_filter;
# Prevent output breakage in case of echo message contains invalid chars
$last_echo_msg =~ s/\||\n/ - /msg;
$stepOk += 1;
} else {
my $exit_command;
$last_cmd = $trim_action . ' ' . $trim_filter . ' ' . $trim_value;
eval {
$exit_command = $sel->do_command($trim_action, $trim_filter, $trim_value);
};
@ -172,8 +180,17 @@ sub run {
my $exit2 = $self->{perfdata}->threshold_check(value => $timeelapsed,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed));
if ($exit eq 'OK') {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed));
} else {
my $extra_info = $last_cmd;
if (defined($last_echo_msg)) {
$extra_info .= " - $last_echo_msg";
}
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%d/%d steps (%.3fs) - %s", $stepOk, $step, $timeelapsed, $extra_info));
}
$self->{output}->perfdata_add(label => "time", unit => 's',
value => sprintf('%.3f', $timeelapsed),
min => 0,

View File

@ -20,38 +20,44 @@
package centreon::common::airespace::snmp::mode::apchannelinterference;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
'000_interference-power' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'interference_power' }, { name => 'label_perfdata' },
],
output_template => 'Interference Power : %s',
perfdatas => [
{ label => 'interference_power', value => 'interference_power_absolute', template => '%s',
label_extra_instance => 1, instance_use => 'label_perfdata_absolute' },
],
}
},
'001_interference-util' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'interference_util' }, { name => 'label_perfdata' },
],
output_template => 'Interference Utilization : %s %%',
perfdatas => [
{ label => 'interference_util', value => 'interference_util_absolute', template => '%s',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'label_perfdata_absolute' },
],
}
},
};
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All AP interference statistics are ok' },
];
$self->{maps_counters}->{ap} = [
{ label => 'interference-power', set => {
key_values => [ { name => 'interference_power' }, { name => 'label_perfdata' } ],
output_template => 'Interference Power : %s',
perfdatas => [
{ label => 'interference_power', value => 'interference_power_absolute', template => '%s',
label_extra_instance => 1, instance_use => 'label_perfdata_absolute' },
],
}
},
{ label => 'interference-util', set => {
key_values => [ { name => 'interference_util' }, { name => 'label_perfdata' } ],
output_template => 'Interference Utilization : %s %%',
perfdatas => [
{ label => 'interference_util', value => 'interference_util_absolute', template => '%s',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'label_perfdata_absolute' },
],
}
},
];
}
sub prefix_ap_output {
my ($self, %options) = @_;
return $options{instance_value}->{display} . " ";
}
sub new {
my ($class, %options) = @_;
@ -64,97 +70,10 @@ sub new {
"filter-name:s" => { name => 'filter_name' },
"filter-channel:s" => { name => 'filter_channel' },
});
foreach (keys %{$maps_counters}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{ap_selected}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All AP interference statistics are ok');
}
foreach my $id ($self->{snmp}->oid_lex_sort(keys %{$self->{ap_selected}})) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => $id);
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{ap_selected}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => $self->{ap_selected}->{$id}->{display} . " $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
my $oid_bsnAPName = '.1.3.6.1.4.1.14179.2.2.1.1.3';
my $oid_bsnAPIfInterferencePower = '.1.3.6.1.4.1.14179.2.2.14.1.2';
my $oid_bsnAPIfInterferenceUtilization = '.1.3.6.1.4.1.14179.2.2.14.1.22';
@ -162,8 +81,8 @@ my $oid_bsnAPIfInterferenceUtilization = '.1.3.6.1.4.1.14179.2.2.14.1.22';
sub manage_selection {
my ($self, %options) = @_;
$self->{ap_selected} = {};
$self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName },
$self->{ap} = {};
$self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName },
{ oid => $oid_bsnAPIfInterferencePower },
{ oid => $oid_bsnAPIfInterferenceUtilization },
],
@ -187,7 +106,7 @@ sub manage_selection {
next;
}
$self->{ap_selected}->{$instance_mac . '.' . $instance_end} = {
$self->{ap}->{$instance_mac . '.' . $instance_end} = {
display => "AP '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "' Slot $1 Channel $2",
label_perfdata => $self->{results}->{$oid_bsnAPName}->{$oid} . "_$1_$2",
interference_power => $self->{results}->{$oid_bsnAPIfInterferencePower}->{$oid_bsnAPIfInterferencePower . '.' . $instance_mac . '.' . $instance_end},
@ -197,7 +116,7 @@ sub manage_selection {
}
}
if (scalar(keys %{$self->{ap_selected}}) <= 0) {
if (scalar(keys %{$self->{ap}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}
@ -213,6 +132,11 @@ Check AP Channel Interference.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='interference-util'
=item B<--warning-*>
Threshold warning.

View File

@ -20,26 +20,35 @@
package centreon::common::airespace::snmp::mode::apchannelnoise;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
'000_noise-power' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'noise_power' }, { name => 'label_perfdata' }
],
output_template => 'Noise Power : %s dBm',
perfdatas => [
{ label => 'noise_power', value => 'noise_power_absolute', template => '%s',
unit => 'dBm', label_extra_instance => 1, instance_use => 'label_perfdata_absolute' },
],
}
},
};
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All AP noise statistics are ok' },
];
$self->{maps_counters}->{ap} = [
{ label => 'noise-power', set => {
key_values => [ { name => 'noise_power' }, { name => 'label_perfdata' } ],
output_template => 'Noise Power : %s dBm',
perfdatas => [
{ label => 'noise_power', value => 'noise_power_absolute', template => '%s',
unit => 'dBm', label_extra_instance => 1, instance_use => 'label_perfdata_absolute' },
],
}
},
];
}
sub prefix_ap_output {
my ($self, %options) = @_;
return $options{instance_value}->{display} . " ";
}
sub new {
my ($class, %options) = @_;
@ -53,107 +62,18 @@ sub new {
"filter-channel:s" => { name => 'filter_channel' },
});
foreach (keys %{$maps_counters}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{ap_selected}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All AP noise statistics are ok');
}
foreach my $id ($self->{snmp}->oid_lex_sort(keys %{$self->{ap_selected}})) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => $id);
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{ap_selected}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => $self->{ap_selected}->{$id}->{display} . " $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
my $oid_bsnAPName = '.1.3.6.1.4.1.14179.2.2.1.1.3';
my $oid_bsnAPIfDBNoisePower = '.1.3.6.1.4.1.14179.2.2.15.1.21';
sub manage_selection {
my ($self, %options) = @_;
$self->{ap_selected} = {};
$self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName },
{ oid => $oid_bsnAPIfDBNoisePower },
],
nothing_quit => 1);
$self->{ap} = {};
$self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName }, { oid => $oid_bsnAPIfDBNoisePower } ],
nothing_quit => 1);
foreach my $oid (keys %{$self->{results}->{$oid_bsnAPName}}) {
$oid =~ /^$oid_bsnAPName\.(.*)$/;
my $instance_mac = $1;
@ -173,7 +93,7 @@ sub manage_selection {
next;
}
$self->{ap_selected}->{$instance_mac . '.' . $instance_end} = {
$self->{ap}->{$instance_mac . '.' . $instance_end} = {
display => "AP '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "' Slot $1 Channel $2",
label_perfdata => $self->{results}->{$oid_bsnAPName}->{$oid} . "_$1_$2",
noise_power => $self->{results}->{$oid_bsnAPIfDBNoisePower}->{$oid_bsnAPIfDBNoisePower . '.' . $instance_mac . '.' . $instance_end}
@ -182,7 +102,7 @@ sub manage_selection {
}
}
if (scalar(keys %{$self->{ap_selected}}) <= 0) {
if (scalar(keys %{$self->{ap}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}

View File

@ -20,58 +20,13 @@
package centreon::common::airespace::snmp::mode::apstatus;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $instance_mode;
my $maps_counters = {
ap => {
'000_status' => { threshold => 0,
set => {
key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ],
threshold => 0,
closure_custom_calc => \&custom_status_calc,
closure_custom_output => \&custom_status_output,
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&custom_threshold_output,
}
},
},
global => {
'000_total' => { set => {
key_values => [ { name => 'total' } ],
output_template => 'Total ap : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s',
min => 0 },
],
}
},
'001_total-associated' => { set => {
key_values => [ { name => 'associated' } ],
output_template => 'Total ap associated : %s',
perfdatas => [
{ label => 'total_associated', value => 'associated_absolute', template => '%s',
min => 0 },
],
}
},
'002_total-disassociating' => { set => {
key_values => [ { name => 'disassociating' } ],
output_template => 'Total ap disassociating : %s',
perfdatas => [
{ label => 'total_disassociating', value => 'disassociating_absolute', template => '%s',
min => 0 },
],
}
},
}
};
sub custom_threshold_output {
my ($self, %options) = @_;
my $status = 'ok';
@ -118,6 +73,55 @@ sub custom_status_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_init => 'skip_global', },
{ name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All AP status are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total ap : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'total-associated', set => {
key_values => [ { name => 'associated' } ],
output_template => 'Total ap associated : %s',
perfdatas => [
{ label => 'total_associated', value => 'associated_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'total-disassociating', set => {
key_values => [ { name => 'disassociating' } ],
output_template => 'Total ap disassociating : %s',
perfdatas => [
{ label => 'total_disassociating', value => 'disassociating_absolute', template => '%s',
min => 0 },
],
}
},
];
$self->{maps_counters}->{ap} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -129,22 +133,7 @@ sub new {
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/' },
});
foreach my $key (('global', 'ap')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
});
return $self;
}
@ -152,124 +141,21 @@ sub new {
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('global', 'ap')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$instance_mode = $self;
$self->change_macros();
}
sub run_instance {
sub skip_global {
my ($self, %options) = @_;
if ($self->{multiple} == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All AP status are ok');
}
foreach my $id (sort keys %{$self->{ap_selected}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{ap}}) {
my $obj = $maps_counters->{ap}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{ap_selected}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata(extra_instance => $self->{multiple});
}
$self->{output}->output_add(long_msg => "AP '" . $self->{ap_selected}->{$id}->{display} . "' $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "AP '" . $self->{ap_selected}->{$id}->{display} . "' $short_msg"
);
}
if ($self->{multiple} == 0) {
$self->{output}->output_add(short_msg => "AP '" . $self->{ap_selected}->{$id}->{display} . "' $long_msg");
}
}
scalar(keys %{$self->{ap}}) > 1 ? return(0) : return(1);
}
sub run_global {
sub prefix_ap_output {
my ($self, %options) = @_;
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{global}}) {
my $obj = $maps_counters->{global}->{$_}->{obj};
$obj->set(instance => 'global');
my ($value_check) = $obj->execute(values => $self->{global});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "$short_msg"
);
} else {
$self->{output}->output_add(short_msg => "$long_msg");
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->manage_selection();
if ($self->{multiple} == 1) {
$self->run_global();
}
$self->run_instance();
$self->{output}->display();
$self->{output}->exit();
return "AP '" . $options{instance_value}->{display} . "' ";
}
sub change_macros {
@ -305,9 +191,9 @@ my $oid_agentInventoryMachineModel = '.1.3.6.1.4.1.14179.1.1.1.3';
sub manage_selection {
my ($self, %options) = @_;
$self->{ap_selected} = {};
$self->{ap} = {};
$self->{global} = { total => 0, associated => 0, disassociating => 0, downloading => 0 };
$self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel },
$self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel },
{ oid => $mapping->{bsnAPName}->{oid} },
{ oid => $mapping2->{bsnAPOperationStatus}->{oid} },
{ oid => $mapping3->{bsnAPAdminStatus}->{oid} },
@ -317,9 +203,9 @@ sub manage_selection {
foreach my $oid (keys %{$self->{results}->{ $mapping->{bsnAPName}->{oid} }}) {
$oid =~ /^$mapping->{bsnAPName}->{oid}\.(.*)$/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{bsnAPName}->{oid} }, instance => $instance);
my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{ $mapping2->{bsnAPOperationStatus}->{oid} }, instance => $instance);
my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{ $mapping3->{bsnAPAdminStatus}->{oid} }, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{bsnAPName}->{oid} }, instance => $instance);
my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{ $mapping2->{bsnAPOperationStatus}->{oid} }, instance => $instance);
my $result3 = $options{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{ $mapping3->{bsnAPAdminStatus}->{oid} }, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{bsnAPName} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $result->{bsnAPName} . "': no matching filter.", debug => 1);
@ -329,19 +215,14 @@ sub manage_selection {
$self->{global}->{total}++;
$self->{global}->{$result2->{bsnAPOperationStatus}}++;
$self->{ap_selected}->{$instance} = { display => $result->{bsnAPName},
$self->{ap}->{$instance} = { display => $result->{bsnAPName},
opstatus => $result2->{bsnAPOperationStatus}, admstatus => $result3->{bsnAPAdminStatus}};
}
if (scalar(keys %{$self->{ap_selected}}) <= 0) {
if (scalar(keys %{$self->{ap}}) <= 0) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'No AP associated (can be: slave wireless controller or your filter)');
}
$self->{multiple} = 1;
if (scalar(keys %{$self->{ap_selected}}) <= 1) {
$self->{multiple} = 0;
}
}
1;
@ -354,6 +235,11 @@ Check AP status.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^total-disassociating|total-associated$'
=item B<--filter-name>
Filter AP name (can be a regexp).

View File

@ -20,105 +20,110 @@
package centreon::common::airespace::snmp::mode::apusers;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
'000_total' => { set => {
key_values => [ { name => 'total' } ],
output_template => 'Total Users : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'001_total-idle' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [ { name => 'total_idle' } ],
output_template => 'Total Idle Users : %s',
perfdatas => [
{ label => 'total_idle', value => 'total_idle_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'002_total-aaapending' => { set => {
key_values => [ { name => 'total_aaapending' } ],
output_template => 'Total AaaPending Users : %s',
perfdatas => [
{ label => 'total_aaapending', value => 'total_aaapending_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'003_total-authenticated' => { set => {
key_values => [ { name => 'total_authenticated' } ],
output_template => 'Total Authenticated Users : %s',
perfdatas => [
{ label => 'total_authenticated', value => 'total_authenticated_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'004_total-associated' => { set => {
key_values => [ { name => 'total_associated' } ],
output_template => 'Total Associated Users : %s',
perfdatas => [
{ label => 'total_associated', value => 'total_associated_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'005_total-powersave' => { set => {
key_values => [ { name => 'total_powersave' } ],
output_template => 'Total Powersave Users : %s',
perfdatas => [
{ label => 'total_powersave', value => 'total_powersave_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'006_total-disassociated' => { set => {
key_values => [ { name => 'total_disassociated' } ],
output_template => 'Total Disassociated Users : %s',
perfdatas => [
{ label => 'total_disassociated', value => 'total_disassociated_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'007_total-tobedeleted' => { set => {
key_values => [ { name => 'total_tobedeleted' } ],
output_template => 'Total ToBeDeleted Users : %s',
perfdatas => [
{ label => 'total_tobedeleted', value => 'total_tobedeleted_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'008_total-probing' => { set => {
key_values => [ { name => 'total_probing' } ],
output_template => 'Total Probing Users : %s',
perfdatas => [
{ label => 'total_probing', value => 'total_probing_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
'009_total-blacklisted' => { set => {
key_values => [ { name => 'total_blacklisted' } ],
output_template => 'Total Blacklisted Users : %s',
perfdatas => [
{ label => 'total_blacklisted', value => 'total_blacklisted_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
};
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total Users : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-idle', set => {
key_values => [ { name => 'total_idle' } ],
output_template => 'Total Idle Users : %s',
perfdatas => [
{ label => 'total_idle', value => 'total_idle_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-aaapending', set => {
key_values => [ { name => 'total_aaapending' } ],
output_template => 'Total AaaPending Users : %s',
perfdatas => [
{ label => 'total_aaapending', value => 'total_aaapending_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-authenticated', set => {
key_values => [ { name => 'total_authenticated' } ],
output_template => 'Total Authenticated Users : %s',
perfdatas => [
{ label => 'total_authenticated', value => 'total_authenticated_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-associated', set => {
key_values => [ { name => 'total_aaapending' } ],
output_template => 'Total AaaPending Users : %s',
perfdatas => [
{ label => 'total_aaapending', value => 'total_aaapending_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-powersave', set => {
key_values => [ { name => 'total_powersave' } ],
output_template => 'Total Powersave Users : %s',
perfdatas => [
{ label => 'total_powersave', value => 'total_powersave_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-disassociated', set => {
key_values => [ { name => 'total_disassociated' } ],
output_template => 'Total Disassociated Users : %s',
perfdatas => [
{ label => 'total_disassociated', value => 'total_disassociated_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-tobedeleted', set => {
key_values => [ { name => 'total_tobedeleted' } ],
output_template => 'Total ToBeDeleted Users : %s',
perfdatas => [
{ label => 'total_tobedeleted', value => 'total_tobedeleted_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-probing', set => {
key_values => [ { name => 'total_probing' } ],
output_template => 'Total Probing Users : %s',
perfdatas => [
{ label => 'total_probing', value => 'total_probing_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
{ label => 'total-blacklisted', set => {
key_values => [ { name => 'total_blacklisted' } ],
output_template => 'Total Blacklisted Users : %s',
perfdatas => [
{ label => 'total_blacklisted', value => 'total_blacklisted_absolute', template => '%s',
unit => 'users', min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
@ -130,79 +135,10 @@ sub new {
{
"filter-ssid:s" => { name => 'filter_ssid' },
});
foreach (keys %{$maps_counters}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => 'global');
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{global});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "$short_msg"
);
} else {
$self->{output}->output_add(short_msg => "$long_msg");
}
$self->{output}->display();
$self->{output}->exit();
}
my %map_station_status = (
0 => 'idle',
1 => 'aaapending',
@ -229,7 +165,7 @@ sub manage_selection {
$self->{global} = { total => 0, total_idle => 0, total_aaapending => 0, total_authenticated => 0,
total_associated => 0, total_powersave => 0, total_disassociated => 0,
total_tobedeleted => 0, total_probing => 0, total_blacklisted => 0};
$self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel },
$self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel },
{ oid => $mapping->{bsnMobileStationStatus}->{oid} },
{ oid => $mapping2->{bsnMobileStationSsid}->{oid} },
],
@ -238,8 +174,8 @@ sub manage_selection {
foreach my $oid (keys %{$self->{results}->{ $mapping->{bsnMobileStationStatus}->{oid} }}) {
$oid =~ /^$mapping->{bsnMobileStationStatus}->{oid}\.(.*)$/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{bsnMobileStationStatus}->{oid} }, instance => $instance);
my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{ $mapping2->{bsnMobileStationSsid}->{oid} }, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{bsnMobileStationStatus}->{oid} }, instance => $instance);
my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{ $mapping2->{bsnMobileStationSsid}->{oid} }, instance => $instance);
if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' &&
$result2->{bsnMobileStationSsid} !~ /$self->{option_results}->{filter_ssid}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $result2->{bsnMobileStationSsid} . "': no matching filter.");
@ -260,6 +196,11 @@ Check total users connected and status on AP.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^total|total-idle$'
=item B<--warning-*>
Threshold warning.

View File

@ -32,9 +32,9 @@ my %map_psu_status = (
my $oid_agentSwitchInfoGroup = '.1.3.6.1.4.1.14179.1.1.3';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_agentSwitchInfoGroup };
push @{$self->{request}}, { oid => $oid_agentSwitchInfoGroup };
}
sub check {
@ -42,14 +42,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu'));
return if ($self->check_filter(section => 'psu'));
foreach my $instances ([1, 3], [2, 5]) {
next if (!defined($self->{results}->{$oid_agentSwitchInfoGroup}->{ $oid_agentSwitchInfoGroup . '.' . $$instances[1] . '.0' }));
my $present = $self->{results}->{$oid_agentSwitchInfoGroup}->{ $oid_agentSwitchInfoGroup . '.' . ($$instances[1] - 1) . '.0' };
my $operational = $map_psu_status{ $self->{results}->{$oid_agentSwitchInfoGroup}->{ $oid_agentSwitchInfoGroup . '.' . $$instances[1] . '.0' } };
next if ($self->check_exclude(section => 'psu', instance => $$instances[0]));
next if ($self->check_filter(section => 'psu', instance => $$instances[0]));
next if ($present =~ /0/i &&
$self->absent_problem(section => 'psu', instance => $$instances[0]));
$self->{components}->{psu}->{total}++;

View File

@ -20,154 +20,50 @@
package centreon::common::airespace::snmp::mode::hardware;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
my $thresholds = {
psu => [
['not operational', 'CRITICAL'],
['operational', 'OK'],
],
};
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(psu)$';
$self->{cb_hook2} = 'snmp_execute';
#Example for threshold:
$self->{thresholds} = {
psu => [
['not operational', 'CRITICAL'],
['operational', 'OK'],
],
};
$self->{components_path} = 'centreon::common::airespace::snmp::mode::components';
$self->{components_module} = ['psu'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"exclude:s" => { name => 'exclude' },
"absent-problem:s" => { name => 'absent' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('psu');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "centreon::common::airespace::snmp::mode::components::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
my $func = $mod_name->can('load');
$func->(request => $snmp_request);
}
}
if (scalar(@{$snmp_request}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "centreon::common::airespace::snmp::mode::components::$_";
my $func = $mod_name->can('check');
$func->($self);
}
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_exclude {
my ($self, %options) = @_;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
}
sub absent_problem {
my ($self, %options) = @_;
if (defined($self->{option_results}->{absent}) &&
$self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Component '%s' instance '%s' is not present",
$options{section}, $options{instance}));
}
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
$self->{components}->{$options{section}}->{skip}++;
return 1;
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1;
__END__
@ -183,21 +79,27 @@ Check Hardware (Power Supplies).
Which component to check (Default: '.*').
Can be: 'psu'.
=item B<--exclude>
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=psu)
Can also exclude specific instance: --exclude=psu#1#
Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --filter=psu,1
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=psu#1#
Can be specific or global: --absent-problem=psu,1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='psu,WARNING,not operational'
=back
=cut

View File

@ -401,15 +401,17 @@ sub manage_selection {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxUserEntry}, instance => $instance);
my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{nUserApBSSID}->{oid}}, instance => $instance);
# security
next if (!defined($result2->{nUserApBSSID}));
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 '' &&
$map_ap{$bssid}->{essid} !~ /$self->{option_results}->{filter_essid}/);
$self->{ap_selected}->{$bssid} = { users => 0, bssid => $bssid } if (!defined($self->{ap_selected}->{$bssid}));
$self->{ap_selected}->{$bssid}->{users}++;
$self->{essid_selected}->{$map_ap{$bssid}->{essid}} = { users => 0, essid => $map_ap{$bssid}->{essid} } if (!defined($self->{essid_selected}->{$map_ap{$bssid}->{essid}}));
$self->{essid_selected}->{$map_ap{$bssid}->{essid}}->{users}++;

View File

@ -217,10 +217,12 @@ sub check {
$self->{perfdata}->threshold_validate(label => 'critical-' . $component . '-instance-' . $instance, value => $crit_th);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $component . '-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $component . '-instance-' . $instance);
$exit2 = $self->{perfdata}->threshold_check(value => $result->{entSensorValue}, threshold => [ { label => 'critical-' . $component . '-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-' . $component . '-instance-' . $instance, exit_litteral => 'warning' } ]);
}
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("Sensor '%s' is %s %s", $sensor_descr, $result->{entSensorStatus}, $result->{entSensorType}));
short_msg => sprintf("Sensor '%s' is %s %s", $sensor_descr, $result->{entSensorValue}, $perfdata_unit{$result->{entSensorType}}));
}
$self->{output}->perfdata_add(label => $component . '_' . $sensor_descr, unit => $perfdata_unit{$result->{entSensorType}},
value => $result->{entSensorValue},

View File

@ -155,7 +155,11 @@ sub set_proxy {
error_msg => "Cannot load module 'HTTP::ProxyPAC'.");
my $pac;
eval {
$pac = HTTP::ProxyPAC->new($options{request}->{proxypac});
if ($options{request}->{proxypac} =~ /^(http|https):\/\//) {
$pac = HTTP::ProxyPAC->new(URI->new($options{request}->{proxypac}));
} else {
$pac = HTTP::ProxyPAC->new($options{request}->{proxypac});
}
};
if ($@) {
$self->{output}->add_option_msg(short_msg => 'issue to load proxypac: ' . $@);

View File

@ -32,6 +32,7 @@ sub new {
my $self = {};
bless $self, $class;
$self->{sanity} = 0;
$self->{options_stored} = {};
$self->{options} = {};
@{$self->{pod_package}} = ();
@ -59,10 +60,8 @@ sub set_sanity {
} else {
$centreon::plugins::alternative::Getopt::warn_message = 1;
}
$SIG{__WARN__} = sub {
$self->{output}->add_option_msg(short_msg => $_[0]);
$self->{output}->option_exit(nolabel => 1);
};
$self->{sanity} == 1;
}
sub set_output {
@ -127,10 +126,21 @@ sub parse_options {
my $self = shift;
#%{$self->{options_stored}} = ();
my $save_warn_handler;
if ($self->{sanity} == 1) {
$save_warn_handler = $SIG{__WARN__};
$SIG{__WARN__} = sub {
$self->{output}->add_option_msg(short_msg => $_[0]);
$self->{output}->option_exit(nolabel => 1);
};
}
GetOptions(
%{$self->{options}}
);
%{$self->{options}} = ();
$SIG{__WARN__} = $save_warn_handler if ($self->{sanity} == 1);
}
sub get_option {

View File

@ -0,0 +1,325 @@
#
# Copyright 2015 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 centreon::plugins::templates::counter;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::values;
use centreon::plugins::misc;
sub set_counters {
my ($self, %options) = @_;
if (!defined($self->{maps_counters})) {
$self->{maps_counters} = {};
}
$self->{maps_counters_type} = [];
# 0 = mode total
# 1 = mode instances
#push @{$self->{maps_counters_type}}, {
# name => 'global', type => 0, message_separator => ', ', cb_prefix_output => undef, cb_init => undef,
#};
#$self->{maps_counters}->{global} = [
# { label => 'client', set => {
# key_values => [ { name => 'client' } ],
# output_template => 'Current client connections : %s',
# perfdatas => [
# { label => 'Client', value => 'client_absolute', template => '%s',
# min => 0, unit => 'con' },
# ],
# }
# },
#];
# Example for instances
#push @{$self->{maps_counters_type}}, {
# name => 'cpu', type => 1, message_separator => ', ', cb_prefix_output => undef, cb_init => undef,
# message_multiple => 'All CPU usages are ok',
#};
}
sub call_object_callback {
my ($self, %options) = @_;
if (defined($options{method_name})) {
my $method = $self->can($options{method_name});
if ($method) {
return $self->$method(%options);
}
}
return undef;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-counters:s" => { name => 'filter_counters' },
});
$self->{statefile_value} = undef;
if (defined($options{statefile}) && $options{statefile}) {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'centreon::plugins::statefile',
error_msg => "Cannot load module 'centreon::plugins::statefile'.");
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
}
$self->{maps_counters} = {} if (!defined($self->{maps_counters}));
$self->set_counters();
foreach my $key (keys %{$self->{maps_counters}}) {
foreach (@{$self->{maps_counters}->{$key}}) {
if (!defined($_->{threshold}) || $_->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $_->{label} . ':s' => { name => 'warning-' . $_->{label} },
'critical-' . $_->{label} . ':s' => { name => 'critical-' . $_->{label} },
});
}
$_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_->{label});
$_->{obj}->set(%{$_->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (keys %{$self->{maps_counters}}) {
foreach (@{$self->{maps_counters}->{$key}}) {
$_->{obj}->init(option_results => $self->{option_results});
}
}
if (defined($self->{statefile_value})) {
$self->{statefile_value}->check_options(%options);
}
}
sub run_global {
my ($self, %options) = @_;
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator}: ', ';
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (@{$self->{maps_counters}->{$options{config}->{name}}}) {
my $obj = $_->{obj};
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{label} !~ /$self->{option_results}->{filter_counters}/);
$obj->set(instance => $options{config}->{name});
my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, values => $self->{$options{config}->{name}});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = $message_separator;
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = $message_separator;
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = $message_separator;
}
$obj->perfdata();
}
my ($prefix_output, $suffix_output);
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output})
if (defined($options{config}->{cb_prefix_output}));
$prefix_output = '' if (!defined($prefix_output));
$suffix_output = $self->call_object_callback(method_name => $options{config}->{cb_suffix_output})
if (defined($options{config}->{cb_suffix_output}));
$suffix_output = '' if (!defined($suffix_output));
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}"
);
} else {
$self->{output}->output_add(short_msg => "${prefix_output}${long_msg}${suffix_output}");
}
}
sub run_instances {
my ($self, %options) = @_;
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
$self->{multiple} = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
$self->{multiple} = 0;
}
if ($self->{multiple} == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => $options{config}->{message_multiple});
}
my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator}: ', ';
foreach my $id (sort keys %{$self->{$options{config}->{name}}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (@{$self->{maps_counters}->{$options{config}->{name}}}) {
my $obj = $_->{obj};
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{label} !~ /$self->{option_results}->{filter_counters}/);
$obj->set(instance => $id);
my ($value_check) = $obj->execute(new_datas => $self->{new_datas},
values => $self->{$options{config}->{name}}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = $message_separator;
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = $message_separator;
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = $message_separator;
}
$obj->perfdata(extra_instance => $self->{multiple});
}
my ($prefix_output, $suffix_output);
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$id})
if (defined($options{config}->{cb_prefix_output}));
$prefix_output = '' if (!defined($prefix_output));
$suffix_output = $self->call_object_callback(method_name => $options{config}->{cb_suffix_output})
if (defined($options{config}->{cb_suffix_output}));
$suffix_output = '' if (!defined($suffix_output));
$self->{output}->output_add(long_msg => "${prefix_output}${long_msg}${suffix_output}");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}"
);
}
if ($self->{multiple} == 0) {
$self->{output}->output_add(short_msg => "${prefix_output}${long_msg}${suffix_output}");
}
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
$self->{new_datas} = undef;
if (defined($self->{statefile_value})) {
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => $self->{cache_name}) if (defined($self->{cache_name}));
$self->{new_datas}->{last_timestamp} = time();
}
foreach my $entry (@{$self->{maps_counters_type}}) {
if ($entry->{type} == 0) {
$self->run_global(config => $entry);
} elsif ($entry->{type} == 1) {
$self->run_instances(config => $entry);
}
}
if (defined($self->{statefile_value})) {
$self->{statefile_value}->write(data => $self->{new_datas});
}
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
# example for snmp
#use Digest::MD5 qw(md5_hex);
#$self->{cache_name} = "choose_name_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
# (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Default template for counters. Should be extended.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example to check SSL connections only : --filter-counters='^xxxx|yyyy$'
=item B<--warning-*>
Threshold warning.
Can be: 'xxx', 'xxx'.
=item B<--critical-*>
Threshold critical.
Can be: 'xxx', 'xxx'.
=back
=cut

View File

@ -0,0 +1,428 @@
#
# Copyright 2015 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 centreon::plugins::templates::hardware;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
# To check with a regexp
#$self->{regexp_threshold_overload_check_section_option} = '';
#$self->{cb_threshold_overload_check_section_option} = 'callbackname';
#$self->{regexp_threshold_numeric_check_section_option} = '';
#$self->{cb_threshold_numeric_check_section_option} = 'callbackname';
# Some callbacks
#$self->{cb_hook1} = 'callbackname'; # before the loads
#$self->{cb_hook2} = 'callbackname'; # between loads and requests
#$self->{cb_hook3} = 'callbackname'; # after requests
# Example for threshold:
#$self->{thresholds} = {
# fan => [
# ['bad', 'CRITICAL'],
# ['good', 'OK'],
# ['notPresent', 'OK'],
# ],
#};
# Unset the call to load components
#$self->{components_exec_load} = 0;
# Set the path_info
#$self->{components_path} = 'network::xxxx::mode::components';
# Set the components
#$self->{components_module} = ['cpu', 'memory', ...];
}
sub call_object_callback {
my ($self, %options) = @_;
if (defined($options{method_name})) {
my $method = $self->can($options{method_name});
if ($method) {
return $self->$method(%options);
}
}
return undef;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
});
$self->{performance} = (defined($options{no_performance}) && $options{no_performance} == 1) ?
0 : 1;
if ($self->{performance} == 1) {
$options{options}->add_options(arguments => {
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
});
}
$self->{filter_exclude} = (defined($options{no_filter_exclude}) && $options{no_filter_exclude} == 1) ?
0 : 1;
if ($self->{filter_exclude} == 1) {
$options{options}->add_options(arguments => {
"exclude:s" => { name => 'exclude' },
"filter:s@" => { name => 'filter' },
});
}
$self->{absent} = (defined($options{no_absent}) && $options{no_absent} == 1) ?
0 : 1;
if ($self->{absent} == 1) {
$options{options}->add_options(arguments => {
"absent-problem:s@" => { name => 'absent_problem' },
});
}
$self->{components} = {};
$self->{no_components} = undef;
$self->{components_module} = [];
$self->{components_exec_load} = 1;
$self->set_system();
$self->{request} = [];
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
if ($self->{filter_exclude} == 1) {
$self->{filter} = [];
foreach my $val (@{$self->{option_results}->{filter}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
}
}
if ($self->{absent} == 1) {
$self->{absent_problem} = [];
foreach my $val (@{$self->{option_results}->{absent_problem}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] };
}
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
if (scalar(@values) < 3) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $status, $filter);
if (scalar(@values) == 3) {
($section, $status, $filter) = @values;
$instance = '.*';
} else {
($section, $instance, $status, $filter) = @values;
}
if (defined($self->{regexp_threshold_overload_check_section_option}) &&
$section !~ /$self->{regexp_threshold_overload_check_section_option}/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'.");
$self->{output}->option_exit();
}
$self->call_object_callback(method_name => $self->{cb_threshold_overload_check_section_option},
section => $section, option_value => $val);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance };
}
if ($self->{performance} == 1) {
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
next if (!defined($val) || $val eq '');
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $value) = ($1, $2, $3);
if (defined($self->{regexp_threshold_numeric_check_section_option}) &&
$section !~ /$self->{regexp_threshold_numeric_check_section_option}/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
$self->call_object_callback(method_name => $self->{cb_threshold_numeric_check_section_option},
section => $section, option_value => $val);
my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) {
$position = scalar(@{$self->{numeric_threshold}->{$section}});
}
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
$self->{output}->option_exit();
}
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance };
}
}
}
}
sub run {
my ($self, %options) = @_;
$self->{loaded} = 0;
$self->call_object_callback(method_name => $self->{cb_hook1},
%options);
foreach (@{$self->{components_module}}) {
if (/$self->{option_results}->{component}/) {
my $mod_name = $self->{components_path} . "::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
$self->{loaded} = 1;
if ($self->{components_exec_load} == 1) {
my $func = $mod_name->can('load');
$func->($self);
}
}
}
if ($self->{loaded} == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->call_object_callback(method_name => $self->{cb_hook2},
%options);
foreach (@{$self->{components_module}}) {
if (/$self->{option_results}->{component}/) {
my $mod_name = $self->{components_path} . "::$_";
my $func = $mod_name->can('check');
$func->($self);
}
}
$self->call_object_callback(method_name => $self->{cb_hook3},
%options);
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_filter {
my ($self, %options) = @_;
# Old compatibility variable. We'll be deleted
if (defined($self->{option_results}->{exclude})) {
if (defined($options{instance})) {
if ($self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
}
foreach (@{$self->{filter}}) {
if ($options{section} =~ /$_->{filter}/) {
if (!defined($options{instance}) && !defined($_->{instance})) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
}
}
return 0;
}
sub absent_problem {
my ($self, %options) = @_;
foreach (@{$self->{absent_problem}}) {
if ($options{section} =~ /$_->{filter}/) {
if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Component '%s' instance '%s' is not present",
$options{section}, $options{instance}));
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
$self->{components}->{$options{section}}->{skip}++;
return 1;
}
}
}
return 0;
}
sub get_severity_numeric {
my ($self, %options) = @_;
my $status = 'OK'; # default
my $thresholds = { warning => undef, critical => undef };
my $checked = 0;
if (defined($self->{numeric_threshold}->{$options{section}})) {
my $exits = [];
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
if ($options{instance} =~ /$_->{instance}/) {
push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]);
$thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label});
$checked = 1;
}
}
$status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0);
}
return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked);
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i &&
(!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
$status = $_->{status};
return $status;
}
}
}
my $label = defined($options{label}) ? $options{label} : $options{section};
foreach (@{$self->{thresholds}->{$label}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1;
__END__
=head1 MODE
Default template for hardware. Should be extended.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'xxx', 'yyy'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=xxx --filter=yyyy)
Can also exclude specific instance: --filter=xxxxx,instancevalue
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=xxxx,instancevalue
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='xxxxx,CRITICAL,^(?!(normal)$)'
=item B<--warning>
Set warning threshold for temperatures (syntax: type,instance,threshold)
Example: --warning='xxxxx,.*,30'
=item B<--critical>
Set critical threshold for temperatures (syntax: type,instance,threshold)
Example: --critical='xxxxx,.*,40'
=back
=cut

View File

@ -2,8 +2,8 @@ Welcome to Centreon Plugins documentation!
==========================================
Centreon Plugins is a common monitoring library and plugins written in
Perl. It is licensed under the terms of the `GNU General Public
License Version 2 <https://www.gnu.org/licenses/gpl-2.0.html>`_ as
Perl. It is licensed under the terms of the `Apache License Version 2
<https://www.apache.org/licenses/LICENSE-2.0>`_ as
published by the Free Software Foundation.
Contents:

View File

@ -614,7 +614,7 @@ Warning if space used > 80% and critical if space used > 90%:
Warning if space free < 5G and critical if space free < 2G:
::
$ perl centreon_plugins.pl --plugin=os::windows::snmp::plugin --mode=storage --hostname=xxx.xxx.xxx.xxx --snmp-version=2c --snmp-public=community --verbose --storage='.*' --name --regexp --display-transform-src='(..).*' --display-transform-dst='$1' --warning=5497558138880 --critical=2199023255552 --units='B' --free
$ perl centreon_plugins.pl --plugin=os::windows::snmp::plugin --mode=storage --hostname=xxx.xxx.xxx.xxx --snmp-version=2c --snmp-public=community --verbose --storage='.*' --name --regexp --display-transform-src='(..).*' --display-transform-dst='$1' --warning=5497558138880: --critical=2199023255552: --units='B' --free
OK: All storages are ok. | 'free_C:'=97372344320B;0:5497558138880;0:2199023255552;0;135996108800 'free_D:'=97372344320B;0:5497558138880;0:2199023255552;0;135996108800
Storage 'C:' Total: 126.66 GB Used: 35.97 GB (28.40%) Free: 90.69 GB (71.60%)
Storage 'D:' Total: 126.66 GB Used: 35.97 GB (28.40%) Free: 90.69 GB (71.60%)

View File

@ -2,8 +2,7 @@ Bienvenue dans la documentation Centreon Plugins!
=================================================
Centreon Plugins est un ensemble de bibliothèques et plugins de supervision
écrits en Perl. Cet ensemble est licencié sous les termes de `GNU General Public
License Version 2 <https://www.gnu.org/licenses/gpl-2.0.html>` tel que
écrits en Perl. Cet ensemble est licencié sous les termes de `Apache License Version 2 <https://www.apache.org/licenses/LICENSE-2.0>` tel que
publié par la "Free Software Fondation".
Sommaire :

View File

@ -616,7 +616,7 @@ Dégradé si l'espace utilisé > 80% et critique sur l'espace utilisé > 90% :
Dégradé si l'espace disponible < 5G et critique si l'espace disponible < 2G :
::
$ perl centreon_plugins.pl --plugin=os::windows::snmp::plugin --mode=storage --hostname=xxx.xxx.xxx.xxx --snmp-version=2c --snmp-public=community --verbose --storage='.*' --name --regexp --display-transform-src='(..).*' --display-transform-dst='$1' --warning=5497558138880 --critical=2199023255552 --units='B' --free
$ perl centreon_plugins.pl --plugin=os::windows::snmp::plugin --mode=storage --hostname=xxx.xxx.xxx.xxx --snmp-version=2c --snmp-public=community --verbose --storage='.*' --name --regexp --display-transform-src='(..).*' --display-transform-dst='$1' --warning=5497558138880: --critical=2199023255552: --units='B' --free
OK: All storages are ok. | 'free_C:'=97372344320B;0:5497558138880;0:2199023255552;0;135996108800 'free_D:'=97372344320B;0:5497558138880;0:2199023255552;0;135996108800
Storage 'C:' Total: 126.66 GB Used: 35.97 GB (28.40%) Free: 90.69 GB (71.60%)
Storage 'D:' Total: 126.66 GB Used: 35.97 GB (28.40%) Free: 90.69 GB (71.60%)

View File

@ -20,48 +20,56 @@
package network::3com::snmp::mode::cpu;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $instance_mode;
my $maps_counters = {
cpu => {
'000_5s' => {
set => {
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usages are ok' }
];
$self->{maps_counters}->{cpu} = [
{ label => '5s', set => {
key_values => [ { name => 'usage_5s' }, { name => 'display' } ],
output_template => '%s %% (5sec)', output_error_template => "%s (5sec)",
perfdatas => [
{ label => 'cpu_5s', value => 'usage_5s_absolute', template => '%d',
unit => '%', min => 0, max => 100 },
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' },
],
},
}
},
'001_1m' => {
set => {
{ label => '1m', set => {
key_values => [ { name => 'usage_1m' }, { name => 'display' } ],
output_template => '%s %% (1m)', output_error_template => "%s (1min)",
perfdatas => [
{ label => 'cpu_1m', value => 'usage_1m_absolute', template => '%d',
unit => '%', min => 0, max => 100 },
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' },
],
},
}
},
'002_5m' => {
set => {
{ label => '5m', set => {
key_values => [ { name => 'usage_5m' }, { name => 'display' } ],
output_template => '%s %% (5min)', output_error_template => "%s (5min)",
perfdatas => [
{ label => 'cpu_5m', value => 'usage_5m_absolute', template => '%d',
unit => '%', min => 0, max => 100 },
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' },
],
},
}
},
];
}
sub prefix_cpu_output {
my ($self, %options) = @_;
if ($self->{multiple} == 1) {
return "CPU '" . $options{instance_value}->{display} . "' Usage ";
}
};
return "CPU Usage ";
}
sub new {
my ($class, %options) = @_;
@ -72,107 +80,10 @@ sub new {
$options{options}->add_options(arguments =>
{
});
foreach my $key (('cpu')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('cpu')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$instance_mode = $self;
}
sub run_instances {
my ($self, %options) = @_;
my $multiple = 1;
if (scalar(keys %{$self->{cpu}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All CPU usages are ok');
}
foreach my $id (sort keys %{$self->{cpu}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{cpu}}) {
my $obj = $maps_counters->{cpu}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{cpu}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata(extra_instance => $multiple);
}
my $prefix = "CPU Usage ";
if ($multiple == 1) {
$prefix = sprintf("CPU '%s' Usage ", $self->{cpu}->{$id}->{display});
}
$self->{output}->output_add(long_msg => "${prefix}$long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "${prefix}$short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "${prefix}$long_msg");
}
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
$self->run_instances();
$self->{output}->display();
$self->{output}->exit();
}
my $mapping = {
hwCpuCostRate => { oid => '.1.3.6.1.4.1.43.45.1.6.1.1.1.2' },
hwCpuCostRatePer1Min => { oid => '.1.3.6.1.4.1.43.45.1.6.1.1.1.3' },
@ -214,6 +125,11 @@ Check cpu usages.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='5m'
=item B<--warning-*>
Threshold warning.

View File

@ -20,27 +20,10 @@
package network::3com::snmp::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $instance_mode;
my $maps_counters = {
mem => {
'000_usage' => {
set => {
key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ],
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) = @_;
@ -89,6 +72,34 @@ sub custom_usage_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok' }
];
$self->{maps_counters}->{memory} = [
{ label => 'usage', set => {
key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub prefix_memory_output {
my ($self, %options) = @_;
if ($self->{multiple} == 1) {
return "Memory '" . $options{instance_value}->{display} . "' ";
}
return '';
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -98,107 +109,10 @@ sub new {
$options{options}->add_options(arguments =>
{
});
foreach my $key (('mem')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('mem')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$instance_mode = $self;
}
sub run_instances {
my ($self, %options) = @_;
my $multiple = 1;
if (scalar(keys %{$self->{mem}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All memory usages are ok');
}
foreach my $id (sort keys %{$self->{mem}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{mem}}) {
my $obj = $maps_counters->{mem}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{mem}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata(extra_instance => $multiple);
}
my $prefix = '';
if ($multiple == 1) {
$prefix = sprintf("Memory '%s' ", $self->{mem}->{$id}->{display});
}
$self->{output}->output_add(long_msg => "${prefix}$long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "${prefix}$short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "${prefix}$long_msg");
}
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
$self->run_instances();
$self->{output}->display();
$self->{output}->exit();
}
my $mapping = {
hwMemSize => { oid => '.1.3.6.1.4.1.43.45.1.6.1.2.1.1.2' },
hwMemFree => { oid => '.1.3.6.1.4.1.43.45.1.6.1.2.1.1.3' },
@ -210,7 +124,7 @@ sub manage_selection {
# a3com-huawei-splat-devm.mib
my $oid_hwMemEntry = '.1.3.6.1.4.1.43.45.1.6.1.2.1.1';
my $results = $options{snmp}->get_table(oid => $oid_hwMemEntry, nothing_quit => 1);
$self->{mem} = {};
$self->{memory} = {};
foreach my $oid (keys %{$results}) {
next if ($oid !~ /^$mapping->{hwMemSize}->{oid}\.(.*)/);
my $instance = $1;
@ -218,10 +132,10 @@ sub manage_selection {
my $total = $result->{hwMemSize};
my $used = $result->{hwMemSize} - $result->{hwMemFree};
$self->{mem}->{$instance} = { display => $instance, used => $used, total => $total };
$self->{memory}->{$instance} = { display => $instance, used => $used, total => $total };
}
if (scalar(keys %{$self->{mem}}) <= 0) {
if (scalar(keys %{$self->{memory}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}

View File

@ -57,7 +57,7 @@ sub check {
return if ($self->check_filter(section => 'disk'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_deviceDiskValueEntry}})) {
next if ($oid !~ /^$mapping->{deviceSensorStatus}->{oid}\.(.*)$/);
next if ($oid !~ /^$mapping->{deviceDiskStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_deviceDiskValueEntry}, instance => $instance);

View File

@ -20,24 +20,10 @@
package network::digi::portserverts::snmp::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
global => {
'000_usage' => { set => {
key_values => [ { name => 'free' }, { name => 'total' } ],
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) = @_;
@ -81,6 +67,25 @@ sub custom_usage_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 0 }
];
$self->{maps_counters}->{memory} = [
{ label => 'usage', set => {
key_values => [ { name => 'free' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -90,95 +95,18 @@ sub new {
$options{options}->add_options(arguments =>
{
});
foreach my $key (('global')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('global')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->manage_selection();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{global}}) {
my $obj = $maps_counters->{global}->{$_}->{obj};
use Data::Dumper;
Data::Dumper::Dumper($obj);
$obj->set(instance => 'global');
my ($value_check) = $obj->execute(values => $self->{global});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "$short_msg"
);
} else {
$self->{output}->output_add(short_msg => "$long_msg");
}
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_memoryTotalMemory = '.1.3.6.1.4.1.332.11.5.3.3.22.11.0';
my $oid_memoryAvailable = '.1.3.6.1.4.1.332.11.5.3.3.22.12.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_memoryTotalMemory, $oid_memoryAvailable],
nothing_quit => 1);
$self->{global} = { free => $result->{$oid_memoryAvailable}, total => $result->{$oid_memoryTotalMemory} };
my $result = $options{snmp}->get_leef(oids => [$oid_memoryTotalMemory, $oid_memoryAvailable],
nothing_quit => 1);
$self->{memory} = { free => $result->{$oid_memoryAvailable}, total => $result->{$oid_memoryTotalMemory} };
}
1;

View File

@ -35,9 +35,9 @@ my $mapping = {
my $oid_extremeFanStatusEntry = '.1.3.6.1.4.1.1916.1.1.1.9.1';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_extremeFanStatusEntry, end => $mapping->{extremeFanOperational}->{oid} };
push @{$self->{request}}, { oid => $oid_extremeFanStatusEntry, end => $mapping->{extremeFanOperational}->{oid} };
}
sub check {
@ -45,7 +45,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan'));
return if ($self->check_filter(section => 'fan'));
my ($exit, $warn, $crit, $checked);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_extremeFanStatusEntry}})) {
@ -53,7 +53,7 @@ sub check {
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremeFanStatusEntry}, instance => $instance);
next if ($self->check_exclude(section => 'fan', instance => $instance));
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance = %s, speed = %s]",

View File

@ -40,9 +40,9 @@ my $mapping = {
my $oid_extremePowerSupplyEntry = '.1.3.6.1.4.1.1916.1.1.1.27.1';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_extremePowerSupplyEntry, start => $mapping->{extremePowerSupplyStatus}->{oid} };
push @{$self->{request}}, { oid => $oid_extremePowerSupplyEntry, start => $mapping->{extremePowerSupplyStatus}->{oid} };
}
sub check_fan_speed {
@ -69,14 +69,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu'));
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_extremePowerSupplyEntry}})) {
next if ($oid !~ /^$mapping->{extremePowerSupplyStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremePowerSupplyEntry}, instance => $instance);
next if ($self->check_exclude(section => 'psu', instance => $instance));
next if ($self->check_filter(section => 'psu', instance => $instance));
if ($result->{extremePowerSupplyStatus} =~ /notPresent/i) {
$self->absent_problem(section => 'psu', instance => $instance);
next;

View File

@ -48,9 +48,9 @@ my $mapping = {
my $oid_extremeSlotEntry = '.1.3.6.1.4.1.1916.1.1.2.2.1';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_extremeSlotEntry, start => $mapping->{extremeSlotName}->{oid}, end => $mapping->{extremeSlotModuleState}->{oid} };
push @{$self->{request}}, { oid => $oid_extremeSlotEntry, start => $mapping->{extremeSlotName}->{oid}, end => $mapping->{extremeSlotModuleState}->{oid} };
}
sub check {
@ -58,14 +58,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking slots");
$self->{components}->{slot} = {name => 'slots', total => 0, skip => 0};
return if ($self->check_exclude(section => 'slot'));
return if ($self->check_filter(section => 'slot'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_extremeSlotEntry}})) {
next if ($oid !~ /^$mapping->{extremeSlotModuleState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremeSlotEntry}, instance => $instance);
next if ($self->check_exclude(section => 'slot', instance => $instance));
next if ($self->check_filter(section => 'slot', instance => $instance));
if ($result->{extremeSlotModuleState} =~ /notPresent/i) {
$self->absent_problem(section => 'slot', instance => $instance);
next;

View File

@ -28,9 +28,9 @@ my $mapping = {
};
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $mapping->{extremeCurrentTemperature}->{oid} };
push @{$self->{request}}, { oid => $mapping->{extremeCurrentTemperature}->{oid} };
}
sub check {
@ -38,13 +38,13 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_exclude(section => 'temperature'));
return if ($self->check_filter(section => 'temperature'));
return if (!defined($self->{results}->{$mapping->{extremeCurrentTemperature}->{oid}}->{$mapping->{extremeCurrentTemperature}->{oid} . '.0'}));
my $instance = 0;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{extremeCurrentTemperature}->{oid}}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance));
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("temperature is %dC [instance: %s].",

View File

@ -20,71 +20,89 @@
package network::extreme::snmp::mode::cpu;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
cpu => {
'000_5secs' => { set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization5secs' }, { name => 'num' }, ],
output_template => '5 seconds : %.2f %%',
perfdatas => [
{ label => 'cpu_5secs', value => 'extremeCpuMonitorSystemUtilization5secs_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
'001_10secs' => { set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization10secs' }, { name => 'num' }, ],
output_template => '10 seconds : %.2f %%',
perfdatas => [
{ label => 'cpu_10secs', value => 'extremeCpuMonitorSystemUtilization10secs_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
'002_30secs' => { set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization30secs' }, { name => 'num' }, ],
output_template => '30 seconds : %.2f %%',
perfdatas => [
{ label => 'cpu_30secs', value => 'extremeCpuMonitorSystemUtilization30secs_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
'003_1min' => { set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization1min' }, { name => 'num' }, ],
output_template => '1 minute : %.2f %%',
perfdatas => [
{ label => 'cpu_1min', value => 'extremeCpuMonitorSystemUtilization1min_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
'004_5min' => { set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization5mins' }, { name => 'num' }, ],
output_template => '5 minutes : %.2f %%',
perfdatas => [
{ label => 'cpu_5min', value => 'extremeCpuMonitorSystemUtilization5mins_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_init => 'skip_global', },
{ name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usages are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total CPU Usage : %.2f %%',
perfdatas => [
{ label => 'cpu_total', value => 'total_absolute', template => '%.2f', min => 0, max => 100, unit => '%' },
],
}
},
total => {
'000_total' => { set => {
key_values => [ { name => 'total' } ],
output_template => 'CPU Usage : %.2f %%',
perfdatas => [
{ label => 'cpu_total', value => 'total_absolute', template => '%.2f', min => 0, max => 100, unit => '%' },
],
}
},
}
};
];
$self->{maps_counters}->{cpu} = [
{ label => '5secs', set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization5secs' }, { name => 'num' }, ],
output_template => '5 seconds : %.2f %%',
perfdatas => [
{ label => 'cpu_5secs', value => 'extremeCpuMonitorSystemUtilization5secs_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
{ label => '10secs', set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization10secs' }, { name => 'num' }, ],
output_template => '10 seconds : %.2f %%',
perfdatas => [
{ label => 'cpu_10secs', value => 'extremeCpuMonitorSystemUtilization10secs_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
{ label => '30secs', set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization30secs' }, { name => 'num' }, ],
output_template => '30 seconds : %.2f %%',
perfdatas => [
{ label => 'cpu_30secs', value => 'extremeCpuMonitorSystemUtilization30secs_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
{ label => '1min', set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization1min' }, { name => 'num' }, ],
output_template => '1 minute : %.2f %%',
perfdatas => [
{ label => 'cpu_1min', value => 'extremeCpuMonitorSystemUtilization1min_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
{ label => '5min', set => {
key_values => [ { name => 'extremeCpuMonitorSystemUtilization5mins' }, { name => 'num' }, ],
output_template => '5 minutes : %.2f %%',
perfdatas => [
{ label => 'cpu_5min', value => 'extremeCpuMonitorSystemUtilization5mins_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
],
}
},
];
}
sub skip_global {
my ($self, %options) = @_;
scalar(keys %{$self->{cpu}}) > 1 ? return(0) : return(1);
}
sub prefix_cpu_output {
my ($self, %options) = @_;
return "CPU '" . $options{instance_value}->{num} . "' ";
}
sub new {
my ($class, %options) = @_;
@ -94,147 +112,11 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
foreach my $key (('cpu', 'total')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('cpu', 'total')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
}
sub check_total {
my ($self, %options) = @_;
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{total}}) {
my $obj = $maps_counters->{total}->{$_}->{obj};
$obj->set(instance => 'global');
my ($value_check) = $obj->execute(values => $self->{global});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Total $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Total $long_msg");
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{cpu}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->check_total();
}
####
# By CPU
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All CPU usages are ok');
}
foreach my $id (sort keys %{$self->{cpu}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{cpu}}) {
my $obj = $maps_counters->{cpu}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{cpu}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{cpu}->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "CPU '" . $self->{cpu}->{$id}->{num} . "' Usage $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "CPU '" . $self->{cpu}->{$id}->{num} . "' Usage $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "CPU '" . $self->{cpu}->{$id}->{num} . "' Usage $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
my $mapping = {
extremeCpuMonitorSystemUtilization5secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.5' },
extremeCpuMonitorSystemUtilization10secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.6' },
@ -248,23 +130,22 @@ sub manage_selection {
my $oid_extremeCpuMonitorSystemEntry = '.1.3.6.1.4.1.1916.1.32.1.4.1';
my $oid_extremeCpuMonitorTotalUtilization = '.1.3.6.1.4.1.1916.1.32.1.2'; # without .0
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
$self->{results} = $options{snmp}->get_multiple_table(oids => [
{ oid => $oid_extremeCpuMonitorTotalUtilization },
{ oid => $oid_extremeCpuMonitorSystemEntry },
],
, nothing_quit => 1);
], nothing_quit => 1);
$self->{cpu} = {};
foreach my $oid (keys %{$self->{results}->{$oid_extremeCpuMonitorSystemEntry}}) {
next if ($oid !~ /^$mapping->{extremeCpuMonitorSystemUtilization1min}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremeCpuMonitorSystemEntry}, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremeCpuMonitorSystemEntry}, instance => $instance);
foreach (keys %{$mapping}) {
$result->{$_} = undef if (defined($result->{$_}) && $result->{$_} =~ /n\/a/i);
}
$self->{cpu}->{$instance} = {num => $instance, %$result};
$self->{cpu}->{$instance} = { num => $instance, %$result };
}
$self->{global} = { total => $self->{results}->{$oid_extremeCpuMonitorTotalUtilization}->{$oid_extremeCpuMonitorTotalUtilization . '.0'} };
@ -280,6 +161,11 @@ Check CPU usages.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^(1min|5min)$'
=item B<--warning-*>
Threshold warning.

View File

@ -20,40 +20,60 @@
package network::extreme::snmp::mode::hardware;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
my $thresholds = {
psu => [
['notPresent', 'OK'],
['presentOK', 'OK'],
['presentPowerOff', 'WARNING'],
['presentNotOK', 'CRITICAL'],
],
fan => [
['not operational', 'CRITICAL'],
['operational', 'OK'],
],
slot => [
['notPresent', 'OK'],
['testing', 'OK'],
['mismatch', 'WARNING'],
['failed', 'CRITICAL'],
['operational', 'OK'],
['powerdown', 'WARNING'],
['unknown', 'UNKNOWN'],
['present', 'OK'],
['poweron', 'OK'],
['post', 'UNKNOWN'],
['downloading', 'WARNING'],
['booting', 'WARNING'],
['offline', 'WARNING'],
['initializing', 'OK'],
['invalid', 'CRITICAL'],
],
};
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|slot)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan|psu\.power|psu\.fan)$';
$self->{cb_hook2} = 'snmp_execute';
#Example for threshold:
$self->{thresholds} = {
psu => [
['notPresent', 'OK'],
['presentOK', 'OK'],
['presentPowerOff', 'WARNING'],
['presentNotOK', 'CRITICAL'],
],
fan => [
['not operational', 'CRITICAL'],
['operational', 'OK'],
],
slot => [
['notPresent', 'OK'],
['testing', 'OK'],
['mismatch', 'WARNING'],
['failed', 'CRITICAL'],
['operational', 'OK'],
['powerdown', 'WARNING'],
['unknown', 'UNKNOWN'],
['present', 'OK'],
['poweron', 'OK'],
['post', 'UNKNOWN'],
['downloading', 'WARNING'],
['booting', 'WARNING'],
['offline', 'WARNING'],
['initializing', 'OK'],
['invalid', 'CRITICAL'],
],
};
$self->{components_path} = 'network::extreme::snmp::mode::components';
$self->{components_module} = ['fan', 'psu', 'slot', 'temperature'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new {
my ($class, %options) = @_;
@ -63,206 +83,11 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"exclude:s" => { name => 'exclude' },
"absent-problem:s" => { name => 'absent' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $regexp, $value) = ($1, $2, $3);
if ($section !~ /^(temperature|fan|psu\.power|psu\.fan)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature, fan, psu.power, psu.fan).");
$self->{output}->option_exit();
}
my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) {
$position = scalar(@{$self->{numeric_threshold}->{$section}});
}
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
$self->{output}->option_exit();
}
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp };
}
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('fan', 'psu', 'slot', 'temperature');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::extreme::snmp::mode::components::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
my $func = $mod_name->can('load');
$func->(request => $snmp_request);
}
}
if (scalar(@{$snmp_request}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::extreme::snmp::mode::components::$_";
my $func = $mod_name->can('check');
$func->($self);
}
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_exclude {
my ($self, %options) = @_;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
}
sub absent_problem {
my ($self, %options) = @_;
if (defined($self->{option_results}->{absent}) &&
$self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Component '%s' instance '%s' is not present",
$options{section}, $options{instance}));
}
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
$self->{components}->{$options{section}}->{skip}++;
return 1;
}
sub get_severity_numeric {
my ($self, %options) = @_;
my $status = 'OK'; # default
my $thresholds = { warning => undef, critical => undef };
my $checked = 0;
if (defined($self->{numeric_threshold}->{$options{section}})) {
my $exits = [];
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
if ($options{instance} =~ /$_->{regexp}/) {
push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]);
$thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label});
$checked = 1;
}
}
$status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0);
}
return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked);
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1;
__END__
@ -278,15 +103,15 @@ Check Hardware (Fans, Power Supplies, Slot, Temperature).
Which component to check (Default: '.*').
Can be: 'fan', 'psu', 'slot', 'temperature'.
=item B<--exclude>
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fan)
Can also exclude specific instance: --exclude=fan#101#
Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
Can also exclude specific instance: --filter=fan,101
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=psu#1#
Can be specific or global: --absent-problem=psu,1
=item B<--no-component>
@ -295,7 +120,7 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='psu,CRITICAL,^(?!(presentOK)$)'

View File

@ -20,24 +20,10 @@
package network::extreme::snmp::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
'000_usage' => { set => {
key_values => [
{ name => 'display' }, { name => 'free' }, { name => 'total' },
],
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) = @_;
@ -86,6 +72,31 @@ sub custom_usage_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok' }
];
$self->{maps_counters}->{memory} = [
{ label => 'usage', set => {
key_values => [ { name => 'display' }, { name => 'free' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub prefix_memory_output {
my ($self, %options) = @_;
return "Memory '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -94,95 +105,11 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
foreach (keys %{$maps_counters}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{memory_selected}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All memory usages are ok');
}
foreach my $id (sort keys %{$self->{memory_selected}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => $id);
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{memory_selected}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
my $mapping = {
extremeMemoryMonitorSystemFree => { oid => '.1.3.6.1.4.1.1916.1.32.2.2.1.3' },
extremeMemoryMonitorSystemTotal => { oid => '.1.3.6.1.4.1.1916.1.32.2.2.1.2' },
@ -191,17 +118,17 @@ my $mapping = {
sub manage_selection {
my ($self, %options) = @_;
$self->{memory_selected} = {};
$self->{memory} = {};
my $oid_extremeMemoryMonitorSystemEntry = '.1.3.6.1.4.1.1916.1.32.2.2.1';
$self->{results} = $self->{snmp}->get_table(oid => $oid_extremeMemoryMonitorSystemEntry,
nothing_quit => 1);
$self->{results} = $options{snmp}->get_table(oid => $oid_extremeMemoryMonitorSystemEntry,
nothing_quit => 1);
foreach my $oid (keys %{$self->{results}}) {
next if ($oid !~ /^$mapping->{extremeMemoryMonitorSystemFree}->{oid}\.(\d+)/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
$self->{memory_selected}->{$instance} = { display => $instance,
free => $result->{extremeMemoryMonitorSystemFree} * 1024, total => $result->{extremeMemoryMonitorSystemTotal} * 1024};
$self->{memory}->{$instance} = { display => $instance,
free => $result->{extremeMemoryMonitorSystemFree} * 1024, total => $result->{extremeMemoryMonitorSystemTotal} * 1024};
}
}

View File

@ -36,9 +36,9 @@ my $mapping = {
my $oid_sysChassisFanEntry = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_sysChassisFanEntry };
push @{$self->{request}}, { oid => $oid_sysChassisFanEntry };
}
sub check {
@ -46,7 +46,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan'));
return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sysChassisFanEntry}})) {
next if ($oid !~ /^$mapping->{sysChassisFanStatus}->{oid}\.(.*)$/);
@ -55,7 +55,7 @@ sub check {
next if ($result->{sysChassisFanStatus} =~ /notPresent/i &&
$self->absent_problem(section => 'fan', instance => $instance));
next if ($self->check_exclude(section => 'fan', instance => $instance));
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;

View File

@ -34,9 +34,9 @@ my $mapping = {
};
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $mapping->{sysChassisPowerSupplyStatus}->{oid} };
push @{$self->{request}}, { oid => $mapping->{sysChassisPowerSupplyStatus}->{oid} };
}
sub check {
@ -44,7 +44,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu'));
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{sysChassisPowerSupplyStatus}->{oid}}})) {
$oid =~ /^$mapping->{sysChassisPowerSupplyStatus}->{oid}\.(.*)$/;
@ -53,7 +53,7 @@ sub check {
next if ($result->{sysChassisPowerSupplyStatus} =~ /notPresent/i &&
$self->absent_problem(section => 'psu', instance => $instance));
next if ($self->check_exclude(section => 'psu', instance => $instance));
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;

View File

@ -28,9 +28,9 @@ my $mapping = {
};
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $mapping->{sysChassisTempTemperature}->{oid} };
push @{$self->{request}}, { oid => $mapping->{sysChassisTempTemperature}->{oid} };
}
sub check {
@ -38,14 +38,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_exclude(section => 'temperature'));
return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{sysChassisTempTemperature}->{oid}}})) {
$oid =~ /^$mapping->{sysChassisTempTemperature}->{oid}\.(.*)$/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{sysChassisTempTemperature}->{oid}}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance));
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("temperature '%s' is %.2f C [instance: %s].",

View File

@ -20,16 +20,29 @@
package network::f5::bigip::mode::connections;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
global => [
sub custom_client_tps_calc {
my ($self, %options) = @_;
my $diff_native = $options{new_datas}->{$self->{instance} . '_client_ssl_tot_native'} - $options{old_datas}->{$self->{instance} . '_client_ssl_tot_native'};
my $diff_compat = $options{new_datas}->{$self->{instance} . '_client_ssl_tot_compat'} - $options{old_datas}->{$self->{instance} . '_client_ssl_tot_compat'};
$self->{result_values}->{client_ssl_tps} = ($diff_native + $diff_compat) / $options{delta_time};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'client', set => {
key_values => [ { name => 'client' } ],
output_template => 'Current client connections : %s',
@ -48,10 +61,10 @@ my $maps_counters = {
],
}
},
{ label => 'client-ssl-tps', set => {
{ label => 'client-ssl-tps', set => {
key_values => [ { name => 'client_ssl_tot_native', diff => 1 }, { name => 'client_ssl_tot_compat', diff => 1 } ],
output_template => 'TPS client SSL connections : %.2f', threshold_use => 'client_ssl_tps', output_use => 'client_ssl_tps',
closure_custom_calc => \&custom_client_tps_calc,
closure_custom_calc => $self->can('custom_client_tps_calc'),
per_second => 1,
perfdatas => [
{ label => 'ClientSSL_Tps', value => 'client_ssl_tps', template => '%.2f',
@ -59,7 +72,7 @@ my $maps_counters = {
],
}
},
{ label => 'server', set => {
{ label => 'server', set => {
key_values => [ { name => 'server' } ],
output_template => 'Current server connections: %s',
perfdatas => [
@ -77,22 +90,12 @@ my $maps_counters = {
],
}
},
]
};
sub custom_client_tps_calc {
my ($self, %options) = @_;
my $diff_native = $options{new_datas}->{$self->{instance} . '_client_ssl_tot_native'} - $options{old_datas}->{$self->{instance} . '_client_ssl_tot_native'};
my $diff_compat = $options{new_datas}->{$self->{instance} . '_client_ssl_tot_compat'} - $options{old_datas}->{$self->{instance} . '_client_ssl_tot_compat'};
$self->{result_values}->{client_ssl_tps} = ($diff_native + $diff_compat) / $options{delta_time};
return 0;
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -100,100 +103,10 @@ sub new {
{
"filter-counters:s" => { name => 'filter_counters' },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach my $key (('global')) {
foreach (@{$maps_counters->{$key}}) {
if (!defined($_->{threshold}) || $_->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $_->{label} . ':s' => { name => 'warning-' . $_->{label} },
'critical-' . $_->{label} . ':s' => { name => 'critical-' . $_->{label} },
});
}
$_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_->{label});
$_->{obj}->set(%{$_->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('global')) {
foreach (@{$maps_counters->{$key}}) {
$_->{obj}->init(option_results => $self->{option_results});
}
}
$self->{statefile_value}->check_options(%options);
}
sub run_global {
my ($self, %options) = @_;
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (@{$maps_counters->{global}}) {
my $obj = $_->{obj};
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{name} !~ /$self->{option_results}->{filter_counters}/);
$obj->set(instance => 'global');
my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, values => $self->{global});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "$short_msg"
);
} else {
$self->{output}->output_add(short_msg => "$long_msg");
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => $self->{cache_name});
$self->{new_datas}->{last_timestamp} = time();
$self->run_global();
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;

View File

@ -20,24 +20,43 @@
package network::f5::bigip::mode::hardware;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use centreon::plugins::misc;
my $thresholds = {
fan => [
['bad', 'CRITICAL'],
['good', 'OK'],
['notPresent', 'OK'],
],
psu => [
['bad', 'CRITICAL'],
['good', 'OK'],
['notPresent', 'OK'],
],
};
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|psu)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$';
$self->{cb_hook2} = 'snmp_execute';
#Example for threshold:
$self->{thresholds} = {
fan => [
['bad', 'CRITICAL'],
['good', 'OK'],
['notPresent', 'OK'],
],
psu => [
['bad', 'CRITICAL'],
['good', 'OK'],
['notPresent', 'OK'],
],
};
$self->{components_path} = 'network::f5::bigip::mode::components';
$self->{components_module} = ['fan', 'psu', 'temperature'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new {
my ($class, %options) = @_;
@ -46,230 +65,12 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"exclude:s" => { name => 'exclude' },
"absent-problem:s@" => { name => 'absent_problem' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
{
});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
$self->{absent_problem} = [];
foreach my $val (@{$self->{option_results}->{absent_problem}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] };
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
if (scalar(@values) < 3) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $status, $filter);
if (scalar(@values) == 3) {
($section, $status, $filter) = @values;
$instance = '.*';
} else {
($section, $instance, $status, $filter) = @values;
}
if ($section !~ /^(temperature|fan|psu)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'.");
$self->{output}->option_exit();
}
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance };
}
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
next if (!defined($val) || $val eq '');
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $value) = ($1, $2, $3);
if ($section !~ /^(temperature|fan)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) {
$position = scalar(@{$self->{numeric_threshold}->{$section}});
}
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
$self->{output}->option_exit();
}
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance };
}
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('fan', 'psu', 'temperature');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::f5::bigip::mode::components::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
my $func = $mod_name->can('load');
$func->(request => $snmp_request);
}
}
if (scalar(@{$snmp_request}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::f5::bigip::mode::components::$_";
my $func = $mod_name->can('check');
$func->($self);
}
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_exclude {
my ($self, %options) = @_;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
}
sub absent_problem {
my ($self, %options) = @_;
foreach (@{$self->{absent_problem}}) {
if ($options{section} =~ /$_->{filter}/) {
if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Component '%s' instance '%s' is not present",
$options{section}, $options{instance}));
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
$self->{components}->{$options{section}}->{skip}++;
return 1;
}
}
}
return 0;
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i &&
(!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
$status = $_->{status};
return $status;
}
}
}
my $label = defined($options{label}) ? $options{label} : $options{section};
foreach (@{$thresholds->{$label}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
sub get_severity_numeric {
my ($self, %options) = @_;
my $status = 'OK'; # default
my $thresholds = { warning => undef, critical => undef };
my $checked = 0;
if (defined($self->{numeric_threshold}->{$options{section}})) {
my $exits = [];
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
if ($options{instance} =~ /$_->{instance}/) {
push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]);
$thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label});
$checked = 1;
}
}
$status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0);
}
return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked);
}
1;
__END__
@ -285,10 +86,10 @@ Check hardware (fans, temperatures, power supplies).
Which component to check (Default: '.*').
Can be: 'fan', 'psu', 'temperature'.
=item B<--exclude>
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fan,psu)
Can be specific or global: --exclude=fan#1#2#,psu
Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
Can also exclude specific instance: --filter=fan,1
=item B<--no-component>
@ -299,7 +100,7 @@ If total (with skipped) is 0. (Default: 'critical' returns).
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='powerQuality,CRITICAL,^(?!(normal)$)'
Example: --threshold-overload='fan,CRITICAL,^(?!(good)$)'
=item B<--warning>

View File

@ -20,11 +20,10 @@
package network::f5::bigip::mode::nodestatus;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $thresholds = {
node => [
@ -38,21 +37,6 @@ my $thresholds = {
};
my $instance_mode;
my $maps_counters = {
node => {
'000_status' => { set => {
key_values => [ { name => 'AvailState' } ],
closure_custom_calc => \&custom_status_calc,
output_template => 'Status : %s', output_error_template => 'Status : %s',
output_use => 'AvailState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&custom_threshold_output,
}
},
},
};
sub custom_threshold_output {
my ($self, %options) = @_;
@ -66,6 +50,31 @@ sub custom_status_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All Nodes are ok' },
];
$self->{maps_counters}->{node} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'AvailState' } ],
closure_custom_calc => $self->can('custom_status_calc'),
output_template => 'Status : %s', output_error_template => 'Status : %s',
output_use => 'AvailState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'),
}
},
];
}
sub prefix_node_output {
my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{Name} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -77,21 +86,6 @@ sub new {
"filter-name:s" => { name => 'filter_name' },
"threshold-overload:s@" => { name => 'threshold_overload' },
});
foreach my $key (('node')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
@ -100,12 +94,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('node')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$instance_mode = $self;
$self->{overload_th} = {};
@ -124,69 +112,6 @@ sub check_options {
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{node}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All Nodes are ok');
}
foreach my $id (sort keys %{$self->{node}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{node}}) {
my $obj = $maps_counters->{node}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{node}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{node}->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Node '$self->{node}->{$id}->{Name}' $long_msg [Status Reason: $self->{node}->{$id}->{StatusReason}]");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Node '$self->{node}->{$id}->{Name}' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Node '$self->{node}->{$id}->{Name}' $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
@ -243,7 +168,7 @@ my $oid_ltmNodeAddrEntry = '.1.3.6.1.4.1.3375.2.2.4.1.2.1'; # old
sub manage_selection {
my ($self, %options) = @_;
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
$self->{results} = $options{snmp}->get_multiple_table(oids => [
{ oid => $oid_ltmNodeAddrEntry, start => $mapping->{old}->{AvailState}->{oid} },
{ oid => $oid_ltmNodeAddrStatusEntry, start => $mapping->{new}->{AvailState}->{oid} },
],
@ -258,7 +183,7 @@ sub manage_selection {
foreach my $oid (keys %{$self->{results}->{$branch}}) {
next if ($oid !~ /^$mapping->{$map}->{AvailState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $instance);
$result->{Name} = $instance;
# prefix by '1.4'

View File

@ -20,11 +20,10 @@
package network::f5::bigip::mode::poolstatus;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $thresholds = {
pool => [
@ -38,21 +37,6 @@ my $thresholds = {
};
my $instance_mode;
my $maps_counters = {
pool => {
'000_status' => { set => {
key_values => [ { name => 'AvailState' } ],
closure_custom_calc => \&custom_status_calc,
output_template => 'Status : %s', output_error_template => 'Status : %s',
output_use => 'AvailState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&custom_threshold_output,
}
},
},
};
sub custom_threshold_output {
my ($self, %options) = @_;
@ -66,6 +50,31 @@ sub custom_status_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All Pools are ok' },
];
$self->{maps_counters}->{pool} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'AvailState' } ],
closure_custom_calc => $self->can('custom_status_calc'),
output_template => 'Status : %s', output_error_template => 'Status : %s',
output_use => 'AvailState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'),
}
},
];
}
sub prefix_pool_output {
my ($self, %options) = @_;
return "Pool '" . $options{instance_value}->{Name} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -77,21 +86,6 @@ sub new {
"filter-name:s" => { name => 'filter_name' },
"threshold-overload:s@" => { name => 'threshold_overload' },
});
foreach my $key (('pool')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
@ -100,12 +94,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('pool')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$instance_mode = $self;
$self->{overload_th} = {};
@ -124,69 +112,6 @@ sub check_options {
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{pool}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All Pools are ok');
}
foreach my $id (sort keys %{$self->{pool}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{pool}}) {
my $obj = $maps_counters->{pool}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{pool}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{pool}->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Pool '$self->{pool}->{$id}->{Name}' $long_msg [Status Reason: $self->{pool}->{$id}->{StatusReason}]");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Pool '$self->{pool}->{$id}->{Name}' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Pool '$self->{pool}->{$id}->{Name}' $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
@ -243,7 +168,7 @@ my $oid_ltmPoolEntry = '.1.3.6.1.4.1.3375.2.2.5.1.2.1'; # old
sub manage_selection {
my ($self, %options) = @_;
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
$self->{results} = $options{snmp}->get_multiple_table(oids => [
{ oid => $oid_ltmPoolEntry, start => $mapping->{old}->{AvailState}->{oid} },
{ oid => $oid_ltmPoolStatusEntry, start => $mapping->{new}->{AvailState}->{oid} },
],
@ -258,7 +183,7 @@ sub manage_selection {
foreach my $oid (keys %{$self->{results}->{$branch}}) {
next if ($oid !~ /^$mapping->{$map}->{AvailState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $instance);
$result->{Name} = '';
foreach (split /\./, $instance) {

View File

@ -20,11 +20,10 @@
package network::f5::bigip::mode::virtualserverstatus;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $thresholds = {
vs => [
@ -38,20 +37,6 @@ my $thresholds = {
};
my $instance_mode;
my $maps_counters = {
vs => {
'000_status' => { set => {
key_values => [ { name => 'AvailState' } ],
closure_custom_calc => \&custom_status_calc,
output_template => 'Status : %s', output_error_template => 'Status : %s',
output_use => 'AvailState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&custom_threshold_output,
}
},
},
};
sub custom_threshold_output {
my ($self, %options) = @_;
@ -65,6 +50,31 @@ sub custom_status_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'vs', type => 1, cb_prefix_output => 'prefix_vs_output', message_multiple => 'All Virtual Servers are ok' },
];
$self->{maps_counters}->{vs} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'AvailState' } ],
closure_custom_calc => $self->can('custom_status_calc'),
output_template => 'Status : %s', output_error_template => 'Status : %s',
output_use => 'AvailState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'),
}
},
];
}
sub prefix_vs_output {
my ($self, %options) = @_;
return "Virtual Server '" . $options{instance_value}->{Name} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -76,21 +86,6 @@ sub new {
"filter-name:s" => { name => 'filter_name' },
"threshold-overload:s@" => { name => 'threshold_overload' },
});
foreach my $key (('vs')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
@ -99,12 +94,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('vs')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$instance_mode = $self;
$self->{overload_th} = {};
@ -123,69 +112,6 @@ sub check_options {
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{vs}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All Virtual Servers are ok');
}
foreach my $id (sort keys %{$self->{vs}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{vs}}) {
my $obj = $maps_counters->{vs}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{vs}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{vs}->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Virtual Server '$self->{vs}->{$id}->{Name}' $long_msg [Status Reason: $self->{vs}->{$id}->{StatusReason}]");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Virtual Server '$self->{vs}->{$id}->{Name}' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Virtual Server '$self->{vs}->{$id}->{Name}' $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
@ -242,7 +168,7 @@ my $oid_ltmVirtualServEntry = '.1.3.6.1.4.1.3375.2.2.10.1.2.1'; # old
sub manage_selection {
my ($self, %options) = @_;
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
$self->{results} = $options{snmp}->get_multiple_table(oids => [
{ oid => $oid_ltmVirtualServEntry, start => $mapping->{old}->{AvailState}->{oid} },
{ oid => $oid_ltmVsStatusEntry, start => $mapping->{new}->{AvailState}->{oid} },
],
@ -257,7 +183,7 @@ sub manage_selection {
foreach my $oid (keys %{$self->{results}->{$branch}}) {
next if ($oid !~ /^$mapping->{$map}->{AvailState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $instance);
$result->{Name} = '';
foreach (split /\./, $instance) {

View File

@ -20,25 +20,10 @@
package network::redback::snmp::mode::disk;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
'0_usage' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'display' }, { name => 'total' }, { name => 'used' },
],
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) = @_;
@ -87,6 +72,31 @@ sub custom_usage_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disk usages are ok' }
];
$self->{maps_counters}->{disk} = [
{ label => 'usage', set => {
key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub prefix_disk_output {
my ($self, %options) = @_;
return "Disk '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -97,95 +107,10 @@ sub new {
{
"filter-name:s" => { name => 'filter_name' },
});
foreach (keys %{$maps_counters}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{disk_selected}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All disk usages are ok');
}
foreach my $id (sort keys %{$self->{disk_selected}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => $id);
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{disk_selected}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Disk '" . $self->{disk_selected}->{$id}->{display} . "' $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Disk '" . $self->{disk_selected}->{$id}->{display} . "' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Disk '" . $self->{disk_selected}->{$id}->{display} . "' $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
my $mapping = {
rbnSRStorageDescr => { oid => '.1.3.6.1.4.1.2352.2.24.1.2.1.1.2' },
rbnSRStorageSize => { oid => '.1.3.6.1.4.1.2352.2.24.1.2.1.1.5' }, # KB
@ -195,14 +120,14 @@ my $mapping = {
sub manage_selection {
my ($self, %options) = @_;
$self->{disk_selected} = {};
$self->{disk} = {};
my $oid_rbnSRStorageEntry = '.1.3.6.1.4.1.2352.2.24.1.2.1.1';
$self->{results} = $self->{snmp}->get_table(oid => $oid_rbnSRStorageEntry,
$self->{results} = $options{snmp}->get_table(oid => $oid_rbnSRStorageEntry,
nothing_quit => 1);
foreach my $oid (keys %{$self->{results}}) {
next if ($oid !~ /^$mapping->{rbnSRStorageSize}->{oid}\.(\d+)/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{rbnSRStorageDescr} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $result->{rbnSRStorageDescr} . "': no matching filter.");
@ -213,11 +138,11 @@ sub manage_selection {
next;
}
$self->{disk_selected}->{$instance} = { display => $result->{rbnSRStorageDescr},
used => $result->{rbnSRStorageUtilization}, total => $result->{rbnSRStorageSize} * 1024};
$self->{disk}->{$instance} = { display => $result->{rbnSRStorageDescr},
used => $result->{rbnSRStorageUtilization}, total => $result->{rbnSRStorageSize} * 1024};
}
if (scalar(keys %{$self->{disk_selected}}) <= 0) {
if (scalar(keys %{$self->{disk}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}

View File

@ -20,25 +20,10 @@
package network::redback::snmp::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
'0_usage' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'display' }, { name => 'free' }, { name => 'used' },
],
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) = @_;
@ -87,6 +72,31 @@ sub custom_usage_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok' }
];
$self->{maps_counters}->{memory} = [
{ label => 'usage', set => {
key_values => [ { name => 'display' }, { name => 'free' }, { name => 'used' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub prefix_memory_output {
my ($self, %options) = @_;
return "Memory '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -96,96 +106,11 @@ sub new {
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
foreach (keys %{$maps_counters}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
my $multiple = 1;
if (scalar(keys %{$self->{memory_selected}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All memory usages are ok');
}
foreach my $id (sort keys %{$self->{memory_selected}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => $id);
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{memory_selected}->{$id});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
my $mapping = {
rbnMemoryModule => { oid => '.1.3.6.1.4.1.2352.2.16.1.2.1.2' },
rbnMemoryFreeKBytes => { oid => '.1.3.6.1.4.1.2352.2.16.1.2.1.3' },
@ -195,25 +120,25 @@ my $mapping = {
sub manage_selection {
my ($self, %options) = @_;
$self->{memory_selected} = {};
$self->{memory} = {};
my $oid_rbnMemoryEntry = '.1.3.6.1.4.1.2352.2.16.1.2.1';
$self->{results} = $self->{snmp}->get_table(oid => $oid_rbnMemoryEntry,
nothing_quit => 1);
$self->{results} = $options{snmp}->get_table(oid => $oid_rbnMemoryEntry,
nothing_quit => 1);
foreach my $oid (keys %{$self->{results}}) {
next if ($oid !~ /^$mapping->{rbnMemoryModule}->{oid}\.(\d+)/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{rbnMemoryModule} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $result->{rbnMemoryModule} . "': no matching filter.");
next;
}
$self->{memory_selected}->{$instance} = { display => $result->{rbnMemoryModule},
free => $result->{rbnMemoryFreeKBytes} * 1024, used => $result->{rbnMemoryKBytesInUse} * 1024};
$self->{memory}->{$instance} = { display => $result->{rbnMemoryModule},
free => $result->{rbnMemoryFreeKBytes} * 1024, used => $result->{rbnMemoryKBytesInUse} * 1024};
}
if (scalar(keys %{$self->{memory_selected}}) <= 0) {
if (scalar(keys %{$self->{memory}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}

View File

@ -20,83 +20,42 @@
package snmp_standard::mode::diskio;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::values;
my $maps_counters = {
disk => {
'000_read' => { set => {
key_values => [ { name => 'read', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Read I/O : %s %s/s', output_error_template => "Read I/O : %s",
output_change_bytes => 1,
perfdatas => [
{ label => 'read', value => 'read_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
'001_write' => { set => {
key_values => [ { name => 'write', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Write I/O : %s %s/s', output_error_template => "Write I/O : %s",
output_change_bytes => 1,
perfdatas => [
{ label => 'write', value => 'write_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
'002_read-iops' => { set => {
key_values => [ { name => 'read_iops', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s",
perfdatas => [
{ label => 'read_iops', value => 'read_iops_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
'003_write-iops' => { set => {
key_values => [ { name => 'write_iops', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s",
perfdatas => [
{ label => 'write_iops', value => 'write_iops_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
},
total => {
'000_total-read' => { set => {
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_init => 'skip_global', cb_prefix_output => 'prefix_global_output', cb_suffix_output => 'suffix_output' },
{ name => 'sum', type => 0, cb_init => 'skip_global', cb_prefix_output => 'prefix_sum_output', cb_suffix_output => 'suffix_output' },
{ name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All devices are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'total-read', set => {
key_values => [ { name => 'total_read', diff => 1 } ],
per_second => 1,
output_template => 'Read I/O : %s %s/s', output_error_template => "Read I/O : %s",
output_change_bytes => 1,
output_change_bytes => 1, per_second => 1,
perfdatas => [
{ label => 'total_read', value => 'total_read_per_second', template => '%d',
unit => 'B/s', min => 0 },
],
}
},
'001_total-write' => { set => {
{ label => 'total-write', set => {
key_values => [ { name => 'total_write', diff => 1 } ],
per_second => 1,
output_template => 'Write I/O : %s %s/s', output_error_template => "Write I/O : %s",
output_change_bytes => 1,
output_change_bytes => 1, per_second => 1,
perfdatas => [
{ label => 'total_write', value => 'total_write_per_second', template => '%d',
unit => 'B/s', min => 0 },
],
}
},
'002_total-read-iops' => { set => {
{ label => 'total-read-iops', set => {
key_values => [ { name => 'total_read_iops', diff => 1 } ],
per_second => 1,
output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s",
@ -106,7 +65,7 @@ my $maps_counters = {
],
}
},
'003_total-write-iops' => { set => {
{ label => 'total-write-iops', set => {
key_values => [ { name => 'total_write_iops', diff => 1 } ],
per_second => 1,
output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s",
@ -115,10 +74,11 @@ my $maps_counters = {
unit => 'iops', min => 0 },
],
}
},
},
sum => {
'000_sum-read-write' => { set => {
},
];
$self->{maps_counters}->{sum} = [
{ label => 'sum-read-write', set => {
key_values => [ { name => 'sum_read_write', diff => 1 } ],
per_second => 1,
output_template => 'R+W I/O : %s %s/s', output_error_template => "R+W I/O : %s",
@ -128,8 +88,8 @@ my $maps_counters = {
unit => 'B/s', min => 0 },
],
}
},
'001_sum-read-write-iops' => { set => {
},
{ label => 'sum-read-write-iops', set => {
key_values => [ { name => 'sum_read_write_iops', diff => 1 } ],
per_second => 1,
output_template => 'R+W IOPs : %.2f', output_error_template => "R+W IOPs : %s",
@ -139,18 +99,55 @@ my $maps_counters = {
],
}
},
},
};
my $oid_diskIODevice = '.1.3.6.1.4.1.2021.13.15.1.1.2';
my $oid_diskIOReads = '.1.3.6.1.4.1.2021.13.15.1.1.5';
my $oid_diskIOWrites = '.1.3.6.1.4.1.2021.13.15.1.1.6';
my $oid_diskIONReadX = '.1.3.6.1.4.1.2021.13.15.1.1.12'; # in B
my $oid_diskIONWrittenX = '.1.3.6.1.4.1.2021.13.15.1.1.13'; # in B
];
$self->{maps_counters}->{disk} = [
{ label => 'read', set => {
key_values => [ { name => 'read', diff => 1 }, { name => 'display' } ],
output_template => 'Read I/O : %s %s/s', output_error_template => "Read I/O : %s",
output_change_bytes => 1, per_second => 1,
perfdatas => [
{ label => 'read', value => 'read_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'write', set => {
key_values => [ { name => 'write', diff => 1 }, { name => 'display' } ],
output_template => 'Write I/O : %s %s/s', output_error_template => "Write I/O : %s",
output_change_bytes => 1, per_second => 1,
perfdatas => [
{ label => 'write', value => 'write_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'read-iops', set => {
key_values => [ { name => 'read_iops', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s",
perfdatas => [
{ label => 'read_iops', value => 'read_iops_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'write-iops', set => {
key_values => [ { name => 'write_iops', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s",
perfdatas => [
{ label => 'write_iops', value => 'write_iops_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -161,240 +158,91 @@ sub new {
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
});
$self->{device_id_selected} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach my $key (('total', 'disk', 'sum')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('total', 'disk', 'sum')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$self->{statefile_value}->check_options(%options);
}
sub check_total {
sub skip_global {
my ($self, %options) = @_;
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{total}}) {
my $obj = $maps_counters->{total}->{$_}->{obj};
$obj->set(instance => 'global');
my ($value_check) = $obj->execute(values => $self->{global},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "All devices [$short_msg]"
);
} else {
$self->{output}->output_add(short_msg => "All devices [$long_msg]");
}
scalar(keys %{$self->{disk}}) > 1 ? return(0) : return(1);
}
sub check_sum {
sub prefix_global_output {
my ($self, %options) = @_;
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{sum}}) {
my $obj = $maps_counters->{sum}->{$_}->{obj};
$obj->set(instance => 'sum');
my ($value_check) = $obj->execute(values => $self->{sum_global},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Server overall [$short_msg]"
);
} else {
$self->{output}->output_add(short_msg => "Server overall [$long_msg]");
}
return "All devices [";
}
sub run {
sub prefix_sum_output {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
if ($self->{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{device}) ? md5_hex($self->{option_results}->{device}) : md5_hex('all')));
$self->{new_datas}->{last_timestamp} = time();
my $multiple = 1;
if (scalar(keys %{$self->{device_id_selected}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->check_total();
$self->check_sum();
$self->{output}->output_add(severity => 'OK',
short_msg => 'All devices are ok.');
}
foreach my $id (sort keys %{$self->{device_id_selected}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{disk}}) {
my $obj = $maps_counters->{disk}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{device_id_selected}->{$id},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata(extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Device '" . $self->{device_id_selected}->{$id}->{display} . "' $long_msg");
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Device '" . $self->{device_id_selected}->{$id}->{display} . "' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Device '" . $self->{device_id_selected}->{$id}->{display} . "' $long_msg");
}
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
return "Server overall [";
}
sub prefix_disk_output {
my ($self, %options) = @_;
return "Device '" . $options{instance_value}->{display} . "' ";
}
sub suffix_output {
my ($self, %options) = @_;
return "]";
}
my $oid_diskIODevice = '.1.3.6.1.4.1.2021.13.15.1.1.2';
my $oid_diskIOReads = '.1.3.6.1.4.1.2021.13.15.1.1.5';
my $oid_diskIOWrites = '.1.3.6.1.4.1.2021.13.15.1.1.6';
my $oid_diskIONReadX = '.1.3.6.1.4.1.2021.13.15.1.1.12'; # in B
my $oid_diskIONWrittenX = '.1.3.6.1.4.1.2021.13.15.1.1.13'; # in B
sub add_result {
my ($self, %options) = @_;
$self->{device_id_selected}->{$options{instance}} = { read => undef, write => undef, read_iops => undef, write_iops => undef };
$self->{device_id_selected}->{$options{instance}}->{display} = $self->{results}->{$oid_diskIODevice}->{$oid_diskIODevice . '.' . $options{instance}};
$self->{disk}->{$options{instance}} = { read => undef, write => undef, read_iops => undef, write_iops => undef };
$self->{disk}->{$options{instance}}->{display} = $self->{results}->{$oid_diskIODevice}->{$oid_diskIODevice . '.' . $options{instance}};
if (defined($self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}}) && $self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}} != 0) {
$self->{device_id_selected}->{$options{instance}}->{read} = $self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}};
$self->{global}->{total_read} += $self->{device_id_selected}->{$options{instance}}->{read};
$self->{disk}->{$options{instance}}->{read} = $self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}};
$self->{global}->{total_read} += $self->{disk}->{$options{instance}}->{read};
}
if (defined($self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}}) && $self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}} != 0) {
$self->{device_id_selected}->{$options{instance}}->{write} = $self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}};
$self->{global}->{total_write} += $self->{device_id_selected}->{$options{instance}}->{write};
$self->{disk}->{$options{instance}}->{write} = $self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}};
$self->{global}->{total_write} += $self->{disk}->{$options{instance}}->{write};
}
if (defined($self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}}) && $self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}} != 0) {
$self->{device_id_selected}->{$options{instance}}->{read_iops} = $self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}};
$self->{global}->{total_read_iops} += $self->{device_id_selected}->{$options{instance}}->{read_iops};
$self->{disk}->{$options{instance}}->{read_iops} = $self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}};
$self->{global}->{total_read_iops} += $self->{disk}->{$options{instance}}->{read_iops};
}
if (defined($self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}}) && $self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}} != 0) {
$self->{device_id_selected}->{$options{instance}}->{write_iops} = $self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}};
$self->{global}->{total_write_iops} += $self->{device_id_selected}->{$options{instance}}->{write_iops};
$self->{disk}->{$options{instance}}->{write_iops} = $self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}};
$self->{global}->{total_write_iops} += $self->{disk}->{$options{instance}}->{write_iops};
}
if ($self->{global}->{total_read} && $self->{global}->{total_write}) {
$self->{sum_global}->{sum_read_write} = $self->{global}->{total_read} + $self->{global}->{total_write};
$self->{sum}->{sum_read_write} = $self->{global}->{total_read} + $self->{global}->{total_write};
}
if ($self->{global}->{total_read_iops} && $self->{global}->{total_write_iops}) {
$self->{sum_global}->{sum_read_write_iops} = $self->{global}->{total_read_iops} + $self->{global}->{total_write_iops};
$self->{sum}->{sum_read_write_iops} = $self->{global}->{total_read_iops} + $self->{global}->{total_write_iops};
}
}
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
$self->{cache_name} = "snmpstandard_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{device}) ? md5_hex($self->{option_results}->{device}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
$self->{global} = { total_read => 0, total_write => 0, total_read_iops => 0, total_write_iops => 0 };
$self->{sum_global} = { sum_read_write => 0, sum_read_write_iops => 0 };
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
$self->{sum} = { sum_read_write => 0, sum_read_write_iops => 0 };
$self->{results} = $options{snmp}->get_multiple_table(oids => [
{ oid => $oid_diskIODevice },
{ oid => $oid_diskIOReads },
{ oid => $oid_diskIOWrites },
@ -430,7 +278,7 @@ sub manage_selection {
}
}
if (scalar(keys %{$self->{device_id_selected}}) <= 0 && !defined($options{disco})) {
if (scalar(keys %{$self->{disk}}) <= 0 && !defined($options{disco})) {
if (defined($self->{option_results}->{device})) {
$self->{output}->add_option_msg(short_msg => "No device found '" . $self->{option_results}->{device} . "' (or counter values are 0).");
} else {
@ -449,11 +297,8 @@ sub disco_format {
sub disco_show {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->manage_selection(disco => 1);
foreach (sort keys %{$self->{device_id_selected}}) {
$self->manage_selection(disco => 1, %options);
foreach (sort keys %{$self->{disk}}) {
$self->{output}->add_disco_entry(name => $self->{results}->{$oid_diskIODevice}->{$oid_diskIODevice . '.' . $_},
deviceid => $_);
}