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
|
use strict;
use Data::Dumper;
BEGIN {
unshift @INC, '/PRD/SYDN/perl-lib';
};
use Net::SNMP;
my %ifCount;
my @device=($_);
my $device;
my $ligne;
my %Count;
open FICHIER,"<input.csv " or die "le fichier n existe pas";
while ($ligne = <FICHIER>){
chomp ($ligne);
my $machine;
my $community;
my $groupe;
foreach($ligne) {
%ifCount=0;
($machine,$community,$groupe) = split (/;/,$ligne);
my ($session, $error) = Net::SNMP->session(
-version => 'snmpv2c',
-hostname => $machine,
-community => 'nVNmgAix',
-port => 161 ,
-timeout=> 1
);
if ($error) {print $error; exit}
my $ifIndex = $session->get_table( -baseoid => "1.3.6.1.2.1.2.2.1.1" );
my $ifType = $session->get_table( -baseoid => "1.3.6.1.2.1.2.2.1.3" );
my $ifLabel = $session->get_table( -baseoid => "1.3.6.1.2.1.31.1.1.1.1" );
my $ifOperStatus = $session->get_table( -baseoid => "1.3.6.1.2.1.2.2.1.8" );
foreach my $nbport (values %$ifIndex) {
$ifCount{$device[0]}{glob}++;
next unless $$ifType{'1.3.6.1.2.1.2.2.1.3.'.$nbport} == 6;
$ifCount{$device[0]}{total}++;
$ifCount{$device[0]}{up}++ if $$ifOperStatus{'1.3.6.1.2.1.2.2.1.8.'.$nbport} == 1 ;
}
print "Groupe: $groupe\t".
"Nombre total de ports:$ifCount{$device[0]}{glob}\t".
"Nombre ports Ethernet:$ifCount{$device[0]}{total}\t".
"Port Ethernet UP:$ifCount{$device[0]}{up}\n";
}
}
close FICHIER; |
Partager