Advertisement
sweenig

Spectrum Export Discovery Profiles

Apr 28th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.65 KB | None | 0 0
  1. #!/bin/perl
  2. # Lists all SpectroSERVERs within a DSS environment and export 'Discovery Configurations' from all landscapes into $SPECROOT/SS-Tools directory
  3.  
  4. ### CPAN Modules ###
  5. use strict;
  6. use Cwd;
  7. use File::Copy;
  8.  
  9. my $SPECROOT = $ENV{SPECROOT};
  10. chomp $SPECROOT;
  11. my $scriptDir = cwd();
  12. my $platform = `uname`;
  13. chomp $platform;
  14. my ($MapUpdate);
  15. my $AwkCmd = 'awk {\'print $4\'}';
  16. 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/\'';
  17. my $MG_ResourceFile = '.modelinggatewayresource.xml';
  18. my $MG_ResourceBackup = '.modelinggatewayresource_Orig.xml';
  19. my ($currentdp, $currlscape, $line);
  20. print "$0 started at " . GetCurrentDateTime() . "\n";
  21. if ( $platform =~ /NT/i ) {
  22.     print "Windows environment detected ($platform).\n";
  23.     $SPECROOT='C:\win32app\Spectrum' unless ( $SPECROOT );
  24.     $SPECROOT = '/' . $SPECROOT;
  25.     $SPECROOT =~ s/://g;
  26.     $SPECROOT =~ s/\\/\//g;
  27.     $MapUpdate = 'MapUpdate.exe';
  28. } else {
  29.     print "Non-Windows environment detected ($platform).\n";
  30.     $SPECROOT = '/usr/Spectrum' unless ( $SPECROOT );
  31.     $MapUpdate = 'MapUpdate';
  32. }
  33. my $MapCommand = "./$MapUpdate -view|grep \"Landscape Default\"|$AwkCmd";
  34. my $SSToolsDir = $SPECROOT . '/' . 'SS-Tools';
  35. chdir $SSToolsDir or die ("ERROR changing directory to $SSToolsDir");
  36. copy $MG_ResourceFile, $MG_ResourceBackup;# Take backup of original modelinggatewa modelinggateway resource xml file
  37. `perl -pi -e $ReplaceConfig $MG_ResourceFile`;
  38. my @Landscapes = `$MapCommand`;
  39. open (OUTFILE, ">devicesperprofile.csv");
  40. foreach my $Landscape (@Landscapes) {
  41.     chomp $Landscape;
  42.     print "Exporting Discovery Configuration from $Landscape landscape started at " . GetCurrentDateTime() . "\n";
  43.     my $ExportFileName = "ExportDC_${Landscape}_" . GetCurrentDateTime() . '.xml';
  44.     if ( $platform =~ /NT/i ) { #export everything this landscape has
  45.         print "\tExporting $Landscape configuration file ($ExportFileName)...\n";
  46.         `./modelinggateway.bat -vnm $Landscape -e $ExportFileName`;
  47.     } else {
  48.         print "\tExporting $Landscape configuration file ($ExportFileName)...\n";
  49.         `./modelinggateway.bat -vnm $Landscape -e $ExportFileName`;
  50.     }
  51.     print "\tDone exporting landscape configuration file ($ExportFileName).\n";
  52.     open (INFILE, $ExportFileName);#open the file just generated and parse it into a CSV
  53.     while (<INFILE>) {
  54.         chomp;
  55.         if ($_ =~ m!<SPECTRUM_Export landscape_name="(.*)" landscape_handle="0x.*">!) {$currlscape = $1;print "\tGathering IP addresses for all discovery profiles in landscape: $currlscape.\n";}  
  56.         if ($_ =~ m!<Discovery_Model name="(.*)" model_type=".*" model_handle="0x.*" ?>!) {$currentdp = $1;print "\tGathering IP addresses from discovery profile: $currentdp.\n";}  
  57.         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>!){
  58.             $line = "$1,\"$currentdp\",$currlscape\n";
  59.             print OUTFILE "$1,\"$currentdp\",$currlscape\n";
  60.         }  
  61.     }
  62.     close(INFILE);
  63.     `rm $ExportFileName`;
  64.     print "Exporting Discovery Configuration from $Landscape landscape completed at " . GetCurrentDateTime() . "\n\n";
  65. }
  66. `cp devicesperprofile.csv /e/installers`;
  67. close(OUTFILE);
  68. move $MG_ResourceBackup, $MG_ResourceFile; # Finally revert back the changes done to modelinggateway resource xml file
  69. print "Script completed at " . GetCurrentDateTime() . "\n";
  70.  
  71.  
  72. sub GetCurrentDateTime {
  73.     my $currentDate = "";
  74.     $currentDate = `date +%h_%d_%y_%I_%M_%S_%p`;
  75.     chomp $currentDate;
  76.     return $currentDate;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement