centreon-plugins/network/cisco/aci/apic/restapi/mode/fabric.pm

141 lines
4.1 KiB
Perl
Raw Normal View History

2019-06-07 16:09:28 +02:00
#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2019-06-07 16:09:28 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::cisco::aci::apic::restapi::mode::fabric;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_health_output {
my ($self, %options) = @_;
my $msg = sprintf("health current: %d%%, previous: %d%%", $self->{result_values}->{current}, $self->{result_values}->{previous});
return $msg;
}
sub custom_health_perfdata {
my ($self, %options) = @_;
foreach ('current', 'previous') {
$self->{output}->perfdata_add(
label => $_,
2019-06-13 10:35:46 +02:00
nlabel => 'fabric.health.' . $_ . '.percentage',
2019-06-07 16:09:28 +02:00
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{dn} : undef,
value => $self->{result_values}->{$_},
unit => '%', min => 0, max => 100
);
}
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'fabric', type => 1, cb_prefix_output => 'prefix_fabric_output', message_multiple => 'all fabrics are ok' },
];
$self->{maps_counters}->{fabric} = [
{ label => 'health', threshold => 0, set => {
key_values => [ { name => 'current' }, { name => 'previous' }, { name => 'dn' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_health_output'),
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_perfdata => $self->can('custom_health_perfdata'),
}
},
];
}
sub prefix_fabric_output {
my ($self, %options) = @_;
return "Fabric '" . $options{instance_value}->{dn} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'warning-health:s' => { name => 'warning_health' },
'critical-health:s' => { name => 'critical_health' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_health', 'critical_health']);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{fabric} = {};
my $result_global = $options{custom}->get_fabric_health();
foreach my $object (@{$result_global->{imdata}}) {
my $dn = $object->{fabricHealthTotal}->{attributes}->{dn};
$self->{fabric}->{$dn} = {
current => $object->{fabricHealthTotal}->{attributes}->{cur},
previous => $object->{fabricHealthTotal}->{attributes}->{prev},
dn => $dn
};
}
if (scalar(keys %{$self->{fabric}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No fabric found (try --debug)");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check fabrics.
=over 8
=item B<--warning-health>
Set warning for the health level
Can used special variables like: %{current}, %{previous}.
example: --warning-health='%{previous} < %{current}'
=item B<--critical-health>
Set critical for the health level
Can used special variables like: %{current}, %{previous}.
example: --critical-health='%{current} < 98'
=back
=cut