SHARE
TWEET

Spectrum Discovery Configuration Export

sweenig Jun 17th, 2015 (edited) 209 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/perl
  2. #
  3. #  CA Technologies, Inc.
  4. #  One CA Plaza
  5. #  Islandia, NY 11749 USA
  6. #
  7. #  Copyright (c) 2014 CA Technologies, Inc.
  8. #  All rights reserved.
  9. #
  10. #  IN NO EVENT SHALL CA TECHNOLOGIES INCORPORATED BE LIABLE FOR
  11. #  ANY INCIDENTAL, INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES
  12. #  WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS) ARISING OUT
  13. #  OF OR RELATED TO THIS SOFTWARE, EVEN IF CA TECHNOLOGIES INCORPORATED
  14. #  HAS BEEN ADVISED OF, KNOWN, OR SHOULD HAVE KNOWN, THE POSSIBILITY OF
  15. #  SUCH DAMAGES.
  16. #
  17. #  Forked by Stuart Weenig (modifications (C) 2015)
  18. #  IN NO EVENT SHALL Stuart Weenig BE LIABLE FOR
  19. #  ANY INCIDENTAL, INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES
  20. #  WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS) ARISING OUT
  21. #  OF OR RELATED TO THIS SOFTWARE, EVEN IF CA TECHNOLOGIES INCORPORATED
  22. #  HAS BEEN ADVISED OF, KNOWN, OR SHOULD HAVE KNOWN, THE POSSIBILITY OF
  23. #  SUCH DAMAGES.
  24.  
  25. ###################################################################
  26. #  ExportDiscoveryConfig.pl
  27. #
  28. #  Lists all SpectroSERVERs within a DSS environment and export 'Discovery Configurations' from all landscapes into $SPECROOT/SS-Tools directory
  29.  
  30. ### CPAN Modules ###
  31. use strict;
  32. use Cwd;
  33. use File::Copy;# qw(copy);
  34.  
  35. ############## ONLY CUSTIMIZATION POSSIBLY NEEDED ##############
  36. my $customspecroot = '/local/vend/spectrum';
  37. ################################################################
  38.  
  39. my $SPECROOT = $ENV{SPECROOT};
  40. chomp $SPECROOT;
  41. my $scriptDir = cwd();
  42. my $platform = `uname`;
  43. chomp $platform;
  44. my ($MapUpdate);
  45. my $AwkCmd = 'awk {\'print $4\'}';
  46. 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/\'';
  47. my $MG_ResourceFile = '.modelinggatewayresource.xml';
  48. my $MG_ResourceBackup = '.modelinggatewayresource_Orig.xml';
  49. my ($currentdp, $currlscape);#added to contain the discovery profile name and current landscape name, while outputting to CSV
  50. if ( $platform =~ /NT/i ) {
  51.         $SPECROOT='C:\win32app\Spectrum' unless ( $SPECROOT );
  52.         $SPECROOT = '/' . $SPECROOT;
  53.         $SPECROOT =~ s/://g;
  54.         $SPECROOT =~ s/\\/\//g;
  55.         $MapUpdate = 'MapUpdate.exe';
  56. } else {
  57.         $SPECROOT = $customspecroot unless ( $SPECROOT );
  58.         $MapUpdate = 'MapUpdate';
  59. }
  60. my $MapCommand = "./$MapUpdate -view|grep \"Landscape Default\"|$AwkCmd";
  61. my $SSToolsDir = $SPECROOT . '/' . 'SS-Tools';
  62. print "$0 started at " . GetCurrentDateTime() . "\n";
  63. chdir $SSToolsDir or die ("ERROR changing directory to $SSToolsDir");
  64. copy $MG_ResourceFile, $MG_ResourceBackup; # Take backup of original modelinggateway resource xml file
  65. `perl -pi -e $ReplaceConfig $MG_ResourceFile`; #Modify the configuration file so that fewer things get exported
  66. my @Landscapes = `$MapCommand`; #grab the landscape names
  67. open (OUTFILE, ">>devicesperprofile" . GetCurrentDateTime() . ".csv"); #setup a file to contain the CSV output
  68. foreach my $Landscape (@Landscapes) { #cycle through the landscapes
  69.         chomp $Landscape;
  70.         print "Exporting Discovery Configuration from $Landscape landscape: " . GetCurrentDateTime();
  71.         my $ExportFileName = "ExportDC_${Landscape}_" . GetCurrentDateTime() . '.xml'; #setup the name for the temporary output file
  72. if ( $platform =~ /NT/i ) {
  73.         #print "modelinggateway.bat -vnm $Landscape -e $ExportFileName\n";
  74.         `./modelinggateway.bat -vnm $Landscape -e $ExportFileName`;
  75. } else {
  76.         #print "modelinggateway -vnm $Landscape -e $ExportFileName\n";
  77.         `./modelinggateway -vnm $Landscape -e $ExportFileName`;
  78. }
  79.         #open the file just generated and parse it into a CSV
  80.         open (INFILE, $ExportFileName);
  81.         while (<INFILE>) {
  82.                 chomp;
  83.                 if ($_ =~ m!<SPECTRUM_Export landscape_name="(.*)" landscape_handle="0x......">!) {$currlscape = $1;}  
  84.                 if ($_ =~ m!<Discovery_Model name="(.*)" model_type=".*" model_handle="0x......" >!) {$currentdp = $1;}  
  85.                 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>!){print OUTFILE "$1,\"$currentdp\",$currlscape\n";}  
  86.         }
  87.         close(INFILE);
  88.         `rm $ExportFileName`; #remove the temporary file
  89.         print " - " . GetCurrentDateTime() . "\n";
  90. }
  91. close(OUTFILE);
  92. move $MG_ResourceBackup, $MG_ResourceFile; # Finally revert back the changes done to modelinggateway resource xml file
  93. print "Script completed at " . GetCurrentDateTime() . "\n";
  94. sub GetCurrentDateTime {
  95.         my $currentDate = "";
  96.         $currentDate = `date +%h_%d_%y_%I_%M_%S_%p`;
  97.         chomp $currentDate;
  98.         return $currentDate;
  99. }
RAW Paste Data
Top