update hp p2000 with counter class

This commit is contained in:
garnier-quentin 2019-04-18 15:32:38 +02:00
parent f0a3790cad
commit a86e339af3
4 changed files with 116 additions and 207 deletions

View File

@ -184,12 +184,13 @@ sub DESTROY {
sub get_infos { sub get_infos {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($xpath, $nodeset); my ($xpath, $nodeset);
$self->login();
my $cmd = $options{cmd}; my $cmd = $options{cmd};
$cmd =~ s/ /\//g; $cmd =~ s/ /\//g;
my $response =$self->{http}->request(url_path => $self->{url_path} . $cmd, my $response = $self->{http}->request(url_path => $self->{url_path} . $cmd,
header => ['Cookie: wbisessionkey=' . $self->{session_id} . '; wbiusername=' . $self->{username}, header => ['Cookie: wbisessionkey=' . $self->{session_id} . '; wbiusername=' . $self->{username},
'dataType: api', 'sessionKey: '. $self->{session_id}]); 'dataType: api', 'sessionKey: '. $self->{session_id}]);
eval { eval {
$xpath = XML::XPath->new(xml => $response); $xpath = XML::XPath->new(xml => $response);
@ -247,7 +248,9 @@ sub get_infos {
############## ##############
sub login { sub login {
my ($self, %options) = @_; my ($self, %options) = @_;
return if ($self->{logon} == 1);
$self->build_options_for_httplib(); $self->build_options_for_httplib();
$self->{http}->set_options(%{$self->{option_results}}); $self->{http}->set_options(%{$self->{option_results}});

View File

@ -36,12 +36,11 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ "exclude:s" => { name => 'exclude' },
"exclude:s" => { name => 'exclude' }, "component:s" => { name => 'component', default => 'all' },
"component:s" => { name => 'component', default => 'all' }, "no-component:s" => { name => 'no_component' },
"no-component:s" => { name => 'no_component' }, });
});
$self->{components} = {}; $self->{components} = {};
$self->{no_components} = undef; $self->{no_components} = undef;
@ -163,4 +162,4 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=back =back
=cut =cut

View File

@ -31,12 +31,12 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ "name:s" => { name => 'name' },
"name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' },
"regexp" => { name => 'use_regexp' }, "filter-type:s" => { name => 'filter_type' },
"filter-type:s" => { name => 'filter_type' }, });
});
$self->{volume_name_selected} = []; $self->{volume_name_selected} = [];
return $self; return $self;
@ -146,4 +146,4 @@ Available types are:
=back =back
=cut =cut

View File

@ -20,85 +20,11 @@
package storage::hp::p2000::xmlapi::mode::volumesstats; package storage::hp::p2000::xmlapi::mode::volumesstats;
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 = {
read => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'data-read-numeric', diff => 1 },
],
per_second => 1,
output_template => 'Read I/O : %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ value => 'data-read-numeric_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1 },
],
}
},
write => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'data-written-numeric', diff => 1 },
],
per_second => 1,
output_template => 'Write I/O : %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ value => 'data-written-numeric_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1 },
],
}
},
'write-cache-hits' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'write-cache-hits', diff => 1 },
{ name => 'write-cache-misses', diff => 1 },
],
closure_custom_calc => \&custom_write_cache_calc,
output_template => 'Write Cache Hits : %.2f %%',
output_use => 'write-cache-hits_prct', threshold_use => 'write-cache-hits_prct',
perfdatas => [
{ value => 'write-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 },
],
}
},
'read-cache-hits' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'read-cache-hits', diff => 1 },
{ name => 'read-cache-misses', diff => 1 },
],
closure_custom_calc => \&custom_read_cache_calc,
output_template => 'Read Cache Hits : %.2f %%',
output_use => 'read-cache-hits_prct', threshold_use => 'read-cache-hits_prct',
perfdatas => [
{ value => 'read-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 },
],
}
},
iops => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'iops' },
],
output_template => 'IOPs : %s',
perfdatas => [
{ value => 'iops_absolute',
unit => 'iops', min => 0, label_extra_instance => 1 },
],
}
},
};
sub custom_write_cache_calc { sub custom_write_cache_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -130,141 +56,122 @@ sub custom_read_cache_calc {
return 0; return 0;
} }
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes statistics are ok', skipped_code => { -2 => 1, -10 => 1 } },
];
$self->{maps_counters}->{volume} = [
{ label => 'read', nlabel => 'volume.io.read.usage.bytespersecond', set => {
key_values => [ { name => 'data-read-numeric', diff => 1 } ],
per_second => 1,
output_template => 'Read I/O : %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ value => 'data-read-numeric_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1 },
],
}
},
{ label => 'write', nlabel => 'volume.io.write.usage.bytespersecond', set => {
key_values => [ { name => 'data-written-numeric', diff => 1 } ],
per_second => 1,
output_template => 'Write I/O : %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ value => 'data-written-numeric_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1 },
],
}
},
{ label => 'read-cache-hits', nlabel => 'volume.cache.read.hits.percentage', set => {
key_values => [ { name => 'read-cache-hits', diff => 1 }, { name => 'read-cache-misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_read_cache_calc'),
output_template => 'Read Cache Hits : %.2f %%',
output_use => 'read-cache-hits_prct', threshold_use => 'read-cache-hits_prct',
perfdatas => [
{ value => 'read-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 },
],
}
},
{ label => 'write-cache-hits', nlabel => 'volume.cache.write.hits.percentage', set => {
key_values => [ { name => 'write-cache-hits', diff => 1 }, { name => 'write-cache-misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_write_cache_calc'),
output_template => 'Write Cache Hits : %.2f %%',
output_use => 'write-cache-hits_prct', threshold_use => 'write-cache-hits_prct',
perfdatas => [
{ value => 'write-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 },
],
}
},
{ label => 'iops', nlabel => 'volume.io.usage.iops', set => {
key_values => [ { name => 'iops' } ],
output_template => 'IOPs : %s',
perfdatas => [
{ value => 'iops_absolute',
unit => 'iops', min => 0, label_extra_instance => 1 },
],
}
},
];
}
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 => {
{ "name:s" => { name => 'name' },
"name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' },
"regexp" => { name => 'use_regexp' }, });
});
$self->{volume_name_selected} = [];
$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; return $self;
} }
sub check_options { sub prefix_volume_output {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) { return "Volume '" . $options{instance_value}->{display} . "' ";
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
$self->{statefile_value}->check_options(%options);
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{results} = $self->{p2000}->get_infos(cmd => 'show volume-statistics', my $result = $options{custom}->get_infos(
base_type => 'volume-statistics', cmd => 'show volume-statistics',
key => 'volume-name', base_type => 'volume-statistics',
properties_name => '^data-read-numeric|data-written-numeric|write-cache-hits|write-cache-misses|read-cache-hits|read-cache-misses|iops$'); key => 'volume-name',
foreach my $name (sort keys %{$self->{results}}) { properties_name => '^data-read-numeric|data-written-numeric|write-cache-hits|write-cache-misses|read-cache-hits|read-cache-misses|iops$'
# Get all without a name );
if (!defined($self->{option_results}->{name})) {
push @{$self->{volume_name_selected}}, $name;
next;
}
if (!defined($self->{option_results}->{use_regexp}) && $name eq $self->{option_results}->{name}) {
push @{$self->{volume_name_selected}}, $name;
next;
}
if (defined($self->{option_results}->{use_regexp}) && $name =~ /$self->{option_results}->{name}/) {
push @{$self->{volume_name_selected}}, $name;
next;
}
}
if (scalar(@{$self->{volume_name_selected}}) <= 0) { $self->{volume} = {};
$self->{output}->add_option_msg(short_msg => "No volume found for name '" . $self->{option_results}->{name} . "'."); foreach my $name (keys %$result) {
$self->{output}->option_exit(); if (defined($self->{option_results}->{name}) && $self->{option_results}->{name} ne '') {
} if ((!defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name}) |
} (defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/)
) {
sub run { $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching volume name.", debug => 1);
my ($self, %options) = @_;
$self->{p2000} = $options{custom};
$self->{p2000}->login();
$self->manage_selection();
my $multiple = 1;
if (scalar(@{$self->{volume_name_selected}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All volumes statistics are ok.');
}
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "cache_hp_p2000_" . $self->{p2000}->{hostname} . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
foreach my $name (sort @{$self->{volume_name_selected}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => $name);
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{results}->{$name},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next; 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(level => 1, extra_instance => $multiple);
}
$self->{output}->output_add(long_msg => "Volume '$name' $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 => "Volume '$name' $short_msg"
);
} }
if ($multiple == 0) { $self->{volume}->{$name} = { display => $name, %{$result->{$name}} };
$self->{output}->output_add(short_msg => "Volume '$name' $long_msg"); }
}
if (scalar(keys %{$self->{volume}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No volume found.");
$self->{output}->option_exit();
} }
$self->{statefile_value}->write(data => $self->{new_datas}); $self->{cache_name} = "hp_p2000_" . $options{custom}->{hostname} . '_' . $self->{mode} . '_' .
$self->{output}->display(); (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
$self->{output}->exit(); (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
} }
1; 1;