Device Module View

Note: this is a development view and is for debug purposes only. If has been incorporated into device.html already.


% foreach my $key (sort { $a <=> $b } keys %modules) { % if (!$printed{$key}) { <& SELF:dump_module, id=>$key &> % } % }
% print Dumper(\%modules);
<%args> $ip => '' # Can be IP or hostname <%shared> my %modules = {}; my %printed = {}; my $device; <%init> #XXX use Data::Dumper; if ($ip) { # Save Search Term my $match = $ip; # Resolve input my $hostname = &hostname($ip); my $ip = &getip($ip); # Check if we're an alias of another device my $devip = &root_device($ip); # redirect to search if no match $m->redirect("device_search.html?text=$match") unless $devip; # Grab Device INFO $device = sql_hash('device', ['ip','extract(epoch from creation) as creation','dns', 'description','uptime','contact','name','location','layers', 'ports','mac','serial','model','ps1_type','ps2_type','ps1_status', 'ps2_status','fan','slots','vendor','log','os_ver','os','vtp_domain', 'extract(epoch from last_discover) as last_discover', 'extract(epoch from last_macsuck) as last_macsuck', 'extract(epoch from last_arpnip) as last_arpnip' ], {'ip'=>$devip}); my $modules = sql_rows('device_module',['*'],{'ip'=>$devip},0,'order by parent,pos,index') || []; foreach my $module (@$modules) { $modules{$module->{index}}{module} = $module; if ($module->{parent}) { # this is wrong. a given parent can # have multiple items at a single pos value. # (HP may have gotten this wrong, but that's # reality...) # # Next wrong: some things have weird pos' # index | description | type | parent | class | pos #-------+----------------------------------------+---------------------+--------+---------+----- # 1 | Cisco Aironet 1200 Series Access Point | cevChassisAIRAP1210 | 0 | chassis | -1 # 3 | PowerPC405GP Ethernet | cevPortFEIP | 1 | port | -1 # 2 | 802.11G Radio | cevPortUnknown | 1 | port | 0 $module->{pos} = 0 if ($module->{pos} < 0); #$m->out(%$module."
\n"); if ($module->{pos}) { ${$modules{$module->{parent}}{children}{$module->{class}}}[$module->{pos}] = $module->{index}; } else { push(@{$modules{$module->{parent}}{children}{$module->{class}}}, $module->{index}); } } else { push(@{$modules{root}}, $module->{index}); } } } else { $m->redirect("device_search.html"); } <%method dump_module> <%args> $id
  • <%perl> return if ($id eq 'root'); if (!defined($modules{$id})) { print "can't get module $id\n"; print Dumper($id); return; } $printed{$id}++; my $mod = $modules{$id}{module}; <% $mod->{description} %> (<% $mod->{name} %>) % if ($mod->{port}) { (<% $mod->{port} %>) % } % for my $f (qw(fw hw sw)) { % if ($mod->{"${f}_ver"}) { [<%$f%>: <%$mod->{"${f}_ver"}%>] % } % } % if ($mod->{serial}) { [serial: <%$mod->{serial}%>] % } / <% $mod->{type} %> / <% $mod->{vendor} %> <% $mod->{model} %> % if ($mod->{fru}) { [FRU] % } // <% $mod->{class} %> % #print join(" | ", keys %$mod); % if ($modules{$id}{children}) { % }
  • %# $Id$ %# vim:syntax=mason