update netapp snmp modes with class counter

This commit is contained in:
garnier-quentin 2019-04-19 10:44:09 +02:00
parent 390dc72ebb
commit df2d54036e
4 changed files with 345 additions and 634 deletions

View File

@ -20,52 +20,15 @@
package storage::netapp::snmp::mode::aggregatestate; package storage::netapp::snmp::mode::aggregatestate;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::values;
my $thresholds = {
state => [
['online', 'OK'],
['offline', 'CRITICAL'],
],
status => [
['normal', 'OK'],
['mirrored', 'OK'],
['.*', 'CRITICAL'],
],
};
my $instance_mode;
my $maps_counters = {
agg => {
'000_state' => { set => {
key_values => [ { name => 'aggrState' } ],
closure_custom_calc => \&custom_state_calc,
output_template => "State : '%s'", output_error_template => "State : '%s'",
output_use => 'aggrState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&custom_state_threshold,
}
},
'001_status' => { set => {
key_values => [ { name => 'aggrStatus' } ],
closure_custom_calc => \&custom_status_calc,
output_template => "Status : '%s'", output_error_template => "Status : '%s'",
output_use => 'aggrStatus',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&custom_status_threshold,
}
},
},
};
sub custom_state_threshold { sub custom_state_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
return $instance_mode->get_severity(section => 'state', value => $self->{result_values}->{aggrState}); return $self->{instance_mode}->get_severity(section => 'state', value => $self->{result_values}->{aggrState});
} }
sub custom_state_calc { sub custom_state_calc {
@ -78,7 +41,7 @@ sub custom_state_calc {
sub custom_status_threshold { sub custom_status_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
return $instance_mode->get_severity(section => 'status', value => $self->{result_values}->{aggrStatus}); return $self->{instance_mode}->get_severity(section => 'status', value => $self->{result_values}->{aggrStatus});
} }
sub custom_status_calc { sub custom_status_calc {
@ -88,48 +51,59 @@ sub custom_status_calc {
return 0; return 0;
} }
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'agg', type => 1, cb_prefix_output => 'prefix_agg_output', message_multiple => 'All aggregates are ok' },
];
$self->{maps_counters}->{agg} = [
{ label => 'state', set => {
key_values => [ { name => 'aggrState' } ],
closure_custom_calc => $self->can('custom_state_calc'),
output_template => "State : '%s'", output_error_template => "State : '%s'",
output_use => 'aggrState',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_state_threshold'),
}
},
{ label => 'status', set => {
key_values => [ { name => 'aggrStatus' } ],
closure_custom_calc => $self->can('custom_status_calc'),
output_template => "Status : '%s'", output_error_template => "Status : '%s'",
output_use => 'aggrStatus',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
}
sub prefix_agg_output {
my ($self, %options) = @_;
return "Aggregate '" . $options{instance_value}->{aggrName} . "' ";
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ "filter-name:s" => { name => 'filter_name' },
"filter-name:s" => { name => 'filter_name' }, "threshold-overload:s@" => { name => 'threshold_overload' },
"threshold-overload:s@" => { name => 'threshold_overload' }, });
});
foreach my $key (('agg')) {
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; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::check_options(%options);
foreach my $key (('agg')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$instance_mode = $self;
$self->{overload_th} = {}; $self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) { if ($val !~ /^(.*?),(.*?),(.*)$/) {
@ -146,67 +120,17 @@ sub check_options {
} }
} }
sub run { my $thresholds = {
my ($self, %options) = @_; state => [
$self->{snmp} = $options{snmp}; ['online', 'OK'],
['offline', 'CRITICAL'],
$self->manage_selection(); ],
status => [
my $multiple = 1; ['normal', 'OK'],
if (scalar(keys %{$self->{agg}}) == 1) { ['mirrored', 'OK'],
$multiple = 0; ['.*', 'CRITICAL'],
} ],
};
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All aggregates status are ok');
}
foreach my $id (sort keys %{$self->{agg}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (sort keys %{$maps_counters->{agg}}) {
my $obj = $maps_counters->{agg}->{$_}->{obj};
$obj->set(instance => $id);
my ($value_check) = $obj->execute(values => $self->{agg}->{$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->{agg}->{$_}->{obj}->perfdata(level => 1, extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Aggregate '$self->{agg}->{$id}->{aggrName}' $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 => "Aggregate '$self->{agg}->{$id}->{aggrName}' $short_msg"
);
}
if ($multiple == 0) {
$self->{output}->output_add(short_msg => "Aggregate '$self->{agg}->{$id}->{aggrName}' Usage $long_msg");
}
}
$self->{output}->display();
$self->{output}->exit();
}
sub get_severity { sub get_severity {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -236,28 +160,30 @@ sub manage_selection {
my $oid_aggrName = '.1.3.6.1.4.1.789.1.5.11.1.2'; my $oid_aggrName = '.1.3.6.1.4.1.789.1.5.11.1.2';
my $oid_aggrState = '.1.3.6.1.4.1.789.1.5.11.1.5'; my $oid_aggrState = '.1.3.6.1.4.1.789.1.5.11.1.5';
my $oid_aggrStatus = '.1.3.6.1.4.1.789.1.5.11.1.6'; my $oid_aggrStatus = '.1.3.6.1.4.1.789.1.5.11.1.6';
$self->{results} = $self->{snmp}->get_multiple_table(oids => [ my $snmp_result = $options{snmp}->get_multiple_table(
{ oid => $oid_aggrName }, oids => [
{ oid => $oid_aggrState }, { oid => $oid_aggrName },
{ oid => $oid_aggrStatus }, { oid => $oid_aggrState },
], { oid => $oid_aggrStatus },
, nothing_quit => 1); ],
nothing_quit => 1
);
$self->{agg} = {}; $self->{agg} = {};
foreach my $oid (keys %{$self->{results}->{$oid_aggrState}}) { foreach my $oid (keys %{$snmp_result->{$oid_aggrState}}) {
next if ($oid !~ /^$oid_aggrState\.(.*)$/); next if ($oid !~ /^$oid_aggrState\.(.*)$/);
my $instance = $1; my $instance = $1;
my $name = $self->{results}->{$oid_aggrName}->{$oid_aggrName . '.' . $instance}; my $name = $snmp_result->{$oid_aggrName}->{$oid_aggrName . '.' . $instance};
my $state = $self->{results}->{$oid_aggrState}->{$oid_aggrState . '.' . $instance}; my $state = $snmp_result->{$oid_aggrState}->{$oid_aggrState . '.' . $instance};
my $status = $self->{results}->{$oid_aggrStatus}->{$oid_aggrStatus . '.' . $instance}; my $status = $snmp_result->{$oid_aggrStatus}->{$oid_aggrStatus . '.' . $instance};
if (!defined($state) || $state eq '') { if (!defined($state) || $state eq '') {
$self->{output}->output_add(long_msg => "Skipping '" . $name . "': state value not set."); $self->{output}->output_add(long_msg => "skipping '" . $name . "': state value not set.");
next; next;
} }
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) { $name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter name."); $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.");
next; next;
} }

View File

@ -20,114 +20,122 @@
package storage::netapp::snmp::mode::cpstatistics; package storage::netapp::snmp::mode::cpstatistics;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex);
use centreon::plugins::values;
my $maps_counters = { sub set_counters {
timer => { class => 'centreon::plugins::values', obj => undef, my ($self, %options) = @_;
set => {
key_values => [ { name => 'timer', diff => 1 }, ], $self->{maps_counters_type} = [
output_template => 'CP timer : %s', { name => 'global', type => 0, skipped_code => { -10 => 1, -11 => 1 } }
perfdatas => [ ];
{ value => 'timer_absolute', template => '%d', min => 0 },
], $self->{maps_counters}->{global} = [
} { label => 'timer', nlabel => 'storage.cp.timer.operations.count', display_ok => 0, set => {
}, key_values => [ { name => 'timer', diff => 1 }, ],
snapshot => { class => 'centreon::plugins::values', obj => undef, output_template => 'CP timer : %s',
set => { perfdatas => [
key_values => [ { name => 'snapshot', diff => 1 }, ], { value => 'timer_absolute', template => '%d', min => 0 },
output_template => 'CP snapshot : %s', ],
perfdatas => [ }
{ value => 'snapshot_absolute', template => '%d', min => 0 }, },
], { label => 'snapshot', nlabel => 'storage.cp.snapshot.operations.count', display_ok => 0, set => {
} key_values => [ { name => 'snapshot', diff => 1 }, ],
}, output_template => 'CP snapshot : %s',
lowerwater => { class => 'centreon::plugins::values', obj => undef, perfdatas => [
set => { { value => 'snapshot_absolute', template => '%d', min => 0 },
key_values => [ { name => 'lowerwater', diff => 1 }, ], ],
output_template => 'CP low water mark : %s', }
perfdatas => [ },
{ value => 'lowerwater_absolute', template => '%d', min => 0 }, { label => 'lowerwater', nlabel => 'storage.cp.lowerwatermark.operations.count', display_ok => 0, set => {
], key_values => [ { name => 'lowerwater', diff => 1 }, ],
} output_template => 'CP low water mark : %s',
}, perfdatas => [
highwater => { class => 'centreon::plugins::values', obj => undef, { value => 'lowerwater_absolute', template => '%d', min => 0 },
set => { ],
key_values => [ { name => 'highwater', diff => 1 }, ], }
output_template => 'CP high water mark : %s', },
perfdatas => [ { label => 'highwater', nlabel => 'storage.cp.highwatermark.operations.count', display_ok => 0, set => {
{ value => 'highwater_absolute', template => '%d', min => 0 }, key_values => [ { name => 'highwater', diff => 1 }, ],
], output_template => 'CP high water mark : %s',
} perfdatas => [
}, { value => 'highwater_absolute', template => '%d', min => 0 },
logfull => { class => 'centreon::plugins::values', obj => undef, ],
set => { }
key_values => [ { name => 'logfull', diff => 1 }, ], },
output_template => 'CP nv-log full : %s', { label => 'logfull', nlabel => 'storage.cp.logfull.operations.count', display_ok => 0, set => {
perfdatas => [ key_values => [ { name => 'logfull', diff => 1 }, ],
{ value => 'logfull_absolute', template => '%d', min => 0 }, output_template => 'CP nv-log full : %s',
], perfdatas => [
} { value => 'logfull_absolute', template => '%d', min => 0 },
}, ],
back => { class => 'centreon::plugins::values', obj => undef, }
set => { },
key_values => [ { name => 'back', diff => 1 }, ], { label => 'back', nlabel => 'storage.cp.back2back.operations.count', display_ok => 0, set => {
output_template => 'CP back-to-back : %s', key_values => [ { name => 'back', diff => 1 }, ],
perfdatas => [ output_template => 'CP back-to-back : %s',
{ value => 'back_absolute', template => '%d', min => 0 }, perfdatas => [
], { value => 'back_absolute', template => '%d', min => 0 },
} ],
}, }
flush => { class => 'centreon::plugins::values', obj => undef, },
set => { { label => 'flush', nlabel => 'storage.cp.flushunlog.operations.count', display_ok => 0, set => {
key_values => [ { name => 'flush', diff => 1 }, ], key_values => [ { name => 'flush', diff => 1 }, ],
output_template => 'CP flush unlogged write data : %s', output_template => 'CP flush unlogged write data : %s',
perfdatas => [ perfdatas => [
{ value => 'flush_absolute', template => '%d', min => 0 }, { value => 'flush_absolute', template => '%d', min => 0 },
], ],
} }
}, },
sync => { class => 'centreon::plugins::values', obj => undef, { label => 'sync', nlabel => 'storage.cp.syncrequests.operations.count', display_ok => 0, set => {
set => { key_values => [ { name => 'sync', diff => 1 }, ],
key_values => [ { name => 'sync', diff => 1 }, ], output_template => 'CP sync requests : %s',
output_template => 'CP sync requests : %s', perfdatas => [
perfdatas => [ { value => 'sync_absolute', template => '%d', min => 0 },
{ value => 'sync_absolute', template => '%d', min => 0 }, ],
], }
} },
}, { label => 'lowvbuf', nlabel => 'storage.cp.lowvirtualbuffers.operations.count', display_ok => 0, set => {
lowvbuf => { class => 'centreon::plugins::values', obj => undef, key_values => [ { name => 'lowvbuf', diff => 1 }, ],
set => { output_template => 'CP low virtual buffers : %s',
key_values => [ { name => 'lowvbuf', diff => 1 }, ], perfdatas => [
output_template => 'CP low virtual buffers : %s', { value => 'lowvbuf_absolute', template => '%d', min => 0 },
perfdatas => [ ],
{ value => 'lowvbuf_absolute', template => '%d', min => 0 }, }
], },
} { label => 'deferred', nlabel => 'storage.cp.deferred.operations.count', display_ok => 0, set => {
}, key_values => [ { name => 'deferred', diff => 1 }, ],
deferred => { class => 'centreon::plugins::values', obj => undef, output_template => 'CP deferred : %s',
set => { perfdatas => [
key_values => [ { name => 'deferred', diff => 1 }, ], { value => 'deferred_absolute', template => '%d', min => 0 },
output_template => 'CP deferred : %s', ],
perfdatas => [ }
{ value => 'deferred_absolute', template => '%d', min => 0 }, },
], { label => 'lowdatavecs', nlabel => 'storage.cp.lowdatavecs.operations.count', display_ok => 0, set => {
} key_values => [ { name => 'lowdatavecs', diff => 1 }, ],
}, output_template => 'CP low datavecs : %s',
lowdatavecs => { class => 'centreon::plugins::values', obj => undef, perfdatas => [
set => { { value => 'lowdatavecs_absolute', template => '%d', min => 0 },
key_values => [ { name => 'lowdatavecs', diff => 1 }, ], ],
output_template => 'CP low datavecs : %s', }
perfdatas => [ },
{ value => 'lowdatavecs_absolute', template => '%d', min => 0 }, ];
], }
}
}, sub new {
}; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
});
return $self;
}
my $oid_cpFromTimerOps = '.1.3.6.1.4.1.789.1.2.6.2.0'; my $oid_cpFromTimerOps = '.1.3.6.1.4.1.789.1.2.6.2.0';
my $oid_cpFromSnapshotOps = '.1.3.6.1.4.1.789.1.2.6.3.0'; my $oid_cpFromSnapshotOps = '.1.3.6.1.4.1.789.1.2.6.3.0';
@ -142,122 +150,40 @@ my $oid_cpFromLowVbufOps = '.1.3.6.1.4.1.789.1.2.6.11.0';
my $oid_cpFromCpDeferredOps = '.1.3.6.1.4.1.789.1.2.6.12.0'; my $oid_cpFromCpDeferredOps = '.1.3.6.1.4.1.789.1.2.6.12.0';
my $oid_cpFromLowDatavecsOps = '.1.3.6.1.4.1.789.1.2.6.13.0'; my $oid_cpFromLowDatavecsOps = '.1.3.6.1.4.1.789.1.2.6.13.0';
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 =>
{
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$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});
}
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "cache_netapp_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
$self->{output}->output_add(severity => 'OK',
short_msg => 'All CP statistics are ok');
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},
new_datas => $self->{new_datas});
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 = ', ';
}
$self->{output}->output_add(long_msg => $output);
$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"
);
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $request = [
$oid_cpFromTimerOps, $oid_cpFromSnapshotOps,
$oid_cpFromLowWaterOps, $oid_cpFromHighWaterOps,
$oid_cpFromLogFullOps, $oid_cpFromCpOps,
$oid_cpTotalOps, $oid_cpFromFlushOps,
$oid_cpFromSyncOps, $oid_cpFromLowVbufOps,
$oid_cpFromCpDeferredOps, $oid_cpFromLowDatavecsOps
];
my $request = [$oid_cpFromTimerOps, $oid_cpFromSnapshotOps, my $snmp_result = $options{snmp}->get_leef(oids => $request, nothing_quit => 1);
$oid_cpFromLowWaterOps, $oid_cpFromHighWaterOps,
$oid_cpFromLogFullOps, $oid_cpFromCpOps, $self->{output}->output_add(
$oid_cpTotalOps, $oid_cpFromFlushOps, severity => 'OK',
$oid_cpFromSyncOps, $oid_cpFromLowVbufOps, short_msg => 'All CP statistics are ok'
$oid_cpFromCpDeferredOps, $oid_cpFromLowDatavecsOps]; );
$self->{results} = $self->{snmp}->get_leef(oids => $request, nothing_quit => 1);
$self->{global} = {}; $self->{global} = {};
$self->{global}->{timer} = defined($self->{results}->{$oid_cpFromTimerOps}) ? $self->{results}->{$oid_cpFromTimerOps} : 0; $self->{global}->{timer} = defined($snmp_result->{$oid_cpFromTimerOps}) ? $snmp_result->{$oid_cpFromTimerOps} : undef;
$self->{global}->{snapshot} = defined($self->{results}->{$oid_cpFromSnapshotOps}) ? $self->{results}->{$oid_cpFromSnapshotOps} : 0; $self->{global}->{snapshot} = defined($snmp_result->{$oid_cpFromSnapshotOps}) ? $snmp_result->{$oid_cpFromSnapshotOps} : undef;
$self->{global}->{lowerwater} = defined($self->{results}->{$oid_cpFromLowWaterOps}) ? $self->{results}->{$oid_cpFromLowWaterOps} : 0; $self->{global}->{lowerwater} = defined($snmp_result->{$oid_cpFromLowWaterOps}) ? $snmp_result->{$oid_cpFromLowWaterOps} : undef;
$self->{global}->{highwater} = defined($self->{results}->{$oid_cpFromHighWaterOps}) ? $self->{results}->{$oid_cpFromHighWaterOps} : 0; $self->{global}->{highwater} = defined($snmp_result->{$oid_cpFromHighWaterOps}) ? $snmp_result->{$oid_cpFromHighWaterOps} : undef;
$self->{global}->{logfull} = defined($self->{results}->{$oid_cpFromLogFullOps}) ? $self->{results}->{$oid_cpFromLogFullOps} : 0; $self->{global}->{logfull} = defined($snmp_result->{$oid_cpFromLogFullOps}) ? $snmp_result->{$oid_cpFromLogFullOps} : undef;
$self->{global}->{back} = defined($self->{results}->{$oid_cpFromCpOps}) ? $self->{results}->{$oid_cpFromCpOps} : 0; $self->{global}->{back} = defined($snmp_result->{$oid_cpFromCpOps}) ? $snmp_result->{$oid_cpFromCpOps} : undef;
$self->{global}->{flush} = defined($self->{results}->{$oid_cpFromFlushOps}) ? $self->{results}->{$oid_cpFromFlushOps} : 0; $self->{global}->{flush} = defined($snmp_result->{$oid_cpFromFlushOps}) ? $snmp_result->{$oid_cpFromFlushOps} : undef;
$self->{global}->{sync} = defined($self->{results}->{$oid_cpFromSyncOps}) ? $self->{results}->{$oid_cpFromSyncOps} : 0; $self->{global}->{sync} = defined($snmp_result->{$oid_cpFromSyncOps}) ? $snmp_result->{$oid_cpFromSyncOps} : undef;
$self->{global}->{lowvbuf} = defined($self->{results}->{$oid_cpFromLowVbufOps}) ? $self->{results}->{$oid_cpFromLowVbufOps} : 0; $self->{global}->{lowvbuf} = defined($snmp_result->{$oid_cpFromLowVbufOps}) ? $snmp_result->{$oid_cpFromLowVbufOps} : undef;
$self->{global}->{deferred} = defined($self->{results}->{$oid_cpFromCpDeferredOps}) ? $self->{results}->{$oid_cpFromCpDeferredOps} : 0; $self->{global}->{deferred} = defined($snmp_result->{$oid_cpFromCpDeferredOps}) ? $snmp_result->{$oid_cpFromCpDeferredOps} : undef;
$self->{global}->{lowdatavecs} = defined($self->{results}->{$oid_cpFromLowDatavecsOps}) ? $self->{results}->{$oid_cpFromLowDatavecsOps} : 0; $self->{global}->{lowdatavecs} = defined($snmp_result->{$oid_cpFromLowDatavecsOps}) ? $snmp_result->{$oid_cpFromLowDatavecsOps} : undef;
$self->{cache_name} = "cache_netapp_" . $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; 1;
@ -285,4 +211,4 @@ Can be: 'timer', 'snapshot', 'lowerwater', 'highwater',
=back =back
=cut =cut

View File

@ -20,43 +20,56 @@
package storage::netapp::snmp::mode::globalstatus; package storage::netapp::snmp::mode::globalstatus;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex);
use centreon::plugins::values;
my $maps_counters = { sub set_counters {
read => { class => 'centreon::plugins::values', obj => undef, my ($self, %options) = @_;
set => {
key_values => [ $self->{maps_counters_type} = [
{ name => 'read', diff => 1 }, { name => 'global', type => 0, skipped_code => { -10 => 1 } }
], ];
per_second => 1,
output_template => 'Read I/O : %s %s/s', $self->{maps_counters}->{global} = [
output_change_bytes => 1, { label => 'read', nlabel => 'storage.io.read.usage.bytespersecond', set => {
perfdatas => [ key_values => [ { name => 'read', diff => 1 } ],
{ value => 'read_per_second', template => '%d', per_second => 1,
unit => 'B/s', min => 0 }, output_template => 'Read I/O : %s %s/s',
], output_change_bytes => 1,
} perfdatas => [
}, { value => 'read_per_second', template => '%d',
write => { class => 'centreon::plugins::values', obj => undef, unit => 'B/s', min => 0 },
set => { ],
key_values => [ }
{ name => 'write', diff => 1 }, },
], { label => 'write', nlabel => 'storage.io.write.usage.bytespersecond', set => {
per_second => 1, key_values => [ { name => 'write', diff => 1 } ],
output_template => 'Write I/O : %s %s/s', per_second => 1,
output_change_bytes => 1, output_template => 'Write I/O : %s %s/s',
perfdatas => [ output_change_bytes => 1,
{ value => 'write_per_second', template => '%d', perfdatas => [
unit => 'B/s', min => 0 }, { value => 'write_per_second', template => '%d',
], unit => 'B/s', min => 0 },
} ],
}, }
}; },
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
});
return $self;
}
my %states = ( my %states = (
1 => ['other', 'WARNING'], 1 => ['other', 'WARNING'],
@ -83,126 +96,40 @@ my $oid_miscLowDiskReadBytes = '.1.3.6.1.4.1.789.1.2.2.16.0';
my $oid_miscHighDiskWriteBytes = '.1.3.6.1.4.1.789.1.2.2.17.0'; my $oid_miscHighDiskWriteBytes = '.1.3.6.1.4.1.789.1.2.2.17.0';
my $oid_miscLowDiskWriteBytes = '.1.3.6.1.4.1.789.1.2.2.18.0'; my $oid_miscLowDiskWriteBytes = '.1.3.6.1.4.1.789.1.2.2.18.0';
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 =>
{
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$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});
}
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
$self->manage_selection();
$self->{results}->{$oid_miscGlobalStatusMessage} =~ s/\n//g;
$self->{output}->output_add(severity => ${$states{$self->{results}->{$oid_miscGlobalStatus}}}[1],
short_msg => sprintf("Overall global status is '%s' [message: '%s']",
${$states{$self->{results}->{$oid_miscGlobalStatus}}}[0], $self->{results}->{$oid_miscGlobalStatusMessage}));
$self->{results}->{$oid_fsStatusMessage} =~ s/\n//g;
$self->{output}->output_add(severity => ${$fs_states{$self->{results}->{$oid_fsOverallStatus}}}[1],
short_msg => sprintf("Overall file system status is '%s' [message: '%s']",
${$fs_states{$self->{results}->{$oid_fsOverallStatus}}}[0], $self->{results}->{$oid_fsStatusMessage}));
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "cache_netapp_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
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},
new_datas => $self->{new_datas});
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->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $request = [$oid_fsOverallStatus, $oid_fsStatusMessage, my $request = [
$oid_miscGlobalStatus, $oid_miscGlobalStatusMessage, $oid_fsOverallStatus, $oid_fsStatusMessage,
$oid_miscHighDiskReadBytes, $oid_miscLowDiskReadBytes, $oid_miscGlobalStatus, $oid_miscGlobalStatusMessage,
$oid_miscHighDiskWriteBytes, $oid_miscLowDiskWriteBytes]; $oid_miscHighDiskReadBytes, $oid_miscLowDiskReadBytes,
if (!$self->{snmp}->is_snmpv1()) { $oid_miscHighDiskWriteBytes, $oid_miscLowDiskWriteBytes
];
if (!$options{snmp}->is_snmpv1()) {
push @{$request}, ($oid_misc64DiskReadBytes, $oid_misc64DiskWriteBytes); push @{$request}, ($oid_misc64DiskReadBytes, $oid_misc64DiskWriteBytes);
} }
$self->{results} = $self->{snmp}->get_leef(oids => $request, nothing_quit => 1); my $snmp_result = $options{snmp}->get_leef(oids => $request, nothing_quit => 1);
$self->{global} = {}; $self->{global} = {};
$self->{global}->{read} = defined($self->{results}->{$oid_misc64DiskReadBytes}) ? $self->{global}->{read} = defined($snmp_result->{$oid_misc64DiskReadBytes}) ?
$self->{results}->{$oid_misc64DiskReadBytes} : $snmp_result->{$oid_misc64DiskReadBytes} :
($self->{results}->{$oid_miscHighDiskReadBytes} << 32) + $self->{results}->{$oid_miscLowDiskReadBytes}; ($snmp_result->{$oid_miscHighDiskReadBytes} << 32) + $snmp_result->{$oid_miscLowDiskReadBytes};
$self->{global}->{write} = defined($self->{results}->{$oid_misc64DiskWriteBytes}) ? $self->{global}->{write} = defined($snmp_result->{$oid_misc64DiskWriteBytes}) ?
$self->{results}->{$oid_misc64DiskWriteBytes} : $snmp_result->{$oid_misc64DiskWriteBytes} :
($self->{results}->{$oid_miscHighDiskWriteBytes} << 32) + $self->{results}->{$oid_miscLowDiskWriteBytes}; ($snmp_result->{$oid_miscHighDiskWriteBytes} << 32) + $snmp_result->{$oid_miscLowDiskWriteBytes};
$snmp_result->{$oid_miscGlobalStatusMessage} =~ s/\n//g;
$self->{output}->output_add(severity => ${$states{$snmp_result->{$oid_miscGlobalStatus}}}[1],
short_msg => sprintf("Overall global status is '%s' [message: '%s']",
${$states{$snmp_result->{$oid_miscGlobalStatus}}}[0], $snmp_result->{$oid_miscGlobalStatusMessage}));
$snmp_result->{$oid_fsStatusMessage} =~ s/\n//g;
$self->{output}->output_add(severity => ${$fs_states{$snmp_result->{$oid_fsOverallStatus}}}[1],
short_msg => sprintf("Overall file system status is '%s' [message: '%s']",
${$fs_states{$snmp_result->{$oid_fsOverallStatus}}}[0], $snmp_result->{$oid_fsStatusMessage}));
$self->{cache_name} = "cache_netapp_" . $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; 1;
@ -229,4 +156,4 @@ Can be: 'read', 'write'.
=back =back
=cut =cut

