package DeviceReport::SWITCH2;
use System;
use strict;
use DeviceReport;
use base 'DeviceReport';


# xml for GUI Interface

sub xmlSummary {
   my($class, $report, $q) = @_;

  my $rep = $report->content();
  my $summary = $q->{summary};
  my (%S);

  my $out = "<REPORT>\n";
  $out .= " <CONTENT>\n";

  my $key0 = $rep->{"id.device_key"};
  my $product_name = $rep->{'info.Product'} || $rep->{"system.sysDescr"};

  $S{HEADER} =   {
                  device_key   => { order => 1 , value => $rep->{"id.device_key"}       },
                  device_label => { order => 2 , value => $rep->{"id.device_userLabel"} },
                  device_ip    => { order => 3 , value => $rep->{"id.device_ipno"} },
                  product_name => { order => 4 , value => $product_name },

                 };
  $S{SAN} = $class->san_info($report);

  my $version = $rep->subset("info.version.");
  my $order = 5;
  foreach my $x (sort keys %$version) {
     $S{HEADER}{$x} = { order => $order , value => $version->{$x} },
     $order++;
  }



  $S{FRU}{"enclosure"} = {  name=> $rep->{"id.device_name"},
                            id  => 1,
                        status  => $report->status(),
                          type  => $rep->{"id.device_type"},
                       revision => $rep->{"info.version.Active_Firmware_image"},
                         serial => $rep->{"id.device_wwn"},
                          model => $rep->{"id.device_userLabel"},
                          vendor=> "SUN",
                       keyLabel => "WWN",
                       keyValue => $key0,
                           };

  foreach my $el (sort keys %$rep) {
       my @L = split(/\./, $el);
       my $x  = "$L[0].$L[1].$L[2]";

       if (!$summary) {
          if ($L[0] eq "sensor" && $L[3] eq "message") {
            my $key = "$key0.$L[1].$L[2]";
            $S{COMPONENT}{$x} = {  name  => $x ,
                               id  => $x ,
                           status  => $rep->{"$x.status"},
                             type  => $L[1],
                          revision => "",
                            serial => "",
                             model => "",
                            vendor => "SUN",
                          keyLabel => "ID",
                          keyValue => $key,
                           };

          } elsif ($L[0] eq "port" && $L[2] eq "state") {
              $x = "$L[0].$L[1]";
              my $displaySummary = "name,state,status,type,speed,serial";
              my $wwn = $rep->{"id.wwn"}  || "000000";
              $S{PORT}{$x} = {  name  => $x,
                                 id  => $x,
                              state  => $rep->{"$x.state"},
                             status  => $rep->{"$x.state.AdmStatus"},
                               type  => $rep->{"$x.type"},
                               speed => $rep->{"$x.speed"},
                           keyLabel  => "ID",
                           keyValue  => $rep->{"id.wwn"} . ".$x",
                           serial    => sprintf("%2s%2.2d%s", substr($wwn,0,2), $L[1], substr($wwn,4)),
                             summary => $displaySummary,
                            };

          } elsif ($L[0] eq "info") {
              $x = "$L[0].$L[1]";
              my $val = $rep->{$el};
              $S{SYSTEM}{$x} = { value => $val };

          } elsif ($L[0] eq "system") {
              $x = "$L[0].$L[1]";
              if (index("uptime,sysUpTime,sysObjectID,sysDescr,sysLocation,sysName,sysContact", $L[1]) >= 0) {
                my $val = $rep->{$el};
                $val =~ s/[\<\>]//g;
                $S{SYSTEM}{$x} = { value => $val };
              }

          } elsif ($L[0] eq "id") {
              $x = "$L[0].$L[1]";
              $S{ID}{$x} = { value => $rep->{$el} };

          } else {
              #$S{OTHER}{$x} = 1;
          }
       } elsif (substr($el,0, length($summary)) eq $summary) {
          $out .= "   <VALUE ID=\"$el\">$rep->{$el}</VALUE>\n";
       }
  }

  if (!$summary) {
    $out .= DeviceReport->xml(\%S, "ID,SYSTEM");
  }
  $out .= " </CONTENT>\n";
  $out .= "</REPORT>\n";
  return (\%S, $out);
}




#    'SFC.Front5.Attention' => '0',
#    'SFC.Front5.CardNum' => '5',
#    'SFC.Front5.Class' => 'Switch Fabric Card',
#    'SFC.Front5.DateOfMfg' => '06-13-2003',
#    'SFC.Front5.HWRev' => 'AF',
#    'SFC.Front5.MACAddr' => '00:01:5D:00:3F:FF',
#    'SFC.Front5.MACCnt' => '0',
#    'SFC.Front5.NumCpus' => '1',
#    'SFC.Front5.NumPorts' => '0',
#    'SFC.Front5.PCBRev' => '04',
#    'SFC.Front5.Panel' => 'Front',
#    'SFC.Front5.PartNumber' => '720-00014-04',
#    'SFC.Front5.Power' => '1',
#    'SFC.Front5.Ready' => 'Ready',
#    'SFC.Front5.SerialNumber' => '500077',
#    'SFC.Front5.State' => 'Normal',
#    'SFC.Front5.TempF' => '111',
#    'SFC.Front5.Type' => 'SFC_1',



1;
