Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/perl
- # Lists all SpectroSERVERs within a DSS environment and export 'Discovery Configurations' from all landscapes into $SPECROOT/SS-Tools directory
- ### CPAN Modules ###
- use strict;
- use Cwd;
- use File::Copy;
- my $SPECROOT = $ENV{SPECROOT};
- chomp $SPECROOT;
- my $scriptDir = cwd();
- my $platform = `uname`;
- chomp $platform;
- my ($MapUpdate);
- my $AwkCmd = 'awk {\'print $4\'}';
- my $ReplaceConfig = '\'/(export_devices|export_containers|export_port_attributes|export_links|export_topology_layout|export_annotation|export_WA_Link_models|export_spectrum_settings|export_user_models|export_service_modeling|export_schedules|export_global_collections|export_policy_manager)\s*\=/ && s/true/false/\'';
- my $MG_ResourceFile = '.modelinggatewayresource.xml';
- my $MG_ResourceBackup = '.modelinggatewayresource_Orig.xml';
- my ($currentdp, $currlscape, $line);
- print "$0 started at " . GetCurrentDateTime() . "\n";
- if ( $platform =~ /NT/i ) {
- print "Windows environment detected ($platform).\n";
- $SPECROOT='C:\win32app\Spectrum' unless ( $SPECROOT );
- $SPECROOT = '/' . $SPECROOT;
- $SPECROOT =~ s/://g;
- $SPECROOT =~ s/\\/\//g;
- $MapUpdate = 'MapUpdate.exe';
- } else {
- print "Non-Windows environment detected ($platform).\n";
- $SPECROOT = '/usr/Spectrum' unless ( $SPECROOT );
- $MapUpdate = 'MapUpdate';
- }
- my $MapCommand = "./$MapUpdate -view|grep \"Landscape Default\"|$AwkCmd";
- my $SSToolsDir = $SPECROOT . '/' . 'SS-Tools';
- chdir $SSToolsDir or die ("ERROR changing directory to $SSToolsDir");
- copy $MG_ResourceFile, $MG_ResourceBackup;# Take backup of original modelinggatewa modelinggateway resource xml file
- `perl -pi -e $ReplaceConfig $MG_ResourceFile`;
- my @Landscapes = `$MapCommand`;
- open (OUTFILE, ">devicesperprofile.csv");
- foreach my $Landscape (@Landscapes) {
- chomp $Landscape;
- print "Exporting Discovery Configuration from $Landscape landscape started at " . GetCurrentDateTime() . "\n";
- my $ExportFileName = "ExportDC_${Landscape}_" . GetCurrentDateTime() . '.xml';
- if ( $platform =~ /NT/i ) { #export everything this landscape has
- print "\tExporting $Landscape configuration file ($ExportFileName)...\n";
- `./modelinggateway.bat -vnm $Landscape -e $ExportFileName`;
- } else {
- print "\tExporting $Landscape configuration file ($ExportFileName)...\n";
- `./modelinggateway.bat -vnm $Landscape -e $ExportFileName`;
- }
- print "\tDone exporting landscape configuration file ($ExportFileName).\n";
- open (INFILE, $ExportFileName);#open the file just generated and parse it into a CSV
- while (<INFILE>) {
- chomp;
- if ($_ =~ m!<SPECTRUM_Export landscape_name="(.*)" landscape_handle="0x.*">!) {$currlscape = $1;print "\tGathering IP addresses for all discovery profiles in landscape: $currlscape.\n";}
- if ($_ =~ m!<Discovery_Model name="(.*)" model_type=".*" model_handle="0x.*" ?>!) {$currentdp = $1;print "\tGathering IP addresses from discovery profile: $currentdp.\n";}
- if ($_ =~ m!<value>(\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)</value>!){
- $line = "$1,\"$currentdp\",$currlscape\n";
- print OUTFILE "$1,\"$currentdp\",$currlscape\n";
- }
- }
- close(INFILE);
- `rm $ExportFileName`;
- print "Exporting Discovery Configuration from $Landscape landscape completed at " . GetCurrentDateTime() . "\n\n";
- }
- `cp devicesperprofile.csv /e/installers`;
- close(OUTFILE);
- move $MG_ResourceBackup, $MG_ResourceFile; # Finally revert back the changes done to modelinggateway resource xml file
- print "Script completed at " . GetCurrentDateTime() . "\n";
- sub GetCurrentDateTime {
- my $currentDate = "";
- $currentDate = `date +%h_%d_%y_%I_%M_%S_%p`;
- chomp $currentDate;
- return $currentDate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement