(plugin): virtualization-nutanix-snmp - Nutanix host discovery & metrics v2 (#3583)
* Nutanix discovery & metrics v2 * Nutanix discovery & metrics v2
This commit is contained in:
parent
54f482451e
commit
9c4acc9fa7
|
@ -25,10 +25,19 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
my $cluster_name = '';
|
||||
|
||||
sub prefix_cluster_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"Cluster '%s'",
|
||||
$cluster_name
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -46,10 +55,10 @@ sub custom_status_calc {
|
|||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $label = 'used';
|
||||
my ($label, $nlabel) = ('used', $self->{nlabel});
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
if (defined($self->{instance_mode}->{option_results}->{free})) {
|
||||
$label = 'free';
|
||||
($label, $nlabel) = ('free', 'cluster.storage.space.free.bytes');
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my %total_options = ();
|
||||
|
@ -60,9 +69,10 @@ sub custom_usage_perfdata {
|
|||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label, unit => 'B',
|
||||
nlabel => $nlabel,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
@ -77,7 +87,13 @@ sub custom_usage_threshold {
|
|||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(
|
||||
value => $threshold_value,
|
||||
threshold => [
|
||||
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -115,40 +131,44 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$self->{maps_counters}->{cluster} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
{
|
||||
label => 'status',
|
||||
type => 2,
|
||||
critical_default => '%{status} ne "started"',
|
||||
set => {
|
||||
key_values => [ { name => 'clusterStatus' } ],
|
||||
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 => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'usage', set => {
|
||||
{ label => 'usage', nlabel => 'cluster.storage.space.usage.bytes', set => {
|
||||
key_values => [ { name => 'clusterTotalStorageCapacity' }, { name => 'clusterUsedStorageCapacity' } ],
|
||||
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'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'avg-latency', set => {
|
||||
{ label => 'avg-latency', nlabel => 'cluster.average.io.latency.microseconds', set => {
|
||||
key_values => [ { name => 'clusterLatency' } ],
|
||||
output_template => 'Average Latency : %s µs',
|
||||
perfdatas => [
|
||||
{ label => 'avg_latency', value => 'clusterLatency', template => '%s', unit => 'µs',
|
||||
min => 0 },
|
||||
],
|
||||
min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'iops', set => {
|
||||
{ label => 'iops', nlabel => 'cluster.operations.iops', set => {
|
||||
key_values => [ { name => 'clusterIops' } ],
|
||||
output_template => 'IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'iops', value => 'clusterIops', template => '%s', unit => 'iops',
|
||||
min => 0 },
|
||||
],
|
||||
min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -158,10 +178,8 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '' },
|
||||
'units:s' => { name => 'units', default => '%' },
|
||||
'free' => { name => 'free' },
|
||||
'free' => { name => 'free' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -170,14 +188,6 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub prefix_cluster_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Cluster '" . $cluster_name . "' ";
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
|
@ -188,6 +198,7 @@ my $mapping = {
|
|||
clusterIops => { oid => '.1.3.6.1.4.1.41263.506' },
|
||||
clusterLatency => { oid => '.1.3.6.1.4.1.41263.507' },
|
||||
};
|
||||
|
||||
my $oid_nutanix = '.1.3.6.1.4.1.41263';
|
||||
|
||||
sub manage_selection {
|
||||
|
|
|
@ -26,13 +26,22 @@ use strict;
|
|||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub prefix_container_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"Container '%s'",
|
||||
$options{instance_value}->{display}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $label = 'used';
|
||||
my ($label, $nlabel) = ('used', $self->{nlabel});
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
if (defined($self->{instance_mode}->{option_results}->{free})) {
|
||||
$label = 'free';
|
||||
($label, $nlabel) = ('free', 'container.storage.space.free.bytes');
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my $extra_label = '';
|
||||
|
@ -45,9 +54,10 @@ sub custom_usage_perfdata {
|
|||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label . $extra_label, unit => 'B',
|
||||
nlabel => $nlabel,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
@ -62,7 +72,13 @@ sub custom_usage_threshold {
|
|||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(
|
||||
value => $threshold_value,
|
||||
threshold => [
|
||||
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -96,36 +112,36 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'container', type => 1, cb_prefix_output => 'prefix_container_output', message_multiple => 'All containers are ok', skipped_code => { -10 => 1 } },
|
||||
{ name => 'container', type => 1, cb_prefix_output => 'prefix_container_output', message_multiple => 'All containers are ok', skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{container} = [
|
||||
{ label => 'usage', set => {
|
||||
{ label => 'usage', nlabel => 'container.storage.space.usage.bytes', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'citUsedCapacity' }, { name => 'citTotalCapacity' } ],
|
||||
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'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'avg-latency', set => {
|
||||
{ label => 'avg-latency', nlabel => 'container.average.io.latency.microseconds', set => {
|
||||
key_values => [ { name => 'citAvgLatencyUsecs' }, { name => 'display' } ],
|
||||
output_template => 'Average Latency : %s µs',
|
||||
perfdatas => [
|
||||
{ label => 'avg_latency', value => 'citAvgLatencyUsecs', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'avg_latency', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'iops', set => {
|
||||
{ label => 'iops', nlabel => 'container.operations.iops', set => {
|
||||
key_values => [ { name => 'citIOPerSecond' }, { name => 'display' } ],
|
||||
output_template => 'IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'iops', value => 'citIOPerSecond', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'iops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -137,24 +153,18 @@ sub new {
|
|||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'units:s' => { name => 'units', default => '%' },
|
||||
'free' => { name => 'free' },
|
||||
'free' => { name => 'free' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub prefix_container_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Container '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
citContainerName => { oid => '.1.3.6.1.4.1.41263.8.1.3' },
|
||||
citTotalCapacity => { oid => '.1.3.6.1.4.1.41263.8.1.4' },
|
||||
citUsedCapacity => { oid => '.1.3.6.1.4.1.41263.8.1.5' },
|
||||
citIOPerSecond => { oid => '.1.3.6.1.4.1.41263.8.1.6' },
|
||||
citAvgLatencyUsecs => { oid => '.1.3.6.1.4.1.41263.8.1.7' },
|
||||
citAvgLatencyUsecs => { oid => '.1.3.6.1.4.1.41263.8.1.7' }
|
||||
};
|
||||
|
||||
my $oid_citEntry = '.1.3.6.1.4.1.41263.8.1';
|
||||
|
|
|
@ -0,0 +1,170 @@
|
|||
#
|
||||
# Copyright 2022 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 cloud::nutanix::snmp::mode::discovery;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use NetAddr::IP;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'discovery-type:s' => { name => 'discovery_type' },
|
||||
'prettify' => { name => 'prettify' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
citContainerName => { oid => '.1.3.6.1.4.1.41263.8.1.3' },
|
||||
hypervisorName => { oid => '.1.3.6.1.4.1.41263.9.1.3' },
|
||||
vmName => { oid => '.1.3.6.1.4.1.41263.10.1.3' },
|
||||
vmPowerState => { oid => '.1.3.6.1.4.1.41263.10.1.5' }
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
my @disco_data;
|
||||
my $disco_stats;
|
||||
|
||||
$disco_stats->{start_time} = time();
|
||||
|
||||
if (defined($self->{option_results}->{discovery_type}) && $self->{option_results}->{discovery_type} ne '') {
|
||||
if ($self->{option_results}->{discovery_type} eq 'container') {
|
||||
my $snmp_result = $self->{snmp}->get_table(oid => $mapping->{citContainerName}->{oid}, nothing_quit => 1);
|
||||
|
||||
foreach my $oid (keys %{$snmp_result}) {
|
||||
$snmp_result->{$oid} = centreon::plugins::misc::trim($snmp_result->{$oid});
|
||||
|
||||
my %host;
|
||||
$host{nutanix_hostname} = $self->{option_results}->{host};
|
||||
$host{container_name} = $snmp_result->{$oid};
|
||||
$host{snmp_version} = $self->{option_results}->{snmp_version};
|
||||
$host{snmp_community} = $self->{option_results}->{snmp_community};
|
||||
$host{snmp_port} = $self->{option_results}->{snmp_port};
|
||||
push @disco_data, \%host;
|
||||
}
|
||||
}
|
||||
|
||||
if ($self->{option_results}->{discovery_type} eq 'hypervisor') {
|
||||
my $snmp_result = $self->{snmp}->get_table(oid => $mapping->{hypervisorName}->{oid}, nothing_quit => 1);
|
||||
|
||||
foreach my $oid (keys %{$snmp_result}) {
|
||||
$snmp_result->{$oid} = centreon::plugins::misc::trim($snmp_result->{$oid});
|
||||
|
||||
my %host;
|
||||
$host{nutanix_hostname} = $self->{option_results}->{host};
|
||||
$host{hypervisor_name} = $snmp_result->{$oid};
|
||||
$host{snmp_version} = $self->{option_results}->{snmp_version};
|
||||
$host{snmp_community} = $self->{option_results}->{snmp_community};
|
||||
$host{snmp_port} = $self->{option_results}->{snmp_port};
|
||||
push @disco_data, \%host;
|
||||
}
|
||||
}
|
||||
|
||||
if ($self->{option_results}->{discovery_type} eq 'vm') {
|
||||
my $snmp_result = $self->{snmp}->get_multiple_table(
|
||||
oids => [
|
||||
{ oid => $mapping->{vmName}->{oid} },
|
||||
{ oid => $mapping->{vmPowerState}->{oid} },
|
||||
],
|
||||
return_type => 1,
|
||||
nothing_quit => 1
|
||||
);
|
||||
|
||||
foreach my $oid (keys %{$snmp_result}) {
|
||||
next if ($oid !~ /^$mapping->{vmPowerState}->{oid}\.(.*)$/);
|
||||
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
|
||||
$result->{vmName} = centreon::plugins::misc::trim($result->{vmName});
|
||||
$result->{vmPowerState} = centreon::plugins::misc::trim($result->{vmPowerState});
|
||||
|
||||
my %host;
|
||||
$host{nutanix_hostname} = $self->{option_results}->{host};
|
||||
$host{vm_name} = $result->{vmName};
|
||||
$host{vm_power_state} = $result->{vmPowerState};
|
||||
$host{snmp_version} = $self->{option_results}->{snmp_version};
|
||||
$host{snmp_community} = $self->{option_results}->{snmp_community};
|
||||
$host{snmp_port} = $self->{option_results}->{snmp_port};
|
||||
push @disco_data, \%host;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$disco_stats->{end_time} = time();
|
||||
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
||||
$disco_stats->{discovered_items} = @disco_data;
|
||||
$disco_stats->{results} = \@disco_data;
|
||||
|
||||
my $encoded_data;
|
||||
eval {
|
||||
if (defined($self->{option_results}->{prettify})) {
|
||||
$encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats);
|
||||
} else {
|
||||
$encoded_data = JSON::XS->new->utf8->encode($disco_stats);
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}';
|
||||
}
|
||||
|
||||
$self->{output}->output_add(short_msg => $encoded_data);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Nutanix resources discovery.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--prettify>
|
||||
|
||||
Prettify JSON output.
|
||||
|
||||
=item B<--discovery-type>
|
||||
|
||||
Resource types to discover.
|
||||
Can be: 'container', 'hypervisor', 'vm'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -25,12 +25,43 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub prefix_controllervm_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"ControllerVM '%s'",
|
||||
$options{instance_value}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub controllervm_long_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"checking ControllerVM '%s'",
|
||||
$options{instance_value}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_disk_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"Disk '%s'",
|
||||
$options{instance_value}->{display}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 'state : ' . $self->{result_values}->{state};
|
||||
return sprintf(
|
||||
"state: '%s'",
|
||||
$self->{result_values}->{state}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
|
@ -44,10 +75,10 @@ sub custom_status_calc {
|
|||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $label = 'used';
|
||||
my ($label, $nlabel) = ('used', $self->{nlabel});
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
if (defined($self->{instance_mode}->{option_results}->{free})) {
|
||||
$label = 'free';
|
||||
($label, $nlabel) = ('free', 'disk.storage.space.free.bytes');
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my $extra_label = '';
|
||||
|
@ -61,8 +92,10 @@ sub custom_usage_perfdata {
|
|||
$self->{output}->perfdata_add(
|
||||
label => $label . $extra_label, unit => 'B',
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
nlabel => $nlabel,
|
||||
instances => [ $self->{result_values}->{name}, $self->{result_values}->{display} ],
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
@ -77,7 +110,13 @@ sub custom_usage_threshold {
|
|||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(
|
||||
value => $threshold_value,
|
||||
threshold => [
|
||||
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -99,6 +138,7 @@ sub custom_usage_calc {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_dstNumTotalBytes'};
|
||||
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_dstNumFreeBytes'};
|
||||
$self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free};
|
||||
|
@ -111,53 +151,59 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disks are ok', skipped_code => { -10 => 1 } },
|
||||
{ name => 'controllervm', type => 3, cb_prefix_output => 'prefix_controllervm_output',
|
||||
cb_long_output => 'controllervm_long_output', indent_long_output => ' ',
|
||||
message_multiple => 'All ControllerVM disks are ok',
|
||||
group => [
|
||||
{ name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disks are ok', skipped_code => { -10 => 1 } }
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{disk} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
{ label => 'status', type => 2, set => {
|
||||
key_values => [ { name => 'dstState' }, { 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 => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'dstNumFreeBytes' }, { name => 'dstNumTotalBytes' } ],
|
||||
{ label => 'usage', nlabel => 'disk.storage.space.usage.bytes', set => {
|
||||
key_values => [ { name => 'name' }, { name => 'display' }, { name => 'dstNumFreeBytes' }, { name => 'dstNumTotalBytes' } ],
|
||||
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'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'inodes', set => {
|
||||
{ label => 'inodes', nlabel => 'disk.storage.inodes.usage.percentage', set => {
|
||||
key_values => [ { name => 'inodes_used' }, { name => 'display' } ],
|
||||
output_template => 'Inodes Used : %s %%',
|
||||
perfdatas => [
|
||||
{ label => 'inodes', value => 'inodes_used', template => '%s', unit => '%',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'inodes', template => '%s', unit => '%',
|
||||
min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'avg-latency', set => {
|
||||
key_values => [ { name => 'dstAverageLatency' }, { name => 'display' } ],
|
||||
{ label => 'avg-latency', nlabel => 'disk.average.io.latency.microseconds', set => {
|
||||
key_values => [ { name => 'dstAverageLatency' } ],
|
||||
output_template => 'Average Latency : %s µs',
|
||||
perfdatas => [
|
||||
{ label => 'avg_latency', value => 'dstAverageLatency', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'avg_latency', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'iops', set => {
|
||||
{ label => 'iops', nlabel => 'disk.operations.iops', set => {
|
||||
key_values => [ { name => 'dstNumberIops' }, { name => 'display' } ],
|
||||
output_template => 'IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'iops', value => 'dstNumberIops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'iops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -166,12 +212,11 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '' },
|
||||
'units:s' => { name => 'units', default => '%' },
|
||||
'free' => { name => 'free' },
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-controllervm:s' => { name => 'filter_controllervm' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'units:s' => { name => 'units', default => '%' },
|
||||
'free' => { name => 'free' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -180,30 +225,29 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub prefix_disk_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Disk '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
my %map_state = (1 => 'online', 2 => 'offline');
|
||||
|
||||
my $mapping = {
|
||||
my $disk_mapping = {
|
||||
dstDiskId => { oid => '.1.3.6.1.4.1.41263.3.1.2' },
|
||||
dstControllerVMId => { oid => '.1.3.6.1.4.1.41263.3.1.3' },
|
||||
dstNumTotalBytes => { oid => '.1.3.6.1.4.1.41263.3.1.6' },
|
||||
dstNumFreeBytes => { oid => '.1.3.6.1.4.1.41263.3.1.7' },
|
||||
dstNumTotalInodes => { oid => '.1.3.6.1.4.1.41263.3.1.8' },
|
||||
dstNumFreeInodes => { oid => '.1.3.6.1.4.1.41263.3.1.9' },
|
||||
dstAverageLatency => { oid => '.1.3.6.1.4.1.41263.3.1.10' },
|
||||
dstNumberIops => { oid => '.1.3.6.1.4.1.41263.3.1.12' },
|
||||
dstState => { oid => '.1.3.6.1.4.1.41263.3.1.13', map => \%map_state },
|
||||
dstState => { oid => '.1.3.6.1.4.1.41263.3.1.13', map => \%map_state }
|
||||
};
|
||||
|
||||
my $controllervm_mapping = {
|
||||
crtControllerVMId => { oid => '.1.3.6.1.4.1.41263.4.1.2' },
|
||||
crtName => { oid => '.1.3.6.1.4.1.41263.4.1.5' }
|
||||
};
|
||||
|
||||
my $oid_dstEntry = '.1.3.6.1.4.1.41263.3.1';
|
||||
my $oid_cstEntry = '.1.3.6.1.4.1.41263.4.1';
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -213,34 +257,79 @@ sub manage_selection {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{disk} = {};
|
||||
my $snmp_result = $options{snmp}->get_table(
|
||||
$self->{controllervm} = {};
|
||||
my $controllervm_snmp_result = $options{snmp}->get_table(
|
||||
oid => $oid_cstEntry,
|
||||
nothing_quit => 1
|
||||
);
|
||||
|
||||
my $controllervm_name_mapping = {};
|
||||
foreach my $oid (keys %{$controllervm_snmp_result}) {
|
||||
next if ($oid !~ /^$controllervm_mapping->{crtControllerVMId}->{oid}\.(.*)$/);
|
||||
my $controllervm_instance = $1;
|
||||
my $controllervm_result = $options{snmp}->map_instance(mapping => $controllervm_mapping, results => $controllervm_snmp_result, instance => $controllervm_instance);
|
||||
|
||||
if (defined($self->{option_results}->{filter_controllervm}) && $self->{option_results}->{filter_controllervm} ne '' &&
|
||||
$controllervm_result->{crtName} !~ /$self->{option_results}->{filter_controllervm}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $controllervm_result->{crtName} . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{controllervm}->{$controllervm_result->{crtName}} = {
|
||||
id => $controllervm_result->{crtControllerVMId},
|
||||
name => $controllervm_result->{crtName},
|
||||
disk => {}
|
||||
};
|
||||
|
||||
$controllervm_name_mapping->{$controllervm_result->{crtControllerVMId}} = $controllervm_result->{crtName};
|
||||
}
|
||||
|
||||
my $disk_snmp_result = $options{snmp}->get_table(
|
||||
oid => $oid_dstEntry,
|
||||
nothing_quit => 1
|
||||
);
|
||||
|
||||
foreach my $oid (keys %{$snmp_result}) {
|
||||
next if ($oid !~ /^$mapping->{dstDiskId}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||
foreach my $oid (keys %{$disk_snmp_result}) {
|
||||
next if ($oid !~ /^$disk_mapping->{dstDiskId}->{oid}\.(.*)$/);
|
||||
my $disk_instance = $1;
|
||||
my $disk_result = $options{snmp}->map_instance(mapping => $disk_mapping, results => $disk_snmp_result, instance => $disk_instance);
|
||||
|
||||
$result->{dstDiskId} = centreon::plugins::misc::trim($result->{dstDiskId});
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$result->{dstDiskId} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $result->{dstDiskId} . "': no matching filter.", debug => 1);
|
||||
if (!defined($controllervm_name_mapping->{$disk_result->{dstControllerVMId}})) {
|
||||
next;
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$disk_result->{dstDiskId} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $disk_result->{dstDiskId} . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$disk_result->{dstDiskId} = centreon::plugins::misc::trim($disk_result->{dstDiskId});
|
||||
|
||||
my $inodes_used;
|
||||
$inodes_used = 100 - ($result->{dstNumFreeInodes} * 100 / $result->{dstNumTotalInodes}) if ($result->{dstNumTotalInodes} > 0);
|
||||
$self->{disk}->{$instance} = {
|
||||
display => $result->{dstDiskId},
|
||||
%$result,
|
||||
inodes_used => $inodes_used
|
||||
$inodes_used = 100 - ($disk_result->{dstNumFreeInodes} * 100 / $disk_result->{dstNumTotalInodes}) if ($disk_result->{dstNumTotalInodes} > 0);
|
||||
|
||||
$self->{controllervm}->{$controllervm_name_mapping->{$disk_result->{dstControllerVMId}}}->{disk}->{$disk_result->{dstDiskId}} = {
|
||||
name => $controllervm_name_mapping->{$disk_result->{dstControllerVMId}},
|
||||
display => $disk_result->{dstDiskId},
|
||||
%$disk_result,
|
||||
inodes_used => $inodes_used
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{disk}}) <= 0) {
|
||||
if (scalar(keys %{$self->{controllervm}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No ControllerVM found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $disk_int = 0;
|
||||
foreach my $controllervm (keys %{$self->{controllervm}}) {
|
||||
if (scalar(keys %{$self->{controllervm}->{$controllervm}->{disk}}) <= 0) {
|
||||
$disk_int = $disk_int + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($disk_int eq keys %{$self->{controllervm}}) {
|
||||
$self->{output}->add_option_msg(short_msg => "No disk found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
@ -265,6 +354,10 @@ Example: --filter-counters='^usage$'
|
|||
|
||||
Filter disk name (can be a regexp).
|
||||
|
||||
=item B<--filter-controllervm>
|
||||
|
||||
Filter controllervm name (can be a regexp).
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status.
|
||||
|
|
|
@ -26,10 +26,19 @@ use strict;
|
|||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub prefix_hypervisor_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"Hypervisor '%s'",
|
||||
$options{instance_value}->{display}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $label = 'memory_used';
|
||||
my ($label, $nlabel) = ('memory_used', $self->{nlabel});
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
@ -37,9 +46,10 @@ sub custom_usage_perfdata {
|
|||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label . $extra_label, unit => 'B',
|
||||
nlabel => $nlabel,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
@ -78,59 +88,59 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$self->{maps_counters}->{hypervisor} = [
|
||||
{ label => 'cpu', set => {
|
||||
{ label => 'cpu', nlabel => 'hypervisor.cpu.utilization.percentage', set => {
|
||||
key_values => [ { name => 'hypervisorCpuUsagePercent' }, { name => 'display' } ],
|
||||
output_template => 'CPU Usage : %s %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_usage', value => 'hypervisorCpuUsagePercent', template => '%s', unit => '%',
|
||||
min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'cpu_usage', template => '%s', unit => '%',
|
||||
min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'memory', set => {
|
||||
{ label => 'memory', nlabel => 'hypervisor.memory.usage.bytes', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'hypervisorMemory' }, { name => 'hypervisorMemoryUsagePercent' } ],
|
||||
threshold_use => 'prct_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_perfdata => $self->can('custom_usage_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'avg-latency', set => {
|
||||
{ label => 'avg-latency', nlabel => 'hypervisor.average.io.latency.microseconds', set => {
|
||||
key_values => [ { name => 'hypervisorAverageLatency' }, { name => 'display' } ],
|
||||
output_template => 'Average Latency : %s µs',
|
||||
perfdatas => [
|
||||
{ label => 'avg_latency', value => 'hypervisorAverageLatency', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'avg_latency', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'read-iops', set => {
|
||||
{ label => 'read-iops', nlabel => 'hypervisor.read.usage.iops', set => {
|
||||
key_values => [ { name => 'hypervisorReadIOPerSecond' }, { name => 'display' } ],
|
||||
output_template => 'Read IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'read_iops', value => 'hypervisorReadIOPerSecond', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'read_iops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'write-iops', set => {
|
||||
{ label => 'write-iops', nlabel => 'hypervisor.write.usage.iops', set => {
|
||||
key_values => [ { name => 'hypervisorWriteIOPerSecond' }, { name => 'display' } ],
|
||||
output_template => 'Write IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'write_iops', value => 'hypervisorWriteIOPerSecond', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'write_iops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'vm-count', set => {
|
||||
{ label => 'vm-count', nlabel => 'hypervisor.vm.count', set => {
|
||||
key_values => [ { name => 'hypervisorVmCount' }, { name => 'display' } ],
|
||||
output_template => 'VM Count : %s',
|
||||
perfdatas => [
|
||||
{ label => 'vm_count', value => 'hypervisorVmCount', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'vm_count', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -146,12 +156,6 @@ sub new {
|
|||
return $self;
|
||||
}
|
||||
|
||||
sub prefix_hypervisor_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Hypervisor '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
hypervisorName => { oid => '.1.3.6.1.4.1.41263.9.1.3' },
|
||||
hypervisorVmCount => { oid => '.1.3.6.1.4.1.41263.9.1.4' },
|
||||
|
@ -160,7 +164,7 @@ my $mapping = {
|
|||
hypervisorMemoryUsagePercent => { oid => '.1.3.6.1.4.1.41263.9.1.8' },
|
||||
hypervisorReadIOPerSecond => { oid => '.1.3.6.1.4.1.41263.9.1.9' },
|
||||
hypervisorWriteIOPerSecond => { oid => '.1.3.6.1.4.1.41263.9.1.10' },
|
||||
hypervisorAverageLatency => { oid => '.1.3.6.1.4.1.41263.9.1.11' },
|
||||
hypervisorAverageLatency => { oid => '.1.3.6.1.4.1.41263.9.1.11' }
|
||||
};
|
||||
|
||||
my $oid_hypervisorEntry = '.1.3.6.1.4.1.41263.9.1';
|
||||
|
|
|
@ -26,13 +26,22 @@ use strict;
|
|||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub prefix_sp_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprinf(
|
||||
"Storage Pool '%s'",
|
||||
$options{instance_value}->{display}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $label = 'used';
|
||||
my ($label, $nlabel) = ('used', $self->{nlabel});
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
if (defined($self->{instance_mode}->{option_results}->{free})) {
|
||||
$label = 'free';
|
||||
($label, $nlabel) = ('free', 'storagepool.storage.space.free.bytes');
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my $extra_label = '';
|
||||
|
@ -45,9 +54,10 @@ sub custom_usage_perfdata {
|
|||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label . $extra_label, unit => 'B',
|
||||
nlabel => $nlabel,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
@ -62,7 +72,13 @@ sub custom_usage_threshold {
|
|||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(
|
||||
value => $threshold_value,
|
||||
threshold => [
|
||||
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -100,32 +116,32 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$self->{maps_counters}->{sp} = [
|
||||
{ label => 'usage', set => {
|
||||
{ label => 'usage', nlabel => 'storagepool.storage.space.usage.bytes', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'spitUsedCapacity' }, { name => 'spitTotalCapacity' } ],
|
||||
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'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'avg-latency', set => {
|
||||
{ label => 'avg-latency', nlabel => 'storagepool.average.io.latency.microseconds', set => {
|
||||
key_values => [ { name => 'spitAvgLatencyUsecs' }, { name => 'display' } ],
|
||||
output_template => 'Average Latency : %s µs',
|
||||
perfdatas => [
|
||||
{ label => 'avg_latency', value => 'spitAvgLatencyUsecs', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'avg_latency', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'iops', set => {
|
||||
{ label => 'iops', nlabel => 'storagepool.operations.iops', set => {
|
||||
key_values => [ { name => 'spitIOPerSecond' }, { name => 'display' } ],
|
||||
output_template => 'IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'iops', value => 'spitIOPerSecond', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'iops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -143,12 +159,6 @@ sub new {
|
|||
return $self;
|
||||
}
|
||||
|
||||
sub prefix_sp_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Storage Pool '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
spitStoragePoolName => { oid => '.1.3.6.1.4.1.41263.7.1.3' },
|
||||
spitTotalCapacity => { oid => '.1.3.6.1.4.1.41263.7.1.4' },
|
||||
|
|
|
@ -25,72 +25,155 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub prefix_vm_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"Virtual machine '%s'",
|
||||
$options{instance_value}->{display}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"state: '%s'",
|
||||
$self->{result_values}->{vmPowerState}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($label, $nlabel) = ('memory_used', $self->{nlabel});
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
my %total_options = (total => $self->{result_values}->{total}, cast_int => 1);
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label . $extra_label, unit => 'B',
|
||||
nlabel => $nlabel,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
return sprintf(
|
||||
'Memory Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_vmMemory'};
|
||||
$self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_vmMemoryUsagePercent'};
|
||||
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
|
||||
$self->{result_values}->{used} = $self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100;
|
||||
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok', skipped_code => { -10 => 1 } },
|
||||
{ name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok', skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{vm} = [
|
||||
{ label => 'cpu', set => {
|
||||
{
|
||||
label => 'vm-power-state',
|
||||
type => 2,
|
||||
critical_default => '%{vmPowerState} ne "on"',
|
||||
set => {
|
||||
key_values => [ { name => 'vmPowerState' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'cpu', nlabel => 'vm.cpu.utilization.percentage', set => {
|
||||
key_values => [ { name => 'vmCpuUsagePercent' }, { name => 'display' } ],
|
||||
output_template => 'CPU Usage : %s %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_usage', template => '%s', unit => '%',
|
||||
min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'avg-latency', set => {
|
||||
{ label => 'memory', nlabel => 'vm.memory.usage.bytes', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'vmMemory' }, { name => 'vmMemoryUsagePercent' } ],
|
||||
threshold_use => 'prct_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')
|
||||
}
|
||||
},
|
||||
{ label => 'avg-latency', nlabel => 'vm.average.io.latency.microseconds', set => {
|
||||
key_values => [ { name => 'vmAverageLatency' }, { name => 'display' } ],
|
||||
output_template => 'Average Latency : %s µs',
|
||||
perfdatas => [
|
||||
{ label => 'avg_latency', template => '%s', unit => 'µs',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'read-iops', set => {
|
||||
{ label => 'read-iops', nlabel => 'vm.read.usage.iops', set => {
|
||||
key_values => [ { name => 'vmReadIOPerSecond' }, { name => 'display' } ],
|
||||
output_template => 'Read IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'read_iops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'write-iops', set => {
|
||||
{ label => 'write-iops', nlabel => 'vm.write.usage.iops', set => {
|
||||
key_values => [ { name => 'vmWriteIOPerSecond' }, { name => 'display' } ],
|
||||
output_template => 'Write IOPs : %s',
|
||||
perfdatas => [
|
||||
{ label => 'write_iops', template => '%s', unit => 'iops',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'traffic-in', set => {
|
||||
{ label => 'traffic-in', nlabel => 'vm.traffic.in.bitspersecond', set => {
|
||||
key_values => [ { name => 'vmRxBytes', per_second => 1 }, { name => 'display' } ],
|
||||
output_template => 'Traffic In : %s %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'traffic_in', template => '%.2f',
|
||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
|
||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'traffic-out', set => {
|
||||
{ label => 'traffic-out', nlabel => 'vm.traffic.out.bitspersecond', set => {
|
||||
key_values => [ { name => 'vmTxBytes', per_second => 1 }, { name => 'display' } ],
|
||||
output_template => 'Traffic Out : %s %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'traffic_out', template => '%.2f',
|
||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -106,14 +189,9 @@ sub new {
|
|||
return $self;
|
||||
}
|
||||
|
||||
sub prefix_vm_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Virtual machine '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
vmName => { oid => '.1.3.6.1.4.1.41263.10.1.3' },
|
||||
vmPowerState => { oid => '.1.3.6.1.4.1.41263.10.1.5' },
|
||||
vmCpuUsagePercent => { oid => '.1.3.6.1.4.1.41263.10.1.7' },
|
||||
vmMemory => { oid => '.1.3.6.1.4.1.41263.10.1.8' },
|
||||
vmMemoryUsagePercent => { oid => '.1.3.6.1.4.1.41263.10.1.9' },
|
||||
|
@ -146,6 +224,7 @@ sub manage_selection {
|
|||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||
|
||||
$result->{vmName} = centreon::plugins::misc::trim($result->{vmName});
|
||||
$result->{vmPowerState} = centreon::plugins::misc::trim($result->{vmPowerState});
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$result->{vmName} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $result->{vmName} . "': no matching filter.", debug => 1);
|
||||
|
@ -189,17 +268,27 @@ Example: --filter-counters='^memory$'
|
|||
|
||||
Filter virtual machine name (can be a regexp).
|
||||
|
||||
=item B<--warning-vm-power-state>
|
||||
|
||||
Set warning threshold for the virtual machine power state.
|
||||
Can used special variables like: %{vmPowerState}.
|
||||
|
||||
=item B<--critical-vm-power-state>
|
||||
|
||||
Set critical threshold for the virtual machine power state.
|
||||
Can used special variables like: %{vmPowerState}.
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'avg-latency', 'read-iops', 'write-iops',
|
||||
'cpu' (%), 'traffic-in', 'traffic-out'.
|
||||
'cpu' (%), 'memory' (%s), 'traffic-in', 'traffic-out'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'avg-latency', 'read-iops', 'write-iops',
|
||||
'cpu' (%), 'traffic-in', 'traffic-out'.
|
||||
'cpu' (%), 'memory' (%s), 'traffic-in', 'traffic-out'.
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -30,19 +30,20 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'cluster-usage' => 'cloud::nutanix::snmp::mode::clusterusage',
|
||||
'container-usage' => 'cloud::nutanix::snmp::mode::containerusage',
|
||||
'disk-usage' => 'cloud::nutanix::snmp::mode::diskusage',
|
||||
'hypervisor-usage' => 'cloud::nutanix::snmp::mode::hypervisorusage',
|
||||
'list-containers' => 'cloud::nutanix::snmp::mode::listcontainers',
|
||||
'list-disks' => 'cloud::nutanix::snmp::mode::listdisks',
|
||||
'list-hypervisors' => 'cloud::nutanix::snmp::mode::listhypervisors',
|
||||
'list-storage-pools' => 'cloud::nutanix::snmp::mode::liststoragepools',
|
||||
'list-vms' => 'cloud::nutanix::snmp::mode::listvms',
|
||||
'storage-pool-usage' => 'cloud::nutanix::snmp::mode::storagepoolusage',
|
||||
'vm-usage' => 'cloud::nutanix::snmp::mode::vmusage',
|
||||
);
|
||||
$self->{modes} = {
|
||||
'cluster-usage' => 'cloud::nutanix::snmp::mode::clusterusage',
|
||||
'container-usage' => 'cloud::nutanix::snmp::mode::containerusage',
|
||||
'discovery' => 'cloud::nutanix::snmp::mode::discovery',
|
||||
'disk-usage' => 'cloud::nutanix::snmp::mode::diskusage',
|
||||
'hypervisor-usage' => 'cloud::nutanix::snmp::mode::hypervisorusage',
|
||||
'list-containers' => 'cloud::nutanix::snmp::mode::listcontainers',
|
||||
'list-disks' => 'cloud::nutanix::snmp::mode::listdisks',
|
||||
'list-hypervisors' => 'cloud::nutanix::snmp::mode::listhypervisors',
|
||||
'list-storage-pools' => 'cloud::nutanix::snmp::mode::liststoragepools',
|
||||
'list-vms' => 'cloud::nutanix::snmp::mode::listvms',
|
||||
'storage-pool-usage' => 'cloud::nutanix::snmp::mode::storagepoolusage',
|
||||
'vm-usage' => 'cloud::nutanix::snmp::mode::vmusage'
|
||||
};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue