Up till now, we did have a bunch of shell and perl scripts doing this work. Today, as I was looking for some stuff to do, I found them and decided rewriting it, so you wouldn’t need a shell script to call the perl worker script … This is pretty much the result!

 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
#!/usr/bin/perl

# LICENSE:     GNU General Public License v2. (see LICENSE.txt)
# COPYRIGHT:   Copyright 2010 Christian Heim <christian.heim@barfoo.org>

# This script runs a batch of commands on a list of FC-switches. For example:
# fc-switch-commands.pl statsclear | configupload | supportsave

use strict;
use warnings;
use Net::Telnet;

our( @san_fabric1_core, @san_fabric1_edge_1, @san_fabric1_edge_2 );
our( @san_fabric2_core, @san_fabric2_edge_1, @san_fabric2_edge_2 );
our( @switches );
our( $ftp_host, $ftp_username, $ftp_password );
our( $telnet );
our( $i, $version, @debug );

@san_fabric1_core = ( "10.144.20.50", "admin", "JuNxJFSAS!", 'san_fabric1_core' );
@san_fabric1_edge_1 = ( "10.144.20.51", "admin", "JuNxJFSAS!", 'san_fabric1_edge_1' );
@san_fabric1_edge_2 = ( "10.144.20.52", "admin", "JuNxJFSAS!", 'san_fabric1_edge_2' );
@san_fabric2_core = ( "10.144.20.60", "admin", "JuNxJFSAS!", 'san_fabric2_core' );
@san_fabric2_edge_1 = ( "10.144.20.61", "admin", "JuNxJFSAS!", 'san_fabric2_edge_1' );
@san_fabric2_edge_2 = ( "10.144.20.62", "admin", "JuNxJFSAS!", 'san_fabric2_edge_2' );

$ftp_host = '10.144.20.45';
$ftp_username = 'brocade_cfg';
$ftp_password = 'JuNxJPFC!';

@switches = ( @san_fabric1_core, @san_fabric2_core,
              @san_fabric1_edge_1, @san_fabric1_edge_2,
              @san_fabric2_edge_1, @san_fabric2_edge_2 );

@debug = ( Dump_Log => 'dump.log', Output_Log => 'out.log', Input_Log => 'in.log' );

$telnet = new Net::Telnet(Timeout=>240, Errmode=>'die',
                          Prompt => '/.*:admin> $/is', @debug);

for ($i = 0; $i < $#switches + 1; $i++) {
  $telnet->open($switches[$i][0]);
  $telnet->login($switches[$i][1], $switches[$i][2]);

  if ( $ARGV[0] eq "statsclear" ) {
    $telnet->cmd("statsclear");
  } elsif ( $ARGV[0] eq "configupload" ) {
    # Check the FabricOS version, as Brocade decided to break compatiblity with
    # earlier firmware versions w/ v6 (at least configupload)
    $telnet->cmd("firmwareshow");
    $version = $telnet->lastline;
    $version =~ s/s+|s+$//g;

    if ( $version =~ "v6" ) {
      $telnet->cmd("configupload -all -ftp "$ftp_host","$ftp_username","$switches[$i][3].cfg","$ftp_password"");
    } else {
      $telnet->cmd("configupload "$ftp_host","$ftp_username","$switches[$i][3].cfg","$ftp_password"");
    }
  } elsif ( $ARGV[0] eq "supportsave" ) {
    $telnet->cmd("supportsave -n -u "$ftp_username" -p "$ftp_password" -h "$ftp_host" -d "supportsave/$switches[$i][3]" -l ftp");
  }

  $telnet->close();
}