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
| use strict;
use warnings;
use feature 'say';
use Data::Dumper;
no warnings 'uninitialized';
use Spreadsheet::Read;
use Net::Ping::External qw(ping); # NEt::PIng ne fonctionne pas en ICMP avec STRAWBERRY
my $SITE = "$ARGV[0]";
my $VILLE;
my $match = 0;
my $book = ReadData ('15062017_LOXAM_Etat REF CPE_vue CPE.csv', sep => ";");
my @rows = Spreadsheet::Read::rows($book->[1]);
shift @rows;
my %HASH_NOMINAL;
my %HASH_BACKUP;
foreach my $row (@rows) {
my ($ID_SITE, $LOOPBACK, $TOPOLOGIE) = @$row[5, 8, 11];
my @ELEMENTS = qw(ID_SITE LOOPBACK TOPOLOGIE LAN SWITCH190);
if ($ID_SITE =~ /\b$SITE\b/) {
$match++;
my @AGENCE_ID = grep { $_ =~ /\b\d\d/ } split /-/, $ID_SITE;
my $OCTET2 = substr($AGENCE_ID[0],0,2);
my $OCTET3 = substr($AGENCE_ID[0],2,2);
# Si le début est 0, supprimer le 0 pour ne garder que le dernier chiffre.
if ( $OCTET2 =~ /^0(\d)/) {
$OCTET2 = $1;
}
if ( $OCTET3 =~ /^0(\d)/) {
$OCTET3 = $1;
}
### IP LAN CE ###
my $LAN1 = "10.$OCTET2.$OCTET3.237";
my $LAN2 = "10.$OCTET2.$OCTET3.238";
my $SWITCH190 = "10.$OCTET2.$OCTET3.252";
if ($ID_SITE =~ /\s(\w+)$/i) {
$VILLE = $1;
}
my @NOMINAL;
my @BACKUP;
if ($TOPOLOGIE =~ /nominal/i) {
push (@NOMINAL, ($AGENCE_ID[0], $LOOPBACK, $TOPOLOGIE, $LAN1, $SWITCH190));
@HASH_NOMINAL{@ELEMENTS} = @NOMINAL;
}
else {
push (@BACKUP, ($AGENCE_ID[0], $LOOPBACK, $TOPOLOGIE, $LAN2, $SWITCH190));
@HASH_BACKUP{@ELEMENTS} = @BACKUP;
}
}
}
if ($match eq 0) {
print "$SITE INEXISTANT\n";
exit;
}
printf "%40s\n", "LOCALITE : $VILLE";
print "ROUTEUR NOMINAL";
printf "%40s\n", "ROUTEUR SECOURS";
check(%HASH_NOMINAL{LOOPBACK}, %HASH_BACKUP{LOOPBACK});
check(%HASH_NOMINAL{LAN}, %HASH_BACKUP{LAN});
ping_simple(%HASH_NOMINAL{SWITCH190});
sub check{
my $key0 = $_[0];
my $value0 = $_[1];
my $key1 = $_[2];
my $value1 = $_[3];
{
my $p = ping(host => "$value0", count => 3);
if ($p eq 1) {
print "$key0 $value0 = OK";
}
else {
print "$key0 $value0 = KO";
}
}
{
my $p = ping(host => "$value1", count => 3);
if ($p eq 1) {
printf "%40s\n", "$key1 $value1 = OK";
}
else {
printf "%40s\n", "$key1 $value1 = KO";
}
}
}
sub ping_simple{
my $p = ping(host => "$HASH_NOMINAL{SWITCH190}", count => 2);
if ($p eq 1) {
print "SWITCH $HASH_NOMINAL{SWITCH190} = OK";
}
else {
print "SWITCH $HASH_NOMINAL{SWITCH190} = KO";
}
} |
Partager