check_nwc_health icon indicating copy to clipboard operation
check_nwc_health copied to clipboard

mode hardware-health on HH3C mismatches indices of hh3cEntityExtErrorStatus with entity MIB

Open mhahnagsb opened this issue 8 years ago • 0 comments

The mode hardware-health on HH3C platform like HP5900 switches use entPhysicalDescr hh3cEntityExtErrorStatus MIB variables. The code in sub get_sub_table returns an array that is in pseudo random order from the perl built in functions keys and values.

package Classes::HH3C::Component::EnvironmentalSubsystem;
our @ISA = qw(Classes::HH3C::Component::EntitySubsystem);
use strict;

sub init {
  my $self = shift;

  $self->get_entities('Classes::HH3C::Component::EnvironmentalSubsystem::EntityState');

  # ** $self->entities at this time is in pseudo random order. It is not ordered by
  # ** $self->entities->[0]->flat_indices 

  my $i = 0;

  # ** The result of $self->get_sub_table is in another pseudo random order but
  # ** not the same as before as the code assumes.
  # ** This results in different results every time check_nwc_health is called

  foreach my $h ($self->get_sub_table('HH3C-ENTITY-EXT-MIB', [ 'hh3cEntityExtErrorStatus' ])) {
    foreach (keys %$h) {
      next if $_ =~ /indices/;
      @{$self->{entities}}[$i]->{$_} = $h->{$_};
    }
    $i++;
  }
}

I don't understand the structure of the script enough to give the best solution but I tried the following and it seems to work (for me):

sub init {
  my $self = shift;

  $self->get_entities('Classes::HH3C::Component::EnvironmentalSubsystem::EntityState');

  # create a lookup hash table
  my %index;
  my $j = 0;
  foreach my $entity (@{$self->{entities}}) {
    $index{$entity->{flat_indices}} = $j;
    $j++
  }

  my $i = 0;
  foreach my $h ($self->get_sub_table('HH3C-ENTITY-EXT-MIB', [ 'hh3cEntityExtErrorStatus' ])) {
    next unless exists($h->{flat_indices});
    foreach (keys %$h) {
      next if $_ =~ /indices/;
      @{$self->{entities}}[$index{$h->{flat_indices}}]->{$_} = $h->{$_};
    }
    $i++;
  }
}

mhahnagsb avatar Jul 01 '16 10:07 mhahnagsb