View File

@ -20,35 +20,52 @@
package storage::netapp::snmp::mode::sharecalls; package storage::netapp::snmp::mode::sharecalls;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex);
use centreon::plugins::values;
my $maps_counters = { sub set_counters {
cifs => { class => 'centreon::plugins::values', obj => undef, my ($self, %options) = @_;
set => {
key_values => [ { name => 'cifs', diff => 1 }, ], $self->{maps_counters_type} = [
per_second => 1, { name => 'global', type => 0, skipped_code => { -10 => 1 } }
output_template => 'CIFS : %s calls/s', ];
perfdatas => [
{ value => 'cifs_per_second', template => '%d', min => 0 }, $self->{maps_counters}->{global} = [
], { label => 'cifs', nlabel => 'storage.cifs.calls.persecond', set => {
} key_values => [ { name => 'cifs', diff => 1 }, ],
}, per_second => 1,
nfs => { class => 'centreon::plugins::values', obj => undef, output_template => 'CIFS : %s calls/s',
set => { perfdatas => [
key_values => [ { name => 'nfs', diff => 1 }, ], { value => 'cifs_per_second', template => '%d', min => 0 },
per_second => 1, ],
output_template => 'NFS : %s calls/s', }
perfdatas => [ },
{ value => 'nfs_per_second', template => '%d', min => 0 }, { label => 'nfs', nlabel => 'storage.nfs.calls.persecond', set => {
], key_values => [ { name => 'nfs', diff => 1 }, ],
} per_second => 1,
}, output_template => 'NFS : %s calls/s',
}; perfdatas => [
{ value => 'nfs_per_second', template => '%d', min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
});
return $self;
}
my $oid_miscHighNfsOps = '.1.3.6.1.4.1.789.1.2.2.5.0'; my $oid_miscHighNfsOps = '.1.3.6.1.4.1.789.1.2.2.5.0';
my $oid_miscLowNfsOps = '.1.3.6.1.4.1.789.1.2.2.6.0'; my $oid_miscLowNfsOps = '.1.3.6.1.4.1.789.1.2.2.6.0';
@ -57,114 +74,29 @@ my $oid_miscLowCifsOps = '.1.3.6.1.4.1.789.1.2.2.8.0';
my $oid_misc64NfsOps = '.1.3.6.1.4.1.789.1.2.2.27.0'; my $oid_misc64NfsOps = '.1.3.6.1.4.1.789.1.2.2.27.0';
my $oid_misc64CifsOps = '.1.3.6.1.4.1.789.1.2.2.28.0'; my $oid_misc64CifsOps = '.1.3.6.1.4.1.789.1.2.2.28.0';
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 =>
{
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$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});
}
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "cache_netapp_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
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},
new_datas => $self->{new_datas});
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->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $request = [$oid_miscHighNfsOps, $oid_miscLowNfsOps, my $request = [
$oid_miscHighCifsOps, $oid_miscLowCifsOps]; $oid_miscHighNfsOps, $oid_miscLowNfsOps,
if (!$self->{snmp}->is_snmpv1()) { $oid_miscHighCifsOps, $oid_miscLowCifsOps
];
if (!$options{snmp}->is_snmpv1()) {
push @{$request}, ($oid_misc64NfsOps, $oid_misc64CifsOps); push @{$request}, ($oid_misc64NfsOps, $oid_misc64CifsOps);
} }
$self->{results} = $self->{snmp}->get_leef(oids => $request, nothing_quit => 1); my $snmp_result = $options{snmp}->get_leef(oids => $request, nothing_quit => 1);
$self->{global} = {}; $self->{global} = {};
$self->{global}->{cifs} = defined($self->{results}->{$oid_misc64CifsOps}) ? $self->{global}->{cifs} = defined($snmp_result->{$oid_misc64CifsOps}) ?
$self->{results}->{$oid_misc64CifsOps} : $snmp_result->{$oid_misc64CifsOps} :
($self->{results}->{$oid_miscHighCifsOps} << 32) + $self->{results}->{$oid_miscLowCifsOps}; ($snmp_result->{$oid_miscHighCifsOps} << 32) + $snmp_result->{$oid_miscLowCifsOps};
$self->{global}->{nfs} = defined($self->{results}->{$oid_misc64NfsOps}) ? $self->{global}->{nfs} = defined($snmp_result->{$oid_misc64NfsOps}) ?
$self->{results}->{$oid_misc64NfsOps} : $snmp_result->{$oid_misc64NfsOps} :
($self->{results}->{$oid_miscHighNfsOps} << 32) + $self->{results}->{$oid_miscLowNfsOps}; ($snmp_result->{$oid_miscHighNfsOps} << 32) + $snmp_result->{$oid_miscLowNfsOps};
$self->{cache_name} = "cache_netapp_" . $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; 1;
@ -191,4 +123,4 @@ Can be: 'cifs', 'nfs'.
=back =back
=cut =cut