#!/usr/bin/perl # # Report info on a list of 3com devices # # Jim Trocki # # $Id: 3cinfo,v 1.3 2000/07/05 20:44:05 trockij Exp $ # # Copyright (C) 1998 Jim Trocki # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use A3Com::Sys; use Getopt::Std; sub help; $COMM = $opt{"c"} || "public"; $SWITCH_LIST = "/home/mis/net/switch-config/switch-list"; %COLORS = ( superStack3900 => "f0f0f0", superStack9300 => "c0c0c0", coreBuilder3500 => "a0a0a0", "" => "808080", ); $CGI = 0; if ($ENV{"REQUEST_METHOD"} eq "GET") { $CGI = 1; if (!open (I, $SWITCH_LIST)) { print <
could not open: $!
EOF exit (1); } while () { next if (/^\s*$/ || /^\s*#/); chomp; push @HOSTS, $_; } close (I); } else { getopts ("hrsc:", \%opt); help() if ($opt{"h"} || @ARGV == 0); @HOSTS = @ARGV; } @l = (); foreach $h (@HOSTS) { ($r, $v) = A3Com::Sys::system_info ( host => $h, community => $COMM, ); if (!defined $r) { $v = { hostname => $h, type => "?", serial_number => "?", id => "?", software_revision => "?", hardware_revision => "?", name => "?", }; } else { $v->{"name"} =~ s/\s+/_/g; } $v->{"hostname"} = $h; push (@l, $v); } if ($opt{"s"} || $CGI) { @l = sort {$a->{"type"} cmp $b->{"type"}} @l; } if (!$CGI) { foreach $v (@l) { if ($opt{"r"}) { write; } else { print join (" ", $v->{"hostname"}, $v->{"type"}, $v->{"serial_number"}, $v->{"id"}, $v->{"software_revision"}, $v->{"hardware_revision"}, $v->{"name"}, ), "\n"; } } } else { print < 3Com switch inventory

3Com switch inventory

All data is gathered in real-time, so this list is up-to-date.

Hostname Type Serial number ID Software rev Hardware rev Name EOF foreach $v (@l) { my $c = $COLORS{$v->{"type"}}; print < $v->{"hostname"} $v->{"type"} $v->{"serial_number"} $v->{"id"} $v->{"software_revision"} $v->{"hardware_revision"} $v->{"name"} EOF } print < EOF } exit; sub help { print <{"hostname"}, $v->{"type"}, $v->{"serial_number"}, $v->{"id"}, $v->{"software_revision"}, $v->{"hardware_revision"}, $v->{"name"} .