From 280b9ed147f2e3973dc2c96de33a9b5c99339779 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 19 Apr 2021 13:15:05 +0200 Subject: [PATCH] Fix #2710 (#2716) --- .../cisco/callmanager/snmp/mode/ccmusage.pm | 103 +++++++------- .../cisco/callmanager/snmp/mode/ctiusage.pm | 129 ++++++++---------- .../callmanager/snmp/mode/gatewayusage.pm | 103 ++++++-------- .../callmanager/snmp/mode/mediadeviceusage.pm | 99 ++++++-------- .../cisco/callmanager/snmp/mode/phoneusage.pm | 17 +-- .../callmanager/snmp/mode/voicemailusage.pm | 98 ++++++------- .../network/cisco/callmanager/snmp/plugin.pm | 6 +- 7 files changed, 246 insertions(+), 309 deletions(-) diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm index 9b45a69eb..7105fe467 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return 'status : ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -41,49 +40,56 @@ sub custom_status_calc { return 0; } +sub prefix_ccm_output { + my ($self, %options) = @_; + + return "CCM '" . $options{instance_value}->{ccmName} . "' "; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ { name => 'global', type => 0 }, - { name => 'ccm', type => 1, cb_prefix_output => 'prefix_ccm_output', message_multiple => 'All CCM are ok' }, + { name => 'ccm', type => 1, cb_prefix_output => 'prefix_ccm_output', message_multiple => 'All CCM are ok' } ]; $self->{maps_counters}->{ccm} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{status} !~ /up/', set => { key_values => [ { name => 'ccmStatus' }, { name => 'ccmName' } ], 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 } - }, + } ]; my @map = ( - ['phones-registered', 'Phones Registered : %s', 'ccmRegisteredPhones'], - ['phones-unregistered', 'Phones Unregistered : %s', 'ccmUnregisteredPhones'], - ['phones-rejected', 'Phones Rejected : %s', 'ccmRejectedPhones'], - ['gateways-registered', 'Gateways Registered : %s', 'ccmRegisteredPhones'], - ['gateways-unregistered', 'Gateways Unregistered : %s', 'ccmUnregisteredGateways'], - ['gateways-rejected', 'Gateways Rejected : %s', 'ccmRejectedGateways'], - ['mediadevices-registered', 'Media Devices Registered : %s', 'ccmRegisteredMediaDevices'], - ['mediadevices-unregistered', 'Media Devices Unregistered : %s', 'ccmUnregisteredMediaDevices'], - ['mediadevices-rejected', 'Media Devices Rejected : %s', 'ccmRejectedMediaDevices'], + ['phones-registered', 'Phones Registered : %s', 'ccmRegisteredPhones', 'phones.registered.count'], + ['phones-unregistered', 'Phones Unregistered : %s', 'ccmUnregisteredPhones', 'phones.unregistered.count'], + ['phones-rejected', 'Phones Rejected : %s', 'ccmRejectedPhones', 'phones.rejected.count'], + ['gateways-registered', 'Gateways Registered : %s', 'ccmRegisteredGateways', 'gateways.registered.count'], + ['gateways-unregistered', 'Gateways Unregistered : %s', 'ccmUnregisteredGateways', 'gateways.unregistered.count'], + ['gateways-rejected', 'Gateways Rejected : %s', 'ccmRejectedGateways', 'gateways.rejected.count'], + ['mediadevices-registered', 'Media Devices Registered : %s', 'ccmRegisteredMediaDevices', 'media_devices.registered.count'], + ['mediadevices-unregistered', 'Media Devices Unregistered : %s', 'ccmUnregisteredMediaDevices', 'media_devices.unregistered.count'], + ['mediadevices-rejected', 'Media Devices Rejected : %s', 'ccmRejectedMediaDevices', 'media_devices.rejected.count'] ); - + $self->{maps_counters}->{global} = []; foreach (@map) { my $label = $_->[0]; $label =~ tr/-/_/; - push @{$self->{maps_counters}->{global}}, { label => $_->[0], set => { + push @{$self->{maps_counters}->{global}}, { + label => $_->[0], nlabel => $_->[3], set => { key_values => [ { name => $_->[2] } ], output_template => $_->[1], perfdatas => [ - { label => $label, value => $_->[2] , template => '%s', min => 0 }, - ], + { label => $label, value => $_->[2] , template => '%s', min => 0 } + ] } - }, + }; } } @@ -91,29 +97,13 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /up/' }, - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub prefix_ccm_output { - my ($self, %options) = @_; - - return "CCM '" . $options{instance_value}->{ccmName} . "' "; -} - my %mapping_status = (1 => 'unknown', 2 => 'up', 3 => 'down'); my $mapping = { @@ -125,11 +115,11 @@ my $mapping = { ccmRejectedGateways => { oid => '.1.3.6.1.4.1.9.9.156.1.5.10' }, ccmRegisteredMediaDevices => { oid => '.1.3.6.1.4.1.9.9.156.1.5.11' }, ccmUnregisteredMediaDevices => { oid => '.1.3.6.1.4.1.9.9.156.1.5.12' }, - ccmRejectedMediaDevices => { oid => '.1.3.6.1.4.1.9.9.156.1.5.13' }, + ccmRejectedMediaDevices => { oid => '.1.3.6.1.4.1.9.9.156.1.5.13' } }; my $mapping2 = { ccmName => { oid => '.1.3.6.1.4.1.9.9.156.1.1.2.1.2' }, - ccmStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.1.2.1.5', map => \%mapping_status }, + ccmStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.1.2.1.5', map => \%mapping_status } }; my $oid_ccmGlobalInfo = '.1.3.6.1.4.1.9.9.156.1.5'; @@ -137,21 +127,24 @@ my $oid_ccmEntry = '.1.3.6.1.4.1.9.9.156.1.1.2.1'; sub manage_selection { my ($self, %options) = @_; - - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ { oid => $oid_ccmGlobalInfo, end => $mapping->{ccmRejectedMediaDevices}->{oid} }, - { oid => $oid_ccmEntry, end => $mapping2->{ccmStatus}->{oid} }, - ], nothing_quit => 1); + { oid => $oid_ccmEntry, end => $mapping2->{ccmStatus}->{oid} } + ], + nothing_quit => 1 + ); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_ccmGlobalInfo}, instance => '0'); - $self->{global} = { %$result }; - + $self->{global} = $result; + $self->{ccm} = {}; foreach my $oid (keys %{$snmp_result->{$oid_ccmEntry}}) { next if ($oid !~ /^$mapping2->{ccmStatus}->{oid}\.(.*)/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_ccmEntry}, instance => $instance); - - $self->{ccm}->{$instance} = { %$result }; + + $self->{ccm}->{$instance} = $result; } } @@ -180,13 +173,9 @@ Can used special variables like: %{status}, %{display} Set critical threshold for status (Default: '%{status} !~ /up/'). Can used special variables like: %{status}, %{display} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'phones-registered', 'phones-unregistered', 'phones-rejected', 'gateways-registered', 'gateways-unregistered', 'gateways-rejected', diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/ctiusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/ctiusage.pm index 849e4fe27..b0c59ee27 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/ctiusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/ctiusage.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return 'status: ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -41,67 +40,6 @@ sub custom_status_calc { return 0; } -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, - { name => 'cti', type => 1, cb_prefix_output => 'prefix_cti_output', message_multiple => 'All ctis are ok' }, - ]; - - $self->{maps_counters}->{cti} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'ccmCTIDeviceStatus' }, { name => 'ccmCTIDeviceName' } ], - 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, - } - }, - ]; - - my @map = ( - ['total-registered', 'Registered : %s', 'registered'], - ['total-unregistered', 'Unregistered : %s', 'unregistered'], - ['total-rejected', 'Rejected : %s', 'rejected'], - ['total-unknown', 'Unknown : %s', 'unknown'], - ['total-partiallyregistered', 'Partially Registered : %s', 'partiallyregistered'], - ); - - $self->{maps_counters}->{global} = []; - foreach (@map) { - push @{$self->{maps_counters}->{global}}, { label => $_->[0], nlabel => 'cti.devices.total.' . $_->[2] . '.count', set => { - key_values => [ { name => $_->[2] } ], - output_template => $_->[1], - perfdatas => [ - { value => $_->[2] , template => '%s', min => 0 }, - ], - } - }, - } -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => { - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /^registered/' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - sub prefix_cti_output { my ($self, %options) = @_; @@ -111,17 +49,70 @@ sub prefix_cti_output { sub prefix_global_output { my ($self, %options) = @_; - return "Total "; + return 'Total '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'cti', type => 1, cb_prefix_output => 'prefix_cti_output', message_multiple => 'All ctis are ok' } + ]; + + $self->{maps_counters}->{cti} = [ + { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => { + key_values => [ { name => 'ccmCTIDeviceStatus' }, { name => 'ccmCTIDeviceName' } ], + 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_ng + } + } + ]; + + my @map = ( + ['total-registered', 'registered: %s', 'registered'], + ['total-unregistered', 'unregistered: %s', 'unregistered'], + ['total-rejected', 'rejected: %s', 'rejected'], + ['total-unknown', 'unknown: %s', 'unknown'], + ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered'] + ); + + $self->{maps_counters}->{global} = []; + foreach (@map) { + push @{$self->{maps_counters}->{global}}, { + label => $_->[0], nlabel => 'cti.devices.total.' . $_->[2] . '.count', set => { + key_values => [ { name => $_->[2] } ], + output_template => $_->[1], + perfdatas => [ + { value => $_->[2] , template => '%s', min => 0 } + ] + } + }; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => { + }); + + return $self; } my %mapping_status = ( 1 => 'unknown', 2 => 'registered', 3 => 'unregistered', - 4 => 'rejected', 5 => 'partiallyregistered', + 4 => 'rejected', 5 => 'partiallyregistered' ); my $mapping = { ccmCTIDeviceName => { oid => '.1.3.6.1.4.1.9.9.156.1.8.1.1.2' }, - ccmCTIDeviceStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.8.1.1.5', map => \%mapping_status }, + ccmCTIDeviceStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.8.1.1.5', map => \%mapping_status } }; my $oid_ccmCtiEntry = '.1.3.6.1.4.1.9.9.156.1.8.1.1'; @@ -142,8 +133,8 @@ sub manage_selection { next if ($oid !~ /^$mapping->{ccmCTIDeviceStatus}->{oid}\.(.*)/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - - $self->{phone}->{$instance} = { %$result }; + + $self->{phone}->{$instance} = $result; $self->{global}->{$result->{ccmCTIDeviceStatus}}++; } } diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm index af7979c16..dd6058442 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm @@ -24,21 +24,24 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return 'status: ' . $self->{result_values}->{status}; } -sub custom_status_calc { +sub prefix_gateway_output { my ($self, %options) = @_; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_ccmGatewayStatus'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_ccmGatewayName'}; - return 0; + return "Gateway '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Total '; } sub set_counters { @@ -46,40 +49,40 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, - { name => 'gateway', type => 1, cb_prefix_output => 'prefix_gateway_output', message_multiple => 'All gateways are ok' }, + { name => 'gateway', type => 1, cb_prefix_output => 'prefix_gateway_output', message_multiple => 'All gateways are ok' } ]; $self->{maps_counters}->{gateway} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'ccmGatewayStatus' }, { name => 'ccmGatewayName' } ], - closure_custom_calc => $self->can('custom_status_calc'), + { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => { + key_values => [ { name => 'status' }, { name => 'display' } ], 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 } - }, + } ]; my @map = ( - ['total-registered', 'Registered : %s', 'registered'], - ['total-unregistered', 'Unregistered : %s', 'unregistered'], - ['total-rejected', 'Rejected : %s', 'rejected'], - ['total-unknown', 'Unknown : %s', 'unknown'], - ['total-partiallyregistered', 'Partially Registered : %s', 'partiallyregistered'], + ['total-registered', 'registered: %s', 'registered', 'gateways.registered.count'], + ['total-unregistered', 'unregistered: %s', 'unregistered', 'gateways.unregistered.count'], + ['total-rejected', 'rejected: %s', 'rejected', 'gateways.rejected.count'], + ['total-unknown', 'unknown: %s', 'unknown', 'gateways.unknown.count'], + ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered', 'gateways.partially_registered.count'] ); $self->{maps_counters}->{global} = []; foreach (@map) { my $label = $_->[0]; $label =~ tr/-/_/; - push @{$self->{maps_counters}->{global}}, { label => $_->[0], set => { + push @{$self->{maps_counters}->{global}}, { + label => $_->[0], nlabel => $_->[3], set => { key_values => [ { name => $_->[2] } ], output_template => $_->[1], perfdatas => [ - { label => $label, value => $_->[2] , template => '%s', min => 0 }, - ], + { label => $label, value => $_->[2] , template => '%s', min => 0 } + ] } - }, + }; } } @@ -87,61 +90,43 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /^registered/' }, - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub prefix_gateway_output { - my ($self, %options) = @_; - - return "Gateway '" . $options{instance_value}->{ccmGatewayName} . "' "; -} - -sub prefix_global_output { - my ($self, %options) = @_; - - return "Total "; -} - my %mapping_status = ( 1 => 'unknown', 2 => 'registered', 3 => 'unregistered', - 4 => 'rejected', 5 => 'partiallyregistered', + 4 => 'rejected', 5 => 'partiallyregistered' ); my $mapping = { - ccmGatewayName => { oid => '.1.3.6.1.4.1.9.9.156.1.3.1.1.2' }, - ccmGatewayStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.3.1.1.5', map => \%mapping_status }, + display => { oid => '.1.3.6.1.4.1.9.9.156.1.3.1.1.2' }, # ccmGatewayName + status => { oid => '.1.3.6.1.4.1.9.9.156.1.3.1.1.5', map => \%mapping_status } # ccmGatewayStatus }; - my $oid_ccmGatewayEntry = '.1.3.6.1.4.1.9.9.156.1.3.1.1'; sub manage_selection { my ($self, %options) = @_; - - my $snmp_result = $options{snmp}->get_table(oid => $oid_ccmGatewayEntry, start => $mapping->{ccmGatewayName}->{oid}, end => $mapping->{ccmGatewayStatus}->{oid}, nothing_quit => 1); - + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ccmGatewayEntry, + start => $mapping->{display}->{oid}, + end => $mapping->{status}->{oid}, + nothing_quit => 1 + ); + $self->{phone} = {}; $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 }; foreach my $oid (keys %$snmp_result) { - next if ($oid !~ /^$mapping->{ccmGatewayStatus}->{oid}\.(.*)/); + next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - - $self->{phone}->{$instance} = { %$result }; - $self->{global}->{$result->{ccmGatewayStatus}}++; + + $self->{phone}->{$instance} = $result; + $self->{global}->{ $result->{status} }++; } } diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm index 88c332c10..6d242474a 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm @@ -24,21 +24,24 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return 'status: ' . $self->{result_values}->{status}; } -sub custom_status_calc { +sub prefix_md_output { my ($self, %options) = @_; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_ccmMediaDeviceStatus'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_ccmMediaDeviceName'}; - return 0; + return "Media device '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Total '; } sub set_counters { @@ -46,40 +49,40 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, - { name => 'md', type => 1, cb_prefix_output => 'prefix_md_output', message_multiple => 'All media devices are ok' }, + { name => 'md', type => 1, cb_prefix_output => 'prefix_md_output', message_multiple => 'All media devices are ok' } ]; $self->{maps_counters}->{md} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'ccmMediaDeviceStatus' }, { name => 'ccmMediaDeviceName' } ], - closure_custom_calc => $self->can('custom_status_calc'), + { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => { + key_values => [ { name => 'status' }, { name => 'display' } ], 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 } - }, + } ]; my @map = ( - ['total-registered', 'Registered : %s', 'registered'], - ['total-unregistered', 'Unregistered : %s', 'unregistered'], - ['total-rejected', 'Rejected : %s', 'rejected'], - ['total-unknown', 'Unknown : %s', 'unknown'], - ['total-partiallyregistered', 'Partially Registered : %s', 'partiallyregistered'], + ['total-registered', 'registered: %s', 'registered', 'media_devices.registered.count'], + ['total-unregistered', 'unregistered: %s', 'unregistered', 'media_devices.unregistered.count'], + ['total-rejected', 'rejected: %s', 'rejected', 'media_devices.rejected.count'], + ['total-unknown', 'unknown: %s', 'unknown', 'media_devices.unknown.count'], + ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered', 'media_devices.partially_registered.count'] ); $self->{maps_counters}->{global} = []; foreach (@map) { my $label = $_->[0]; $label =~ tr/-/_/; - push @{$self->{maps_counters}->{global}}, { label => $_->[0], set => { + push @{$self->{maps_counters}->{global}}, { + label => $_->[0], nlabel => $_->[3], set => { key_values => [ { name => $_->[2] } ], output_template => $_->[1], perfdatas => [ - { label => $label, value => $_->[2] , template => '%s', min => 0 }, - ], + { label => $label, value => $_->[2] , template => '%s', min => 0 } + ] } - }, + }; } } @@ -87,61 +90,43 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /^registered/' }, - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub prefix_md_output { - my ($self, %options) = @_; - - return "Media device '" . $options{instance_value}->{ccmMediaDeviceName} . "' "; -} - -sub prefix_global_output { - my ($self, %options) = @_; - - return "Total "; -} - my %mapping_status = ( 1 => 'unknown', 2 => 'registered', 3 => 'unregistered', - 4 => 'rejected', 5 => 'partiallyregistered', + 4 => 'rejected', 5 => 'partiallyregistered' ); my $mapping = { - ccmMediaDeviceName => { oid => '.1.3.6.1.4.1.9.9.156.1.6.1.1.2' }, - ccmMediaDeviceStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.6.1.1.5', map => \%mapping_status }, + display => { oid => '.1.3.6.1.4.1.9.9.156.1.6.1.1.2' }, # ccmMediaDeviceName + status => { oid => '.1.3.6.1.4.1.9.9.156.1.6.1.1.5', map => \%mapping_status } # ccmMediaDeviceStatus }; - my $oid_ccmMediaDeviceEntry = '.1.3.6.1.4.1.9.9.156.1.6.1.1'; sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_table(oid => $oid_ccmMediaDeviceEntry, start => $mapping->{ccmMediaDeviceName}->{oid}, end => $mapping->{ccmMediaDeviceStatus}->{oid}, nothing_quit => 1); - + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ccmMediaDeviceEntry, + start => $mapping->{display}->{oid}, + end => $mapping->{status}->{oid}, + nothing_quit => 1 + ); + $self->{md} = {}; $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 }; foreach my $oid (keys %$snmp_result) { - next if ($oid !~ /^$mapping->{ccmMediaDeviceStatus}->{oid}\.(.*)/); + next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - + $self->{md}->{$instance} = { %$result }; - $self->{global}->{$result->{ccmMediaDeviceStatus}}++; + $self->{global}->{ $result->{status} }++; } } diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm index 6eb56573e..b2884e124 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm @@ -29,7 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; + my $msg = 'status: ' . $self->{result_values}->{status}; $msg .= ' [description: ' . $self->{result_values}->{description} . ']' if (defined($self->{result_values}->{description}) && $self->{result_values}->{description} ne ''); return $msg; } @@ -43,7 +43,7 @@ sub prefix_phone_output { sub prefix_global_output { my ($self, %options) = @_; - return "Total "; + return 'Total '; } sub set_counters { @@ -65,18 +65,19 @@ sub set_counters { ]; my @map = ( - ['total-registered', 'registered: %s', 'registered'], - ['total-unregistered', 'unregistered: %s', 'unregistered'], - ['total-rejected', 'rejected: %s', 'rejected'], - ['total-unknown', 'unknown: %s', 'unknown'], - ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered'] + ['total-registered', 'registered: %s', 'registered', 'phones.registered.count'], + ['total-unregistered', 'unregistered: %s', 'unregistered', 'phones.unregistered.count'], + ['total-rejected', 'rejected: %s', 'rejected', 'phones.rejected.count'], + ['total-unknown', 'unknown: %s', 'unknown', 'phones.unknown.count'], + ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered', 'phones.partially_registered.count'] ); $self->{maps_counters}->{global} = []; foreach (@map) { my $label = $_->[0]; $label =~ tr/-/_/; - push @{$self->{maps_counters}->{global}}, { label => $_->[0], set => { + push @{$self->{maps_counters}->{global}}, { + label => $_->[0], nlabel => $_->[3], set => { key_values => [ { name => $_->[2] } ], output_template => $_->[1], perfdatas => [ diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/voicemailusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/voicemailusage.pm index 21b410b37..1309dd22d 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/voicemailusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/voicemailusage.pm @@ -24,21 +24,24 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return 'status: ' . $self->{result_values}->{status}; } -sub custom_status_calc { +sub prefix_voicemail_output { my ($self, %options) = @_; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_ccmVMailDevStatus'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_ccmVMailDevName'}; - return 0; + return "Voicemail '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Total '; } sub set_counters { @@ -46,38 +49,38 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, - { name => 'voicemail', type => 1, cb_prefix_output => 'prefix_voicemail_output', message_multiple => 'All voicemails are ok' }, + { name => 'voicemail', type => 1, cb_prefix_output => 'prefix_voicemail_output', message_multiple => 'All voicemails are ok' } ]; $self->{maps_counters}->{voicemail} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'ccmVMailDevStatus' }, { name => 'ccmVMailDevName' } ], - closure_custom_calc => $self->can('custom_status_calc'), + { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => { + key_values => [ { name => 'status' }, { name => 'display' } ], 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 } - }, + } ]; my @map = ( - ['total-registered', 'Registered : %s', 'registered'], - ['total-unregistered', 'Unregistered : %s', 'unregistered'], - ['total-rejected', 'Rejected : %s', 'rejected'], - ['total-unknown', 'Unknown : %s', 'unknown'], - ['total-partiallyregistered', 'Partially Registered : %s', 'partiallyregistered'], + ['total-registered', 'registered: %s', 'registered'], + ['total-unregistered', 'unregistered: %s', 'unregistered'], + ['total-rejected', 'rejected: %s', 'rejected'], + ['total-unknown', 'unknown: %s', 'unknown'], + ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered'] ); $self->{maps_counters}->{global} = []; foreach (@map) { - push @{$self->{maps_counters}->{global}}, { label => $_->[0], nlabel => 'voicemail.devices.total.' . $_->[2] . '.count', set => { + push @{$self->{maps_counters}->{global}}, { + label => $_->[0], nlabel => 'voicemail.devices.total.' . $_->[2] . '.count', set => { key_values => [ { name => $_->[2] } ], output_template => $_->[1], perfdatas => [ - { value => $_->[2] , template => '%s', min => 0 }, - ], + { value => $_->[2] , template => '%s', min => 0 } + ] } - }, + }; } } @@ -85,62 +88,45 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $self->{version} = '1.0'; $options{options}->add_options(arguments => { - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /^registered/' }, }); - + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub prefix_voicemail_output { - my ($self, %options) = @_; - - return "Voicemail '" . $options{instance_value}->{ccmVMailDevName} . "' "; -} - -sub prefix_global_output { - my ($self, %options) = @_; - - return "Total "; -} - my %mapping_status = ( 1 => 'unknown', 2 => 'registered', 3 => 'unregistered', - 4 => 'rejected', 5 => 'partiallyregistered', + 4 => 'rejected', 5 => 'partiallyregistered' ); my $mapping = { - ccmVMailDevDescription => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.4' }, - ccmVMailDevName => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.2' }, - ccmVMailDevStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.5', map => \%mapping_status }, + display => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.2' }, # ccmVMailDevName + description => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.4' }, # ccmVMailDevDescription + status => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.5', map => \%mapping_status } # ccmVMailDevStatus }; - my $oid_ccmVoicemailEntry = '.1.3.6.1.4.1.9.9.156.1.12.1.1'; sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_table(oid => $oid_ccmVoicemailEntry, start => $mapping->{ccmVMailDevName}->{oid}, end => $mapping->{ccmVMailDevStatus}->{oid}, nothing_quit => 1); - + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ccmVoicemailEntry, + start => $mapping->{display}->{oid}, + end => $mapping->{status}->{oid}, + nothing_quit => 1 + ); + $self->{phone} = {}; $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 }; foreach my $oid (keys %$snmp_result) { - next if ($oid !~ /^$mapping->{ccmVMailDevStatus}->{oid}\.(.*)/); + next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - $self->{phone}->{$instance} = { %$result }; - $self->{global}->{$result->{ccmVMailDevStatus}}++; + $self->{phone}->{$instance} = $result; + $self->{global}->{ $result->{status} }++; } } @@ -161,7 +147,7 @@ Example: --filter-counters='status' =item B<--warning-status> -Set warning threshold for status (Default: ''). +Set warning threshold for status. Can used special variables like: %{status}, %{display} =item B<--critical-status> diff --git a/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm b/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm index 41c36c808..773ddc853 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm @@ -30,14 +30,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( + $self->{modes} = { 'ccm-usage' => 'network::cisco::callmanager::snmp::mode::ccmusage', 'cti-usage' => 'network::cisco::callmanager::snmp::mode::ctiusage', 'gateway-usage' => 'network::cisco::callmanager::snmp::mode::gatewayusage', 'mediadevice-usage' => 'network::cisco::callmanager::snmp::mode::mediadeviceusage', 'phone-usage' => 'network::cisco::callmanager::snmp::mode::phoneusage', - 'voicemail-usage' => 'network::cisco::callmanager::snmp::mode::voicemailusage', - ); + 'voicemail-usage' => 'network::cisco::callmanager::snmp::mode::voicemailusage' + }; return $self; }