Subversion Repositories sysadmin_scripts

Rev

Rev 34 | Rev 133 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 66
Line 1... Line 1...
1
#! /usr/bin/env perl
1
#! /usr/bin/env perl
2
 
2
 
3
# take persistent storage created by mapSwitches.pl and dump entries
3
# take persistent storage created by mapSwitches.pl and dump entries
4
# to a tab delimited text file on STDOUT.
4
# to a tab delimited text file on STDOUT.
5
 
5
 
-
 
6
# v1.2 RWR 20200228
-
 
7
# added description field
-
 
8
 
6
use strict;
9
use strict;
7
use warnings;
10
use warnings;
8
 
11
 
9
use File::Spec; # find location of script so we can put storage in same directory
12
use File::Spec; # find location of script so we can put storage in same directory
10
use File::Basename;
13
use File::Basename;
11
use YAML::Tiny; # apt-get libyaml-tiny-perl under debian
14
use YAML::Tiny; # apt-get libyaml-tiny-perl under debian
12
use POSIX qw( strftime ); # to convert timestamp to something readable
15
use POSIX qw( strftime ); # to convert timestamp to something readable
13
 
16
 
14
our $VERSION = '1.1';
17
our $VERSION = '1.2';
15
 
18
 
16
# where the script is located
19
# where the script is located
17
my $scriptDir = dirname( File::Spec->rel2abs( __FILE__ ) );
20
my $scriptDir = dirname( File::Spec->rel2abs( __FILE__ ) );
18
# put the statefile in there
21
# put the statefile in there
19
my $STATEFILE = $scriptDir . '/mapSwitches.yaml';
22
my $STATEFILE = $scriptDir . '/mapSwitches.yaml';
Line 60... Line 63...
60
%switchports = %{ $yaml->[0] };
63
%switchports = %{ $yaml->[0] };
61
 
64
 
62
foreach my $switch ( sort keys %switchports ) {
65
foreach my $switch ( sort keys %switchports ) {
63
   print "$switchports{$switch}{'name'} Located at $switchports{$switch}{'location'}\n";
66
   print "$switchports{$switch}{'name'} Located at $switchports{$switch}{'location'}\n";
64
   # print the header
67
   # print the header
65
   print &dumpLine(  $delimiter,$encapsulate,'Switch','Port','Alias','MAC','IP','Host Name','Last Seen' );
68
   print &dumpLine(  $delimiter,$encapsulate,'Switch','Port','Alias','Description','MAC','IP','Host Name','Last Seen' );
66
   foreach my $port ( sort {$a<=>$b} keys %{$switchports{$switch}{'ports'}} ) {
69
   foreach my $port ( sort {$a<=>$b} keys %{$switchports{$switch}{'ports'}} ) {
67
      foreach my $connection ( keys %{$switchports{$switch}{'ports'}{$port} } ) {
70
      foreach my $connection ( keys %{$switchports{$switch}{'ports'}{$port} } ) {
68
         next if $connection eq 'alias';
71
         next if $connection eq 'alias' or $connection eq 'description';
69
         print &dumpLine ( $delimiter,$encapsulate,
72
         print &dumpLine ( $delimiter,$encapsulate,
70
            $switch,
73
            $switch,
71
            $port,
74
            $port,
72
            $switchports{$switch}{'ports'}{$port}{'alias'},
75
            $switchports{$switch}{'ports'}{$port}{'alias'},
-
 
76
            $switchports{$switch}{'ports'}{$port}{'description'},
73
            &prettyMAC( $switchports{$switch}{'ports'}{$port}{$connection}{'mac'}),
77
            &prettyMAC( $switchports{$switch}{'ports'}{$port}{$connection}{'mac'}),
74
            $switchports{$switch}{'ports'}{$port}{$connection}{'ip'},
78
            $switchports{$switch}{'ports'}{$port}{$connection}{'ip'},
75
            $switchports{$switch}{'ports'}{$port}{$connection}{'hostname'},
79
            $switchports{$switch}{'ports'}{$port}{$connection}{'hostname'},
76
            &prettyTime( $switchports{$switch}{'ports'}{$port}{$connection}{'lastseen'} )
80
            &prettyTime( $switchports{$switch}{'ports'}{$port}{$connection}{'lastseen'} )
77
         ) ;
81
         ) ;