nv-l
[Top] [All Lists]

RE: [nv-l] Unused Ports

To: <nv-l@lists.us.ibm.com>
Subject: RE: [nv-l] Unused Ports
From: "Shipley, Rob" <rshipley@mt.gov>
Date: Tue, 7 Jun 2005 15:35:32 -0600
Delivery-date: Tue, 07 Jun 2005 22:36:23 +0100
Envelope-to: nv-l-archive@lists.skills-1st.co.uk
Reply-to: nv-l@lists.us.ibm.com
Sender: owner-nv-l@lists.us.ibm.com
Thread-index: AcVq0W+mLnm28C+LQdmGmiWusAPkYgAzhDrQ
Thread-topic: [nv-l] Unused Ports
You might try a different approach.
I constantly use this SNMP script and it works great. 
You can setup your own interval, ie 10:00am, 2:00pm.
It compares the Oper & Admin OID's to determine if ports are dormant like 
CiscoView.
For example, a port that an user demanded you enable (admin = 1) but has never 
used (oper = 2)!
You may need to change the script to run on Solaris, but it should be very easy.
Have a script remove the *.txt switch files every month and you are set.
This creates a file per switch that shows unused ports since you started the 
script.
I have wanted to setup a Web Console Action to integrate with NetView but time 
is limited.
Enjoy.
--- portstatus.pl script  ----
#!/perl/bin/perl
use Net::SNMP;
use Data::Dumper;
use POSIX;

my @ports;
my @inactports;
my %inact;
my %allports;
#devicename
my ($ip) = $ARGV[0];
#Hostname plus domain
my $hostip = $ip . '.domain.com';
#Output Directory
my $portfile = '/wwwroot/secure/Reports/Ports/' . $ip . '.txt';

############## If the inactive port file exists - get the list 
######################
if (-e $portfile){
        open (PORTFILE, "$portfile");
        while (<PORTFILE>){ 
                if (m/^port/){ 
                        my ($devport,$pname,$thistime) = split(/\;/, $_);
                        $pname =~ s/\//_/; 
                        chop ($thistime);
                        unshift (@inactports,"$pname","$thistime");
                }
        }
        close(PORTFILE);
        %inact = (@inactports);
        #print Dumper(\%inact);
}

my ($session, $error) = Net::SNMP->session(-hostname  => $hostip,-community => 
'public');

if (!defined($session)) { print "$error"; exit 1; }

my $names = $session->get_table('.1.3.6.1.2.1.31.1.1.1.1');
my $adminstatus = $session->get_table('.1.3.6.1.2.1.2.2.1.7');
my $operstatus = $session->get_table('.1.3.6.1.2.1.2.2.1.8');
my $index = $session->get_table('.1.3.6.1.2.1.2.2.1.1');
my $port2index = $session->get_table('.1.3.6.1.2.1.17.1.4.1.2');
foreach (sort {$$index{$a} <=> $$index{$b}} keys %$index){
                $admin = $adminstatus->{".1.3.6.1.2.1.2.2.1.7.$$index{$_}"};
                $oper = $operstatus->{".1.3.6.1.2.1.2.2.1.8.$$index{$_}"};
                $name = $names->{".1.3.6.1.2.1.31.1.1.1.1.$$index{$_}"};
                $displayname = $name;
                $name =~ s/\s//;
                $name =~ s/\//_/;
                if (($admin == 1) && ($oper == 2)){unshift 
(@ports,"$name","unconnected");}
        }
$session->close();
%allports = (@ports);

if (! -e $portfile){ timeit();
                open (PORTFILE, ">$portfile");
                #print PORTFILE "REPORT FOR " . $ip . " at " . $timenow . "\n";
                while (($key,$value) = each(%allports)){ my $pkey = $key; $pkey 
=~ s/_/\//;
                        print PORTFILE "port" . "\;" . $pkey . "\;Inactive 
since " . $timenow . "\n";
                }
                close(PORTFILE);
        }

        else { timeit();
                open (PORTFILE, ">$portfile");
                print PORTFILE "REPORT FOR " . $ip . " at " . $timenow . "\n";
                foreach $key (sort keys(%inact)) {
                        if(exists $allports{$key}){ my $value = $inact{$key}; 
my $pkey = $key;
                                 $pkey =~ s/_/\//;
                                print PORTFILE "port" . "\;" . $pkey . "\;" . 
$value . "\n";
                        } else {
                                print "The port $key has been removed from the  
$ip list\n";
                        }
                }
                close(PORTFILE);
        }

sub timeit{
        my $ampm = 'AM';
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 
localtime(time);
        my @weekdays = qw(Sunday Monday Tuesday Wednesday Thursday Friday 
Saturday);
        my @months = ( "January", "February", "March", "April", "May", "June", 
"July", "August", "September", "October", "November", "December" );

        if ($hour == 12) {$ampm = 'PM';}
        if ($hour > 12) {$hour = $hour - 12;$ampm = 'PM';}
        if (($min >=0) && ($min < 10)){ $min = '0'. $min;}
        my $yearnow = 1900 + $year;
        $timenow = "$hour:$min $ampm on $weekdays[$wday], $months[$mon] $mday, 
$yearnow";
        $timenow;
}
--- End ---
--- Sample Command File ---
/perl/bin/perl portstatus.pl HN6500SW1 1>>/logs/portstatus-change.log 
2>>/logs/portstatus.log
--- End ---
-----Original Message-----
From: owner-nv-l@lists.us.ibm.com [mailto:owner-nv-l@lists.us.ibm.com]On
Behalf Of Meyos Yemveng
Sent: Monday, June 06, 2005 1:53 PM
To: netview Tivoli
Subject: [nv-l] Unused Ports


NV 7.1.3 FP3 SOL 8
I'd like to generate a monthly report for unsused
Cisco Switch Ports (ifInOctets or ifOutOctets < 100
bytes)

Any Ideas ?

Thank You,
Meyos 
"ALLEZ LES LIONS INDOMPTABLES"

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


<Prev in Thread] Current Thread [Next in Thread>

Archive operated by Skills 1st Ltd

See also: The NetView Web