1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
#!/usr/bin/perl -w
# $Id: make_dev_matrix.pl,v 1.8 2009/06/07 23:35:06 maxbaker Exp $
$DevMatrix = '../DeviceMatrix.txt';
$DevHTML = 'DeviceMatrix.html';
$DevPNG = 'DeviceMatrix.png';
$Attributes= {};
# Parse Data File
$matrix = parse_data($DevMatrix);
# Graph it for fun
eval "use GraphViz::Data::Structure;";
if ($@) {
print "GraphViz::Data::Structure not installed. $@\n";
} else {
my %graph = ();
foreach my $vendor (sort sort_nocase keys %$matrix){
$graph{$vendor} = {};
foreach my $family (sort sort_nocase keys %{$matrix->{$vendor}->{families}} ){
my @models;
foreach my $mod (keys %{$matrix->{$vendor}->{families}->{$family}->{models}}){
push(@models,split(/\s*,\s*/,$mod));
}
if (scalar @models){
$graph{$vendor}->{$family}=\@models;
} else {
$graph{$vendor}->{$family}=[];
}
}
}
my $now = scalar localtime;
my $gvds = GraphViz::Data::Structure->new(\%graph,Orientation=>'vertical',
Colors=> 'Deep',
graph => {label=>"SNMP::Info and Netdisco Supported Devices \n $now",'fontpath'=>'/usr/local/netdisco','fontname'=>'lucon',concentrate=>'true','overlap'=>'false',spline=>'true',bgcolor=>'wheat'},
node => {fontname=>'lucon'},
);
$gvds->graph()->as_png($DevPNG);
}
print "Creating $DevHTML\n";
open (HTML, "> $DevHTML") or die "Can't open $DevHTML. $!\n";
$old_fh = select(HTML);
&html_head;
print_vendors($matrix);
foreach my $vendor (sort sort_nocase keys %$matrix){
print "<A NAME=\"$vendor\"><SPAN CLASS=\"vendor\"><B>$vendor</B></SPAN></A>\n";
print "<DL>\n";
my $vendor_defaults = $matrix->{$vendor}->{defaults};
print_notes($vendor_defaults,1);
my $families = $matrix->{$vendor}->{families};
foreach my $family (sort sort_nocase keys %$families ) {
print "<DT>$family Family\n";
my $family_defaults = $families->{$family}->{defaults};
print_notes($family_defaults,2);
my $models = $families->{$family}->{models};
foreach my $model (sort sort_nocase keys %$models ){
my $model_defaults = $models->{$model}->{defaults};
print "<DD>$model\n";
print "<DL>\n";
print_notes($model_defaults,3);
print "<DT><DD><TABLE BORDER=1>\n";
print_headers();
print "<TR>\n";
foreach my $a (sort sort_nocase keys %$Attributes) {
my $val;
next if $a eq 'note';
$val = ['-'];
$class = 'none';
if (defined $model_defaults->{$a}) {
$val = $model_defaults->{$a};
$class = 'model';
} elsif (defined $family_defaults->{$a}){
$val = $family_defaults->{$a};
$class = 'family';
} elsif (defined $vendor_defaults->{$a}){
$val = $vendor_defaults->{$a};
$class = 'vendor';
}
print " <TD CLASS='$class'>",join("<BR>\n",@$val),"</TD>\n";
}
print "</TR></TABLE>\n";
print "</DL>\n";
}
}
print "</DL>\n";
}
&html_tail;
select ($old_fh);
close (HTML) or die "Can't write $DevHTML. $!\n";
# Data Structures
# Matrix =
# ( vendor => { families => { family => family_hash },
# defaults => { cmd => [values] },
# }
# )
# Family Hash
# ( models => { model => model_hash },
# defaults => { cmd => [values] }
# )
# Model Hash
# ( defaults => { cmd => [values] } )
sub parse_data {
my $file = shift;
my %ignore = map { $_ => 1 } @_;
my $Matrix;
my @Lines;
open (DM, "< $file") or die "Can't open $file. $!\n";
{
@Lines = <DM>;
}
close (DM);
my ($device,$family,$vendor,$class);
foreach my $line (@Lines){
chomp($line);
# Comments
$line =~ s/#.*//;
# Blank Lines
next if $line =~ /^\s*$/;
# Trim whitespace
$line =~ s/^\s+//;
$line =~ s/\s+$//;
my ($cmd,$value);
if ($line =~ /^([a-z-_]+)\s*:\s*(.*)$/) {
$cmd = $1; $value = $2;
} else {
print "What do i do with this line : $line \n";
next;
}
if (exists $ignore{$cmd}){
print "Ignoring $cmd\n";
}
# Set Class {vendor,family,device}
if ($cmd eq 'device-vendor'){
$vendor = $value;
$family = $model = undef;
$Matrix->{$vendor} = {} unless defined $Matrix->{$vendor};
$class = $Matrix->{$vendor};
$class->{defaults}->{type}='vendor';
next;
}
if ($cmd eq 'device-family'){
$family = $value;
$model = undef;
print "$family has no vendor.\n" unless defined $vendor;
$Matrix->{$vendor}->{families}->{$family} = {}
unless defined $Matrix->{$vendor}->{families}->{$family};
$class = $Matrix->{$vendor}->{families}->{$family};
$class->{defaults}->{type}='family';
next;
}
if ($cmd eq 'device') {
$model = $value;
print "$model has no family.\n" unless defined $family;
print "$model has no vendor.\n" unless defined $vendor;
$Matrix->{$vendor}->{families}->{$family}->{models}->{$model} = {}
unless defined $Matrix->{$vendor}->{families}->{$family}->{models}->{$model};
$class = $Matrix->{$vendor}->{families}->{$family}->{models}->{$model};
$class->{defaults}->{type}='device';
next;
}
# Store attribute
push (@{$class->{defaults}->{$cmd}} , $value);
$Attributes->{$cmd}++;
}
return $Matrix;
}
sub sort_nocase {
return lc($a) cmp lc($b);
}
sub print_notes {
my $defaults = shift;
my $level = shift;
my $notes = $defaults->{note} || [];
foreach my $note (@$notes){
if ($note =~ s/^!//){
$note = '<SPAN CLASS="note">' . $note . '</SPAN>';
}
}
if (scalar @$notes){
print "<DT>\n";
my $print_note = join("\n<LI>",@$notes);
print "<UL TYPE='square'><LI>$print_note</UL>\n";
}
}
sub print_vendors {
my $matrix=shift;
print "<h1>Device Vendors</h1>\n";
foreach my $vendor (sort sort_nocase keys %$matrix){
print "[<A HREF=\"#$vendor\">$vendor</A>]\n";
}
print "<HR>\n";
}
sub html_head {
print <<"end_head";
<HTML>
<HEAD>
<TITLE>SNMP::Info - Device Compatibility Matrix</TITLE>
<STYLE TYPE="text/css" MEDIA="screen">
<!--
BODY { font-family:arial,helvetica,sans-serif; font-size:12pt; }
TD { font-family:arial,helvetica,sans-serif; font-size:10pt; }
TH { font-family:arial,helvetica,sans-serif; font-size:10pt; background:#F0F0F0; }
H1 { font-family:arial,helvetica,sans-serif; font-size:14pt; }
.vendor { font-size:12pt; color:#777777; }
.family { font-size:12pt; color:blue; }
.model { font-size:12pt; color:red; }
.note { color:red; }
//-->
</STYLE>
</HEAD>
<BODY>
<h1>SNMP::Info - Device Compatibility Matrix</h1>
<P>
end_head
}
sub html_tail {
print <<'end_tail';
<HR>
<h1>Color Key</h1>
[<SPAN CLASS="model">Model Attribute</SPAN>]
[<SPAN CLASS="family">Family Attribute</SPAN>]
[<SPAN CLASS="vendor">Vendor Attribute</SPAN>]
<h1>Attribute Key</h1>
A value of <B>-</B> signifies the information is not specified and can
be assumed working.
<TABLE BORDER=1>
<TR>
<TD>Arpnip</TD>
<TD>Ability to collect ARP tables for MAC to IP translation.</TD>
</TR>
<TR>
<TD>CDP</TD>
<TD>Cisco Discovery Protocol usable.
<UL>
<LI><tt>Yes</tt> - Has CDP information through CISCO-CDP-MIB
<LI><tt>Proprietary</tt> means the device has its own L2 Discovery Protocol.
</UL>
</TD>
</TR>
<TR>
<TD>Class</TD>
<TD>SNMP::Info Class the the device currently uses. Devices using more generic
interfaces like <tt>Layer2</tt> or <tt>Layer3</tt> may eventually get their
own subclass.
</TD>
</TR>
<TR>
<TD>Duplex</TD>
<TD>Ability to cull duplex settings from device.<BR>
<UL>
<LI><tt>no</tt> - Can't recover current or admin setting.
<LI><tt>link</tt> - Can get current setting only.
<LI><tt>both</tt> - Can get admin and link setting.
<LI><tt>write</tt> - Can get admin and link setting and perform sets.
</UL>
</TD>
</TR>
<TR>
<TD>Macsuck</TD>
<TD>Ability to get CAM tables for MAC to switch port mapping.<BR>
<UL>
<LI><TT>no</TT> - Have not found an SNMP method to get data yet.
<LI><TT>yes</TT> - Can get through normal SWITCH-MIB method.
<LI><TT>vlan</TT> - Have to re-connect to each VLAN and then fetch with normal
method.
</UL>
</TD>
</TR>
<TR>
<TD>Modules</TD>
<TD>Ability to gather hardware module information.</TD>
</TR>
<TR>
<TD>Portmac</TD>
<TD>Whether the device will list the MAC address of the switch port on each
switch port when doing a Macsuck.
</TD>
</TR>
<TR>
<TD>Ver</TD>
<TD>SNMP Protocol Version the device has to use.</TD>
</TR>
<TR>
<TD>Vlan</TD>
<TD>Ability to get VLAN port assignments.<BR>
<UL>
<LI><TT>no</TT> - Have not found an SNMP method to get data yet.
<LI><TT>yes</TT> - Can read information.
<LI><TT>write</TT> - Can read and write (set).
</UL>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
end_tail
}
sub print_headers {
print "<TR>\n";
foreach my $a (sort sort_nocase keys %$Attributes) {
next if $a eq 'note';
print " <TH>$a</TH>\n";
}
print "</TR>\n";
}
|