Bonjour,

J ai réalisé un script qui qui va parcouri un fichier csv (qu'on me donne) et qui va pour chaque ligne de ce fichier CSV compter les ports de machine qui sont dans ce fichier csv.Il y a une machine par ligne.

Si j ai 5 ligne dans le CSV, il va me retourner les ports pour les 5 machines. J aimerais bien que quand une machine se retrouve sur plusieurs lignes, il fasse la somme des ports.

Voici le code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
use strict;
use Data::Dumper;
 
BEGIN {
	unshift @INC, '/PRD/SYDN/perl-lib';
};
 
use Net::SNMP;
 
my %ifCount;
my $ifCount;
my $ligne;
my $tot;
my $up;
my $ethernet;
my %Count;
my $Count;
my $groupe;
 
 
 
 
open FICHIER,"<input.csv " or die "le fichier n existe pas";
 
while ($ligne = <FICHIER>){
	chomp ($ligne);
 
		my $machine;
		my $community;
 
 
		%Count=0;
 
		($machine,$community,$groupe) = split (/;/,$ligne);
 
 
		my ($session, $error) = Net::SNMP->session(
			      -version     => 'snmpv2c',
			      -hostname    => $machine,
			      -community   => $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 $ifOperStatus		= $session->get_table(	-baseoid => "1.3.6.1.2.1.2.2.1.8" );
 
 
		#On va compter les porte totale, ethernet et ethernet UP
 
 
	foreach  my $C (values %$ifIndex){
 
 
		  $Count{glob}++;
		  next unless $$ifType{'1.3.6.1.2.1.2.2.1.3.'.$C} == 6; 
    		  $Count{Ethernet_tot}++;
                  $Count{up}++   if $$ifOperStatus{'1.3.6.1.2.1.2.2.1.8.'.$C} == 1 ;
 
		#on pourrait les mettres dans $tot $up $etherup
 
		  $tot = $Count{glob};
		  $up  = $Count{up};
		  $ethernet = $Count{Ethernet_tot};
 
		#Afficher 0 quand il n'y a pas de port UP
 
	if ($up == 0) 
		{$up ="0";}
 
				}
 
		#on va stocker le résultats dans ifCount.
 
			 $ifCount{$groupe}{tot}= $tot;
		  	 $ifCount{$groupe}{up}= $up;
		  	 $ifCount{$groupe}{ethernet}= $ethernet;
 
 
		print 	"$groupe \t".
			"Port tot:$tot  \t". 
			"Ethernet:$ethernet  \t".
			"Ethernet up:$up  \n";
 
	}
 
 
		print Dumper( \%ifCount);	
 
close FICHIER;

Merci,

Mimiche