Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/perl
- #
- # CA Technologies, Inc.
- # One CA Plaza
- # Islandia, NY 11749 USA
- #
- # Copyright (c) 2014 CA Technologies, Inc.
- # All rights reserved.
- #
- # IN NO EVENT SHALL CA TECHNOLOGIES INCORPORATED BE LIABLE FOR
- # ANY INCIDENTAL, INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES
- # WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS) ARISING OUT
- # OF OR RELATED TO THIS SOFTWARE, EVEN IF CA TECHNOLOGIES INCORPORATED
- # HAS BEEN ADVISED OF, KNOWN, OR SHOULD HAVE KNOWN, THE POSSIBILITY OF
- # SUCH DAMAGES.
- #
- # Forked by Stuart Weenig (modifications (C) 2015)
- # IN NO EVENT SHALL Stuart Weenig BE LIABLE FOR
- # ANY INCIDENTAL, INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES
- # WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS) ARISING OUT
- # OF OR RELATED TO THIS SOFTWARE, EVEN IF CA TECHNOLOGIES INCORPORATED
- # HAS BEEN ADVISED OF, KNOWN, OR SHOULD HAVE KNOWN, THE POSSIBILITY OF
- # SUCH DAMAGES.
- ###################################################################
- # ExportDiscoveryConfig.pl
- #
- # 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;# qw(copy);
- ############## ONLY CUSTIMIZATION POSSIBLY NEEDED ##############
- my $customspecroot = '/local/vend/spectrum';
- ################################################################
- 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);#added to contain the discovery profile name and current landscape name, while outputting to CSV
- if ( $platform =~ /NT/i ) {
- $SPECROOT='C:\win32app\Spectrum' unless ( $SPECROOT );
- $SPECROOT = '/' . $SPECROOT;
- $SPECROOT =~ s/://g;
- $SPECROOT =~ s/\\/\//g;
- $MapUpdate = 'MapUpdate.exe';
- } else {
- $SPECROOT = $customspecroot unless ( $SPECROOT );
- $MapUpdate = 'MapUpdate';
- }
- my $MapCommand = "./$MapUpdate -view|grep \"Landscape Default\"|$AwkCmd";
- my $SSToolsDir = $SPECROOT . '/' . 'SS-Tools';
- print "$0 started at " . GetCurrentDateTime() . "\n";
- chdir $SSToolsDir or die ("ERROR changing directory to $SSToolsDir");
- copy $MG_ResourceFile, $MG_ResourceBackup; # Take backup of original modelinggateway resource xml file
- `perl -pi -e $ReplaceConfig $MG_ResourceFile`; #Modify the configuration file so that fewer things get exported
- my @Landscapes = `$MapCommand`; #grab the landscape names
- open (OUTFILE, ">>devicesperprofile" . GetCurrentDateTime() . ".csv"); #setup a file to contain the CSV output
- foreach my $Landscape (@Landscapes) { #cycle through the landscapes
- chomp $Landscape;
- print "Exporting Discovery Configuration from $Landscape landscape: " . GetCurrentDateTime();
- my $ExportFileName = "ExportDC_${Landscape}_" . GetCurrentDateTime() . '.xml'; #setup the name for the temporary output file
- if ( $platform =~ /NT/i ) {
- #print "modelinggateway.bat -vnm $Landscape -e $ExportFileName\n";
- `./modelinggateway.bat -vnm $Landscape -e $ExportFileName`;
- } else {
- #print "modelinggateway -vnm $Landscape -e $ExportFileName\n";
- `./modelinggateway -vnm $Landscape -e $ExportFileName`;
- }
- #open the file just generated and parse it into a CSV
- open (INFILE, $ExportFileName);
- while (<INFILE>) {
- chomp;
- if ($_ =~ m!<SPECTRUM_Export landscape_name="(.*)" landscape_handle="0x......">!) {$currlscape = $1;}
- if ($_ =~ m!<Discovery_Model name="(.*)" model_type=".*" model_handle="0x......" >!) {$currentdp = $1;}
- 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";}
- }
- close(INFILE);
- `rm $ExportFileName`; #remove the temporary file
- print " - " . GetCurrentDateTime() . "\n";
- }
- 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