From 0ba84fbbbfbd207aa1b758a69955a1c1f6052fc8 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Thu, 12 Nov 2020 14:24:34 +0100 Subject: [PATCH] enhance cisco wireless (#2342) --- .../common/airespace/snmp/mode/apstatus.pm | 90 +++++++++------ .../common/cisco/standard/snmp/mode/wan3g.pm | 106 +++++++++--------- 2 files changed, 109 insertions(+), 87 deletions(-) diff --git a/centreon/common/airespace/snmp/mode/apstatus.pm b/centreon/common/airespace/snmp/mode/apstatus.pm index 3d0922502..aa68afb99 100644 --- a/centreon/common/airespace/snmp/mode/apstatus.pm +++ b/centreon/common/airespace/snmp/mode/apstatus.pm @@ -24,15 +24,23 @@ 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 = $self->{result_values}->{admstatus} eq 'disabled' ? 'is disabled' : 'status: ' . $self->{result_values}->{opstatus}; + my $msg = $self->{result_values}->{admstatus} eq 'disable' ? 'is disabled' : ('status: ' . $self->{result_values}->{opstatus}); return $msg; } +sub custom_radio_channel_util_calc { + my ($self, %options) = @_; + + return -10 if ($options{new_datas}->{$self->{instance} . '_admstatus'} eq 'disable'); + $self->{result_values}->{channels_util} = $options{new_datas}->{$self->{instance} . '_channels_util'}; + return 0; +} + sub skip_global { my ($self, %options) = @_; @@ -120,18 +128,26 @@ sub set_counters { ]; $self->{maps_counters}->{ap_global} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/', set => { key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { 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 } } ]; $self->{maps_counters}->{interfaces} = [ + { label => 'radio-status', type => 2, critical_default => '%{admstatus} eq "enable" and %{opstatus} eq "down"', set => { + key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { 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 => 'radio-interface-channels-utilization', nlabel => 'accesspoint.radio.interface.channels.utilization.percentage', set => { - key_values => [ { name => 'channels_util' } ], + key_values => [ { name => 'channels_util' }, { name => 'admstatus' } ], + closure_custom_calc => $self->can('custom_radio_channel_util_calc'), output_template => 'channels utilization: %s %%', perfdatas => [ { label => 'radio_interface_channels_utilization', template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1 } @@ -149,21 +165,12 @@ sub new { $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'filter-group:s' => { name => 'filter_group' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/' }, 'add-radio-interfaces' => { name => 'add_radio_interfaces' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - my $map_admin_status = { 1 => 'enable', 2 => 'disable' @@ -173,16 +180,25 @@ my $map_operation_status = { 2 => 'disassociating', 3 => 'downloading' }; +my $map_radio_operation_status = { + 1 => 'down', + 2 => 'up' +}; + my $mapping = { - bsnAPName => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, - bsnAPGroupVlanName => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } + ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName + group_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } # bsnAPGroupVlanName }; my $mapping2 = { - bsnAPOperationStatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.6', map => $map_operation_status }, - bsnAPAdminStatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.37', map => $map_admin_status } + opstatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.6', map => $map_operation_status }, # bsnAPOperationStatus + admstatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.37', map => $map_admin_status } # bsnAPAdminStatus +}; +my $mapping3 = { + opstatus => { oid => '.1.3.6.1.4.1.14179.2.2.2.1.12', map => $map_radio_operation_status }, # bsnAPIfOperStatus + admstatus => { oid => '.1.3.6.1.4.1.14179.2.2.2.1.34', map => $map_admin_status }, # bsnAPIfAdminStatus + channels_util => { oid => '.1.3.6.1.4.1.14179.2.2.13.1.3' } # bsnAPIfLoadChannelUtilization }; my $oid_agentInventoryMachineModel = '.1.3.6.1.4.1.14179.1.1.1.3'; -my $oid_bsnAPIfLoadChannelUtilization = '.1.3.6.1.4.1.14179.2.2.13.1.3'; sub manage_selection { my ($self, %options) = @_; @@ -190,8 +206,8 @@ sub manage_selection { $self->{ap} = {}; $self->{global} = { total => 0, associated => 0, disassociating => 0, downloading => 0, enable => 0, disable => 0 }; - my $request = [ { oid => $oid_agentInventoryMachineModel }, { oid => $mapping->{bsnAPName}->{oid} } ]; - push @$request, { oid => $mapping->{bsnAPGroupVlanName}->{oid} } + my $request = [ { oid => $oid_agentInventoryMachineModel }, { oid => $mapping->{ap_name}->{oid} } ]; + push @$request, { oid => $mapping->{group_name}->{oid} } if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne ''); my $snmp_result = $options{snmp}->get_multiple_table( @@ -206,25 +222,25 @@ sub manage_selection { ); foreach (keys %$snmp_result) { - next if (! /^$mapping->{bsnAPName}->{oid}\.(.*)/); + next if (! /^$mapping->{ap_name}->{oid}\.(.*)/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $result->{bsnAPName} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{bsnAPName} . "'.", debug => 1); + $result->{ap_name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1); next; } if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' && - $result->{bsnAPGroupVlanName} !~ /$self->{option_results}->{filter_group}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{bsnAPName} . "'.", debug => 1); + $result->{group_name} !~ /$self->{option_results}->{filter_group}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1); next; } - $self->{ap}->{ $result->{bsnAPName} } = { + $self->{ap}->{ $result->{ap_name} } = { instance => $instance, - display => $result->{bsnAPName}, - ap_global => { display => $result->{bsnAPName} }, + display => $result->{ap_name}, + ap_global => { display => $result->{ap_name} }, interfaces => {} }; } @@ -242,24 +258,26 @@ sub manage_selection { $snmp_result = $options{snmp}->get_leef(); my $snmp_result_radio; - $snmp_result_radio = $options{snmp}->get_table(oid => $oid_bsnAPIfLoadChannelUtilization) + $snmp_result_radio = $options{snmp}->get_multiple_table(oids => [map({ oid => $_->{oid} }, values(%$mapping3))], return_type => 1) if (defined($self->{option_results}->{add_radio_interfaces})); + foreach (keys %{$self->{ap}}) { my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $self->{ap}->{$_}->{instance}); $self->{global}->{total}++; - $self->{global}->{$result->{bsnAPOperationStatus}}++; - $self->{global}->{$result->{bsnAPAdminStatus}}++; - $self->{ap}->{$_}->{ap_global}->{opstatus} = $result->{bsnAPOperationStatus}; - $self->{ap}->{$_}->{ap_global}->{admstatus} = $result->{bsnAPAdminStatus}; + $self->{global}->{ $result->{opstatus} }++; + $self->{global}->{ $result->{admstatus} }++; + $self->{ap}->{$_}->{ap_global}->{opstatus} = $result->{opstatus}; + $self->{ap}->{$_}->{ap_global}->{admstatus} = $result->{admstatus}; next if (!defined($self->{option_results}->{add_radio_interfaces})); foreach my $oid (keys %$snmp_result_radio) { - next if ($oid !~ /^$oid_bsnAPIfLoadChannelUtilization\.$self->{ap}->{$_}->{instance}\.(\d+)/); + next if ($oid !~ /^$mapping3->{admstatus}->{oid}\.$self->{ap}->{$_}->{instance}\.(\d+)/); + my $result_radio = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result_radio, instance => $self->{ap}->{$_}->{instance} . '.' . $1); $self->{ap}->{$_}->{interfaces}->{$1} = { display => $1, - channels_util => $snmp_result_radio->{$oid} + %$result_radio }; } } diff --git a/centreon/common/cisco/standard/snmp/mode/wan3g.pm b/centreon/common/cisco/standard/snmp/mode/wan3g.pm index 8722adb2e..1a42c6fb2 100644 --- a/centreon/common/cisco/standard/snmp/mode/wan3g.pm +++ b/centreon/common/cisco/standard/snmp/mode/wan3g.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use Digest::MD5 qw(md5_hex); sub custom_connection_status_output { @@ -49,8 +49,11 @@ sub custom_modem_status_output { my ($self, %options) = @_; return sprintf( - 'modem status: %s', - $self->{result_values}->{modem_status} + 'modem status: %s [imsi: %s][imei: %s][iccid: %s]', + $self->{result_values}->{modem_status}, + $self->{result_values}->{imsi}, + $self->{result_values}->{imei}, + $self->{result_values}->{iccid} ); } @@ -101,28 +104,45 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'modem-status', threshold => 0, set => { - key_values => [ { name => 'modem_status' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, + { + label => 'modem-status', + type => 2, + unknown_default => '%{modem_status} =~ /unknown/i', + warning_default => '%{modem_status} =~ /lowPowerMode/i', + critical_default => '%{modem_status} =~ /offLine/i', + set => { + key_values => [ + { name => 'modem_status' }, { name => 'imsi' }, + { name => 'imei' }, { name => 'iccid' }, + { name => 'display' } + ], closure_custom_output => $self->can('custom_modem_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'connection-status', threshold => 0, set => { + { + label => 'connection-status', + type => 2, + unknown_default => '%{connection_status} =~ /unknown/i', + critical_default => '%{connection_status} =~ /inactive|idle|disconnected|error/i', + set => { key_values => [ { name => 'connection_status' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_connection_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'sim-status', threshold => 0, set => { + { + label => 'sim-status', + type => 2, + unknown_default => '%{sim_status} =~ /unknown/i', + critical_default => '%{sim_status} !~ /ok|unknown/i', + set => { key_values => [ { name => 'sim_status' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_sim_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'temperature', nlabel => 'modem.temperature.celsius', display_ok => 0, set => { @@ -138,12 +158,16 @@ sub set_counters { ]; $self->{maps_counters}->{radio} = [ - { label => 'radio-status', threshold => 0, set => { + { + label => 'radio-status', + type => 2, + unknown_default => '%{current_band} =~ /unknown/i', + critical_default => '%{current_band} =~ /invalid|none/i', + set => { key_values => [ { name => 'current_band' }, { name => 'channel_number' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_radio_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'radio-rssi', nlabel => 'modem.radio.rssi.dbm', set => { @@ -159,12 +183,16 @@ sub set_counters { ]; $self->{maps_counters}->{network} = [ - { label => 'network-status', threshold => 0, set => { + { + label => 'network-status', + type => 2, + unknown_default => '%{service_status} =~ /unknown/i', + critical_default => '%{service_status} =~ /emergencyOnly|noService/i', + set => { key_values => [ { name => 'service_status' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_network_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'traffic-in', nlabel => 'modem.traffic.in.bitspersecond', set => { @@ -194,42 +222,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, - 'unknown-modem-status:s' => { name => 'unknown_modem_status', default => '%{modem_status} =~ /unknown/i' }, - 'warning-modem-status:s' => { name => 'warning_modem_status', default => '%{modem_status} =~ /lowPowerMode/i' }, - 'critical-modem-status:s' => { name => 'critical_modem_status', default => '%{modem_status} =~ /offLine/i' }, - 'unknown-connection-status:s' => { name => 'unknown_connection_status', default => '%{connection_status} =~ /unknown/i' }, - 'warning-connection-status:s' => { name => 'warning_connection_status', default => '' }, - 'critical-connection-status:s' => { name => 'critical_connection_status', default => '%{connection_status} =~ /inactive|idle|disconnected|error/i' }, - 'unknown-sim-status:s' => { name => 'unknown_sim_status', default => '%{sim_status} =~ /unknown/i' }, - 'warning-sim-status:s' => { name => 'warning_sim_status', default => '' }, - 'critical-sim-status:s' => { name => 'critical_sim_status', default => '%{sim_status} !~ /ok|unknown/i' }, - 'unknown-radio-status:s' => { name => 'unknown_radio_status', default => '%{current_band} =~ /unknown/i' }, - 'warning-radio-status:s' => { name => 'warning_radio_status', default => '' }, - 'critical-radio-status:s' => { name => 'critical_radio_status', default => '%{current_band} =~ /invalid|none/i' }, - 'unknown-network-status:s' => { name => 'unknown_network_status', default => '%{service_status} =~ /unknown/i' }, - 'warning-network-status:s' => { name => 'warning_network_status', default => '' }, - 'critical-network-status:s' => { name => 'critical_network_status', default => '%{service_status} =~ /emergencyOnly|noService/i' } + 'filter-name:s' => { name => 'filter_name' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros( - macros => [ - 'unknown_modem_status', 'warning_modem_status', 'critical_modem_status', - 'unknown_connection_status', 'warning_connection_status', 'critical_connection_status', - 'unknown_sim_status', 'warning_sim_status', 'critical_sim_status', - 'unknown_radio_status', 'warning_radio_status', 'critical_radio_status', - 'unknown_network_status', 'warning_network_status', 'critical_network_status', - ] - ); -} - my $map_current_band = { 1 => 'unknown', 2 => 'invalid', 3 => 'none', 4 => 'gsm850', 5 => 'gsm900', 6 => 'gsm1800', @@ -260,13 +258,16 @@ my $mapping = { rssi => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.1' }, # c3gCurrentGsmRssi current_band => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.3', map => $map_current_band }, # c3gGsmCurrentBand channel_number => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.4' }, # c3gGsmChannelNumber + imsi => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.1' }, # c3gImsi + imei => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.2' }, # c3gImei + iccid => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.3' }, # c3gIccId modem_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6', map => $map_modem_status }, # c3gModemStatus temperature => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.12' }, # c3gModemTemperature connection_status => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.8', map => $map_connection_status }, # c3gConnectionStatus sim_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.5.1.1.2', map => $map_sim_status }, # c3gGsmSimStatus service_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.2', map => $map_service_status }, # c3gGsmCurrentServiceStatus traffic_out => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.19' }, # c3gGsmTotalByteTransmitted - traffic_in => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.20' }, # c3gGsmTotalByteReceived + traffic_in => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.20' } # c3gGsmTotalByteReceived }; sub manage_selection { @@ -322,6 +323,9 @@ sub manage_selection { foreach (keys %{$self->{modem}}) { my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); $self->{modem}->{$_}->{global}->{modem_status} = $result->{modem_status}; + $self->{modem}->{$_}->{global}->{imsi} = $result->{imsi}; + $self->{modem}->{$_}->{global}->{imei} = $result->{imei}; + $self->{modem}->{$_}->{global}->{iccid} = $result->{iccid}; $self->{modem}->{$_}->{global}->{connection_status} = $result->{connection_status}; $self->{modem}->{$_}->{global}->{sim_status} = $result->{sim_status}; $self->{modem}->{$_}->{global}->{temperature} = $result->{temperature};