diff --git a/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm b/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm index 2c39ef269..310667813 100644 --- a/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm @@ -29,7 +29,7 @@ sub set_oids_label { my ($self, %options) = @_; $self->SUPER::set_oids_label(%options); - $self->{oids_label}->{vdom} = { oid => '.1.3.6.1.4.1.12356.101.7.2.1.1.1', cache => 'reload_cache_vdom_index' }; + $self->{oids_label}->{vdom} = { oid => '.1.3.6.1.4.1.12356.101.7.2.1.1.1', get => 'reload_get_simple', cache => 'reload_cache_vdom_index' }; } sub reload_cache_vdom_index { diff --git a/network/atrica/snmp/mode/connections.pm b/network/atrica/snmp/mode/connections.pm index bc7f2c6f6..a129ca057 100644 --- a/network/atrica/snmp/mode/connections.pm +++ b/network/atrica/snmp/mode/connections.pm @@ -29,8 +29,8 @@ sub set_oids_label { my ($self, %options) = @_; $self->{oids_label} = { - 'atrconncepgendescr' => { oid => '.1.3.6.1.4.1.6110.2.7.5.1.1', cache => 'reload_cache_index_value' }, - 'atrconningdescr' => { oid => '.1.3.6.1.4.1.6110.2.2.1.1.2', cache => 'reload_cache_index_value' }, + 'atrconncepgendescr' => { oid => '.1.3.6.1.4.1.6110.2.7.5.1.1', get => 'reload_get_simple', cache => 'reload_cache_index_value' }, + 'atrconningdescr' => { oid => '.1.3.6.1.4.1.6110.2.2.1.1.2', get => 'reload_get_simple', cache => 'reload_cache_index_value' } }; } diff --git a/network/brocade/snmp/mode/interfaces.pm b/network/brocade/snmp/mode/interfaces.pm index 68cd8ab7e..b99fa7e52 100644 --- a/network/brocade/snmp/mode/interfaces.pm +++ b/network/brocade/snmp/mode/interfaces.pm @@ -32,6 +32,13 @@ sub set_oids_errors { $self->{oid_in_crc} = '.1.3.6.1.4.1.1588.2.1.1.1.6.2.1.22'; # swFCPortRxCrcs } +sub set_oids_label { + my ($self, %options) = @_; + + $self->SUPER::set_oids_label(%options); + $self->{oids_label}->{fcportname} = { oid => '.1.3.6.1.4.1.1588.2.1.1.1.6.2.1.36', get => 'reload_get_fcportname', cache => 'reload_cache_fcportname' }; +} + sub set_counters_errors { my ($self, %options) = @_; @@ -54,8 +61,8 @@ sub set_counters_errors { output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f', perfdatas => [ { label => 'laser_temp', template => '%.2f', - unit => 'C', label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'C', label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => { @@ -63,8 +70,8 @@ sub set_counters_errors { output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s', perfdatas => [ { label => 'input_power', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'dBm', label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => { @@ -72,8 +79,8 @@ sub set_counters_errors { output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s', perfdatas => [ { label => 'output_power', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'dBm', label_extra_instance => 1, instance_use => 'display' } + ] } } ; @@ -103,6 +110,35 @@ sub reload_cache_custom { } } +sub reload_get_fcportname { + my ($self, %options) = @_; + + $options{snmp_get}->{fcportname} = { oid => $self->{oids_label}->{fcportname}->{oid} }; + $options{snmp_get}->{ifname} = { oid => $self->{oids_label}->{ifname}->{oid} }; +} + +sub reload_cache_fcportname { + my ($self, %options) = @_; + + # I cheat. Yes i can ;) change swFCPortIndex to ifIndex + my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0; + foreach (keys %{$options{result}->{ $self->{oids_label}->{ifname}->{oid} }}) { + /^$self->{oids_label}->{ifname}->{oid}\.(.*)$/; + my $if_index = $1; + push @{$options{datas}->{all_ids}}, $if_index if ($store_index == 1); + if ($options{result}->{ $self->{oids_label}->{ifname}->{oid} }->{$_} =~ /\d+\/(\d+)$/) { + $options{datas}->{ $options{name} . '_' . $if_index } = $self->{output}->to_utf8( + $options{result}->{ $self->{oids_label}->{ $options{name} }->{oid} }->{ $self->{oids_label}->{ $options{name} }->{oid} . '.' . ($1 + 1) } + ); + } else { + # we use ifname if there is no fcportname + $options{datas}->{ $options{name} . '_' . $if_index } = $self->{output}->to_utf8( + $options{result}->{ $self->{oids_label}->{ifname}->{oid} }->{$_} + ); + } + } +} + sub map_brocade { my ($self, %options) = @_; @@ -114,8 +150,9 @@ sub map_brocade { }; # swFCPortIndex can be found with ifName ("0/2") or ifDesc ("FC port 0/2") foreach (@{$self->{array_interface_selected}}) { - my $value = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_filter} . '_' . $_); - if ($value =~ /\d+\/(\d+)$/) { + my $value = $self->{statefile_cache}->get(name => 'ifname_' . $_); + $value = $self->{statefile_cache}->get(name => 'ifdesc_' . $_) if (!defined($value)); + if (defined($value) && $value =~ /\d+\/(\d+)$/) { my $port_index = $1 + 1; $self->{map_brocade}->{port2if}->{$port_index} = $_; $self->{map_brocade}->{if2port}->{$_} = $port_index; @@ -136,10 +173,11 @@ sub load_errors { ); $self->map_brocade(); + my $indexes = [keys %{$self->{map_brocade}->{port2if}}]; $self->{snmp}->load( oids => [ $self->{oid_in_crc} ], - instances => [keys %{$self->{map_brocade}->{port2if}}] - ); + instances => $indexes + ) if (scalar(@$indexes) > 0); } my $oid_optical_laser_temp = '.1.3.6.1.4.1.1588.2.1.1.1.28.1.1.1'; # swSfpTemperature @@ -317,11 +355,11 @@ Time in minutes before reloading cache file (default: 180). =item B<--oid-filter> -Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). +Choose OID used to filter interface (default: ifName) (values: fcPortName, ifDesc, ifAlias, ifName, IpAddr). =item B<--oid-display> -Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). +Choose OID used to display interface (default: ifName) (values: fcPortName, ifDesc, ifAlias, ifName, IpAddr). =item B<--oid-extra-display> diff --git a/network/mrv/optiswitch/snmp/mode/interfaces.pm b/network/mrv/optiswitch/snmp/mode/interfaces.pm index f2cd1e64a..2dad8b972 100644 --- a/network/mrv/optiswitch/snmp/mode/interfaces.pm +++ b/network/mrv/optiswitch/snmp/mode/interfaces.pm @@ -96,17 +96,6 @@ sub set_key_values_status { return [ { name => 'linkstatus' }, { name => 'opstatus' }, { name => 'admstatus' }, { name => 'duplexstatus' }, { name => 'display' } ]; } -sub set_oids_label { - my ($self, %options) = @_; - - $self->{oids_label} = { - 'ifdesc' => { oid => '.1.3.6.1.2.1.2.2.1.2', cache => 'reload_cache_index_value' }, - 'ifalias' => { oid => '.1.3.6.1.2.1.31.1.1.1.18', cache => 'reload_cache_index_value' }, - 'ifname' => { oid => '.1.3.6.1.2.1.31.1.1.1.1', cache => 'reload_cache_index_value', }, - 'ipaddr' => { oid => '.1.3.6.1.2.1.4.20.1.2', cache => 'reload_cache_values_index', }, - }; -} - sub set_oids_status { my ($self, %options) = @_; diff --git a/snmp_standard/mode/interfaces.pm b/snmp_standard/mode/interfaces.pm index 1e8994ef1..1e5e3ef05 100644 --- a/snmp_standard/mode/interfaces.pm +++ b/snmp_standard/mode/interfaces.pm @@ -619,10 +619,10 @@ sub set_oids_label { my ($self, %options) = @_; $self->{oids_label} = { - 'ifdesc' => { oid => '.1.3.6.1.2.1.2.2.1.2', cache => 'reload_cache_index_value' }, - 'ifalias' => { oid => '.1.3.6.1.2.1.31.1.1.1.18', cache => 'reload_cache_index_value' }, - 'ifname' => { oid => '.1.3.6.1.2.1.31.1.1.1.1', cache => 'reload_cache_index_value' }, - 'ipaddr' => { oid => '.1.3.6.1.2.1.4.20.1.2', cache => 'reload_cache_values_index' } + 'ifdesc' => { oid => '.1.3.6.1.2.1.2.2.1.2', get => 'reload_get_simple', cache => 'reload_cache_index_value' }, + 'ifalias' => { oid => '.1.3.6.1.2.1.31.1.1.1.18', get => 'reload_get_simple', cache => 'reload_cache_index_value' }, + 'ifname' => { oid => '.1.3.6.1.2.1.31.1.1.1.1', get => 'reload_get_simple', cache => 'reload_cache_index_value' }, + 'ipaddr' => { oid => '.1.3.6.1.2.1.4.20.1.2', get => 'reload_get_simple', cache => 'reload_cache_values_index' } }; } @@ -935,14 +935,20 @@ sub reload_cache_values_index { foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) { /^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/; push @{$options{datas}->{all_ids}}, $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_} if ($store_index == 1); - if (defined($options{datas}->{$options{name} . "_" . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}})) { - $options{datas}->{$options{name} . "_" . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}} .= ', ' . $1; + if (defined($options{datas}->{$options{name} . '_' . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}})) { + $options{datas}->{$options{name} . '_' . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}} .= ', ' . $1; } else { - $options{datas}->{$options{name} . "_" . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}} = $1; + $options{datas}->{$options{name} . '_' . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}} = $1; } } } +sub reload_get_simple { + my ($self, %options) = @_; + + $options{snmp_get}->{ $options{name} } = { oid => $self->{oids_label}->{ $options{name} }->{oid} }; +} + sub reload_cache { my ($self) = @_; @@ -953,20 +959,21 @@ sub reload_cache { $datas->{last_timestamp} = time(); $datas->{all_ids} = []; - my $snmp_get = [ - { oid => $self->{oids_label}->{$self->{option_results}->{oid_filter}}->{oid} }, - ]; - if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) { - push @{$snmp_get}, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}}->{oid} }; + my ($snmp_get, $func) = ({}); + if ($func = $self->can($self->{oids_label}->{ $self->{option_results}->{oid_filter} }->{get})) { + $func->($self, snmp_get => $snmp_get, name => $self->{option_results}->{oid_filter}); + } + if ($func = $self->can($self->{oids_label}->{ $self->{option_results}->{oid_display} }->{get})) { + $func->($self, snmp_get => $snmp_get, name => $self->{option_results}->{oid_display}); + } + if (defined($self->{option_results}->{oid_extra_display}) && + ($func = $self->can($self->{oids_label}->{ $self->{option_results}->{oid_extra_display} }->{get}))) { + $func->($self, snmp_get => $snmp_get, name => $self->{option_results}->{oid_extra_display}); } - if (defined($self->{option_results}->{oid_extra_display}) && $self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_display} && - $self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_filter}) { - push @{$snmp_get}, { oid => $self->{oids_label}->{$self->{option_results}->{oid_extra_display}}->{oid} }; - } - my $result = $self->{snmp}->get_multiple_table(oids => $snmp_get); + my $result = $self->{snmp}->get_multiple_table(oids => [values %$snmp_get]); - my $func = $self->can($self->{oids_label}->{ $self->{option_results}->{oid_filter} }->{cache}); + $func = $self->can($self->{oids_label}->{ $self->{option_results}->{oid_filter} }->{cache}); $func->($self, result => $result, datas => $datas, name => $self->{option_results}->{oid_filter}, store_index => 1); if (my $custom = $self->can('reload_cache_custom')) {