2017-03-10 11:04:11 +01:00
|
|
|
#
|
|
|
|
# Copyright 2017 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 network::audiocodes::snmp::mode::trunkstatus;
|
|
|
|
|
|
|
|
use base qw(centreon::plugins::templates::counter);
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2017-05-24 12:54:12 +02:00
|
|
|
use Digest::MD5 qw(md5_hex);
|
2017-03-10 11:04:11 +01:00
|
|
|
|
|
|
|
my $instance_mode;
|
|
|
|
|
|
|
|
sub custom_status_threshold {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
my $status = 'ok';
|
|
|
|
my $message;
|
|
|
|
|
|
|
|
eval {
|
|
|
|
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
|
|
|
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
|
|
|
|
|
|
|
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
|
|
|
|
eval "$instance_mode->{option_results}->{critical_status}") {
|
|
|
|
$status = 'critical';
|
|
|
|
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
|
|
|
|
eval "$instance_mode->{option_results}->{warning_status}") {
|
|
|
|
$status = 'warning';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (defined($message)) {
|
|
|
|
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub custom_status_output {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
2017-03-17 11:33:14 +01:00
|
|
|
my $msg = 'alarm status : ' . $self->{result_values}->{alarm} . ' [state: ' . $self->{result_values}->{state} . ']';
|
2017-03-10 11:04:11 +01:00
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub custom_status_calc {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
$self->{result_values}->{alarm} = $options{new_datas}->{$self->{instance} . '_alarm'};
|
|
|
|
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
|
|
|
$self->{result_values}->{dchannel} = $options{new_datas}->{$self->{instance} . '_dchannel'};
|
2017-03-17 11:14:30 +01:00
|
|
|
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
|
2017-03-10 11:04:11 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_counters {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
$self->{maps_counters_type} = [
|
|
|
|
{ name => 'trunk', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All trunks are ok' }
|
|
|
|
];
|
|
|
|
|
|
|
|
$self->{maps_counters}->{trunk} = [
|
|
|
|
{ label => 'status', threshold => 0, set => {
|
2017-03-17 11:14:30 +01:00
|
|
|
key_values => [ { name => 'display' }, { name => 'dchannel' }, { name => 'alarm' }, { name => 'state' } ],
|
2017-03-10 11:04:11 +01:00
|
|
|
closure_custom_calc => $self->can('custom_status_calc'),
|
|
|
|
closure_custom_output => $self->can('custom_status_output'),
|
|
|
|
closure_custom_perfdata => sub { return 0; },
|
|
|
|
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
|
|
|
}
|
|
|
|
},
|
2017-05-24 12:54:12 +02:00
|
|
|
{ label => 'avg-calls', set => {
|
|
|
|
key_values => [ { name => 'acPMTrunkUtilizationAverage' }, { name => 'display' } ],
|
|
|
|
output_template => 'Average calls : %s',
|
|
|
|
perfdatas => [
|
|
|
|
{ label => 'avg_calls', value => 'acPMTrunkUtilizationAverage_absolute', template => '%d',
|
|
|
|
min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' },
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ label => 'max-calls', set => {
|
|
|
|
key_values => [ { name => 'acPMTrunkUtilizationMax' }, { name => 'display' } ],
|
|
|
|
output_template => 'Max calls : %s',
|
|
|
|
perfdatas => [
|
|
|
|
{ label => 'max_calls', value => 'acPMTrunkUtilizationMax_absolute', template => '%d',
|
|
|
|
min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' },
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ label => 'count-calls', set => {
|
|
|
|
key_values => [ { name => 'acPMTrunkUtilizationTotal' }, { name => 'display' } ],
|
|
|
|
output_template => 'Count calls : %s',
|
|
|
|
perfdatas => [
|
|
|
|
{ label => 'count_calls', value => 'acPMTrunkUtilizationTotal_absolute', template => '%d',
|
|
|
|
min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' },
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
2017-03-10 11:04:11 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
my ($class, %options) = @_;
|
2017-05-24 12:54:12 +02:00
|
|
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
2017-03-10 11:04:11 +01:00
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
$self->{version} = '1.0';
|
|
|
|
$options{options}->add_options(arguments =>
|
|
|
|
{
|
|
|
|
"warning-status:s" => { name => 'warning_status', default => '' },
|
2017-03-17 11:14:30 +01:00
|
|
|
"critical-status:s" => { name => 'critical_status', default => '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i' },
|
2017-03-10 11:04:11 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_options {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
$self->SUPER::check_options(%options);
|
|
|
|
|
|
|
|
$instance_mode = $self;
|
|
|
|
$self->change_macros();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub prefix_vpn_output {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
return "Trunk '" . $options{instance_value}->{display} . "' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub change_macros {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
foreach (('warning_status', 'critical_status')) {
|
|
|
|
if (defined($self->{option_results}->{$_})) {
|
|
|
|
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my %map_alarm = (0 => 'greyDisabled', 1 => 'greenActive', 2 => 'redLosLof',
|
|
|
|
3 => 'blueAis', 4 => 'yellowRai', 5 => 'orangeDChannel', 6 => 'purpleLowerLayerDown', 7 => 'darkOrangeNFASAlarm');
|
|
|
|
my %map_dchannel = (0 => 'dChannelEstablished', 1 => 'dChannelNotEstablished', 10 => 'dChannelNotApplicable');
|
2017-03-17 11:14:30 +01:00
|
|
|
my %map_deactivate = (0 => 'notAvailable', 1 => 'deActivated', 2 => 'activated');
|
2017-03-10 11:04:11 +01:00
|
|
|
|
|
|
|
my $mapping = {
|
2017-05-24 12:54:12 +02:00
|
|
|
status => {
|
|
|
|
acTrunkStatusDChannel => { oid => '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1.6', map => \%map_dchannel },
|
|
|
|
acTrunkStatusAlarm => { oid => '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1.7', map => \%map_alarm },
|
|
|
|
acTrunkDeactivate => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.11', map => \%map_deactivate },
|
|
|
|
acTrunkName => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.13' },
|
|
|
|
},
|
|
|
|
usage => {
|
|
|
|
acPMTrunkUtilizationAverage => { oid => '.1.3.6.1.4.1.5003.10.10.2.21.1.4' },
|
|
|
|
acPMTrunkUtilizationMax => { oid => '.1.3.6.1.4.1.5003.10.10.2.21.1.5' },
|
|
|
|
acPMTrunkUtilizationTotal => { oid => '.1.3.6.1.4.1.5003.10.10.2.21.1.12' },
|
|
|
|
}
|
2017-03-10 11:04:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
sub manage_selection {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
$self->{trunk} = {};
|
2017-05-24 12:54:12 +02:00
|
|
|
my $oids = [];
|
|
|
|
foreach (keys %{$mapping}) {
|
|
|
|
foreach my $name (keys %{$mapping->{$_}}) {
|
|
|
|
push @{$oids}, { oid => $mapping->{$_}->{$name}->{oid} };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $snmp_result = $options{snmp}->get_multiple_table(oids => $oids, nothing_quit => 1);
|
|
|
|
|
|
|
|
my $datas = { status => {}, usage => {} };
|
|
|
|
foreach (keys %{$mapping}) {
|
|
|
|
foreach my $name (keys %{$mapping->{$_}}) {
|
|
|
|
$datas->{$_} = { %{$datas->{$_}}, %{$snmp_result->{ $mapping->{$_}->{$name}->{oid} }} };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (keys %{$snmp_result->{ $mapping->{status}->{acTrunkStatusAlarm}->{oid} }}) {
|
|
|
|
/\.(\d+)$/;
|
2017-03-10 11:04:11 +01:00
|
|
|
my $instance = $1;
|
2017-05-24 12:54:12 +02:00
|
|
|
my $result = $options{snmp}->map_instance(mapping => $mapping->{status}, results => $datas->{status}, instance => $instance);
|
|
|
|
my $result2 = $options{snmp}->map_instance(mapping => $mapping->{usage}, results => $datas->{usage}, instance => $instance . '.0');
|
2017-03-10 11:04:11 +01:00
|
|
|
|
|
|
|
$self->{trunk}->{$instance} = {
|
|
|
|
display => defined($result->{acTrunkName}) && $result->{acTrunkName} ne '' ? $result->{acTrunkName} : $instance,
|
|
|
|
alarm => $result->{acTrunkStatusAlarm},
|
2017-03-17 11:14:30 +01:00
|
|
|
state => $result->{acTrunkDeactivate},
|
2017-05-24 12:54:12 +02:00
|
|
|
dchannel => $result->{acTrunkStatusDChannel},
|
|
|
|
%$result2 };
|
2017-03-10 11:04:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scalar(keys %{$self->{trunk}}) <= 0) {
|
|
|
|
$self->{output}->add_option_msg(short_msg => "No trunk found.");
|
|
|
|
$self->{output}->option_exit();
|
|
|
|
}
|
2017-05-24 12:54:12 +02:00
|
|
|
|
|
|
|
$self->{cache_name} = "audiocodes_" . $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'));
|
2017-03-10 11:04:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 MODE
|
|
|
|
|
2017-05-24 12:54:12 +02:00
|
|
|
Check trunk status.
|
2017-03-10 11:04:11 +01:00
|
|
|
|
|
|
|
=over 8
|
|
|
|
|
|
|
|
=item B<--warning-status>
|
|
|
|
|
|
|
|
Set warning threshold for status.
|
2017-03-17 11:14:30 +01:00
|
|
|
Can used special variables like: %{display}, %{alarm}, %{dchannel}, %{state}
|
2017-03-10 11:04:11 +01:00
|
|
|
|
|
|
|
=item B<--critical-status>
|
|
|
|
|
2017-03-17 11:14:30 +01:00
|
|
|
Set critical threshold for status (Default: '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i').
|
|
|
|
Can used special variables like: %{display}, %{alarm}, %{dchannel}, %{state}
|
2017-03-10 11:04:11 +01:00
|
|
|
|
2017-05-24 12:54:12 +02:00
|
|
|
=item B<--warning-*>
|
|
|
|
|
|
|
|
Threshold warning.
|
|
|
|
Can be: 'avg-calls', 'max-calls', 'count-calls'.
|
|
|
|
|
|
|
|
=item B<--critical-*>
|
|
|
|
|
|
|
|
Threshold critical.
|
|
|
|
Can be: 'avg-calls', 'max-calls', 'count-calls'.
|
|
|
|
|
|
|
|
|
2017-03-10 11:04:11 +01:00
|
|
|
=back
|
|
|
|
|
|
|
|
=cut
|