Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

s_nodelist.pl

Liste les managed nodes installés sur le serveur OVOW

#
# POLICY: 
#
# CONFIGURATION: N/A
#
# PARAMETRES D'APPEL: N/A
#
# SORTIE: mail
#
# FICHIERS ENTREE:
#
#
# FICHIERS SORTIE:
#
#
# COMMENTAIRES:
#	
#
#
# MODIFICATIONS:
# 15/01/2008    Ajout de trace pour debugging => eval/die
#
#

use strict;
use Getopt::Std;
use Win32;
use Win32::OLE qw( in );
use Win32::OLE('in');

my $RepositoryFile = "\\\\ilbur001\\SrvIBP\\Projet\\Surv_HPOVO (P9SUR024)\\Production\\log\\NodesOn$ENV{COMPUTERNAME}.txt";

if ( $ENV{COMPUTERNAME} =~ /HPO001/ ) {
	$RepositoryFile = "\\\\ilbur001\\SrvIBP\\Projet\\Surv_HPOVO (P9SUR024)\\Production\\log\\old\\NodesOn$ENV{COMPUTERNAME}.txt";
}


my $server      = '';    # connect to local machine
my $debug 	= 'TRUE';
my $log_file    = "$ENV{OVINSTALLDIR}"."temp/s_nodelist.log";

sub TRACE {
	my $f = shift;
	logger( 'TRACE' . "\t" . $f, @_ );
}

sub ERROR {
	my $f = shift;
	logger( 'ERREUR' . "\t" . $f, @_ );
}

sub logger {
	my $f = shift;
	my $msg = sprintf( ts() . "\t" . $f . "\n", @_ );
	print {*STDOUT} $msg;
	open my $desc_log_file , '+>>', $log_file ;
	print {$desc_log_file} $msg ;
	close $desc_log_file;
}

sub ts {
	my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
	  localtime( time() );
	return (
		sprintf(
			'%04d-%02d-%02d %02d:%02d:%02d',
			$year + 1900,
			$mon + 1, $mday, $hour, $min, $sec
		)
	);
}


eval {
	open my $file, '>', "$RepositoryFile" or die "Can't open file $RepositoryFile: $!\n";
#--------------------------------
# Récupère un objet SWbemLocator
#-------------------------------
	my $lobj = Win32::OLE->new('WbemScripting.SWbemLocator')
		or die "can't create locator object: " . Win32::OLE->LastError() . "\n";
#----------------------------------------------------------------
# Prépare une connexion avec un niveau de sécurité "impersonate"
#---------------------------------------------------------------
	$lobj->{Security_}->{impersonationlevel} = 3;

#-----------------------------------
# Connexion à l'objet SWbemServices
#----------------------------------
	my $sobj = $lobj->ConnectServer( $server, 'root\hewlettpackard\openview\data' )
		or die "can't create server object: " . Win32::OLE->LastError() . "\n";

	my $wmiquery = "Select * from OV_ManagedNode";

	print "\$wmiquery=$wmiquery\n" if ($debug);

	my $nodelist = $sobj->ExecQuery($wmiquery)
		or die "La requête a echouée " . Win32::OLE->LastError() . "\n";

	my ( $sourceName, $count );
	my ( @listenoeud, @sortedlist );
	foreach my $node ( in $nodelist )
	{
		#next if ( $node->{Caption} =~ m/(Management Server)/ );
		$sourceName = $node->{PrimaryNodeName};
		push @listenoeud, $sourceName;
	}
	@sortedlist = sort @listenoeud;
	foreach my $node (@sortedlist)
	{
		#next if ( $node =~ /ESX/ );
		print {$file} $node."\n" ;
		$count++;
	}

	close $file;

	TRACE($count . " Managed Nodes listed\n");
};
if ( $@ ) {
	ERROR($@);
}

s_CorRegKeyAgt.pl

Assure la cohérence de la clef de registre de l'agent et du 'Full computer Name'

# $Id: s_CorRegKeyAgt.pl 29 2007-08-14 14:10:01Z jcde $
# $Date: 2007-08-14 16:10:01 +0200 (mar., 14 août 2007) $
# 
# PERL
# $HeadURL: svn://localhost/Perl_OVOW/s_CorRegKeyAgt.pl $ v1.0
#
# FONCTION: Assure la cohérence de la clef de registre de l'agent et du 'Full computer Name'
#
# POLICY: N/A
#
# CONFIGURATION: N/A
#
# PARAMETRES D'APPEL:  
#
# SORTIE: message 
#
#
# FICHIERS ENTREE: 
#
#
# FICHIERS SORTIE: 
#
#
# COMMENTAIRES:
#	
#
# MODIFICATIONS:
#
# $Author: jcde $
#

use strict;
use warnings;
use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );



#my $Registry->Delimiter("/"); # Set delimiter to "/".

my $AgentKey = $Registry->{"LMachine/Software/Hewlett-Packard/Openview/ITO/"};

print "ITO Reg Key Value:".$AgentKey->GetValue('HostName')."\n";

my $HNameKey = $Registry->{"LMachine/System/CurrentControlSet/Services/TCPIP/Parameters/"};

my $Domain = $HNameKey->GetValue('Domain');
my $HstName = $HNameKey->GetValue('HostName');

#print $HNameKey->GetValue('Domain')."\n";
my $sep = ($Domain) ? "." :'';
#print $HNameKey->GetValue('HostName')."\n";

print "Full computer Name Value:".$HstName.$sep.$Domain."\n";

if ( $AgentKey->GetValue('HostName') ne $HstName.$sep.$Domain ) {
    print "Mismatch detected !!";
    $Registry->{"LMachine/Software/Hewlett-Packard/Openview/ITO/Hostname"} = $HstName.$sep.$Domain;
    print "Modification done !\n";
    system('opcagt -k');
    print "Agent stopped !\n";
    system('opcagt -start');
    print "Agent started !\n";
}
else {
	print "OK !!\n";
}

s_update_policies_version.pl

Modification des versions des policies OVOW

# $Id: s_update_policies_version.pl 42 2007-08-16 09:24:31Z jcde $
# $Date: 2007-08-16 11:24:31 +0200 (jeu., 16 août 2007) $
# 
# PERL
# $HeadURL: svn://localhost/Perl_OVOW/s_update_policies_version.pl $ v1.0
#
# FONCTION: 
#
# POLICY: N/A
#
# CONFIGURATION: N/A
#
# PARAMETRES D'APPEL:  
#
# SORTIE: message 
#
#
# FICHIERS ENTREE: 
#
#
# FICHIERS SORTIE: 
#
#
# COMMENTAIRES:
#	
#
# MODIFICATIONS:
#
# $Author: jcde $
#
#
use strict;
use warnings;
use Getopt::Long;

# my $versionpattern = pack "H*", "00560065007200730069006f006e003d";    #  produce " V e r s i o n ="
# my $new_version = pack "H*", "0030003000300032002e00300030003000300D000A";  #  produce " 0 0 0 2 . 0 0 0 0"
# my $old_version = pack "H*", "0030003000300031002e00300030003000320000";    #  produce " 0 0 0 1 . 0 0 0 2"

# my $filename ='H:\\iBP\\testpolicies\\GBL-W2K_system-srv_2464AC5C-7798-467F-842C-2F8ACC15D85F';
# my $filenameout = 'F:\\out.txt';
my %Config;

Configure( \%Config );
if ( $Config{help} )
  {
	Syntax();
	exit(0);
  }

my @file_list;
my $version = $Config{version};

my $file;
opendir DIR, "@{$Config{dirs}}"
  or die "Can't open directory @{ $Config{dirs} }: $!\n";

while ( $file = readdir DIR )
  {
	next if $file =~ /^\./;
	print "Found a file: $file\n";
	push( @file_list, "$file\n" );
  }

foreach my $filename (@file_list)
  {

	chomp $filename;

	`ovpmutil PCV /x $filename`;
	`ovpmutil PCV /c /v $version $filename`;
  }

sub Configure
  {
	my ($Config) = @_;

	Getopt::Long::Configure("prefix_pattern=(-|\/)");
	my $Result = GetOptions(
		$Config,
		qw(
		  version|v
		  help|?
		  )
	);
	$Config->{help} = 1 if ( !$Result );
	push( @{ $Config->{dirs} }, @ARGV );

	if ( !scalar @{ $Config->{dirs} } )
	  {
		$Config->{help} = 1;
	  }
  }

sub Syntax
  {
	my ($Script) = ( $0 =~ /([^\\\/]*?)$/ );
	my ($Line)   = "-" x length($Script);

	print <<EOT;

$Script
$Line
Update policies version from ovpmutil result files by
pipol.

Syntax:
    perl $Script [-r] [-n] <Dir> [Dir2 [, Dir3 ...]]
        -v..........New version for the policies.
        Dir.........Directory of example files to rename.
EOT
  }

s_was_esb_logging.pl

Stocke dans CODA les compteurs de perfs WAS ESB.

#
# PERL
# VERSION: "@(#)s_was_esb_logging.pl v1.0 05/06/2007"
#
# FONCTION:
#
# POLICY: N/A
#
# CONFIGURATION: N/A
#
# PARAMETRES D'APPEL:
#
# SORTIE: message
#
# FICHIERS ENTREE:
#
#
# FICHIERS SORTIE:
#
#
#
# COMMENTAIRES:
#
#
# MODIFICATIONS:
#
#
use strict;
use warnings;
my $debug = '';

my $spi_was_dir    = "$ENV{OVAGENTDIR}\\wasspi\\wbs";
my $instrum_dir = "$ENV{OVAGENTDIR}\\bin\\instrumentation";
#my $udm_dir        = 'c:\IBPEXPL';
#my $udm_file       = 'UDMMetrics.xml';
#my $spiconfig_dir = "$spi_was_dir";
my  $perl_exe_path  = "$ENV{OVPERLBIN}";
my  $dir_for_log    = "$spi_was_dir\\datalog_esb";
my @server_list = ( 'server1 on ibwasr08.srv-ib.dev port 2309',
                    'server1 on ibwasr08.srv-ib.dev port 2209',
                    'server1 on ibwasr08.srv-ib.dev port 2809',
                    'server1 on ibwasr08.srv-ib.dev port 2109',
                    'server1 on ibwasr08.srv-ib.dev port 2109',
                    'server1 on ibwasr08.srv-ib.dev port 2409',
                  );
my @instance_list =
    qw ( DossierCliEJB GestAboEJB GestAdmCliEJB GestAdrComEJB GestComCliEJB FctCtrEJB );
my @metric_list = qw ( 717 710 );
my $coll_cmd    = "wasspi_wbs_perl -S wasspi_wbs_ca -m 717 -x print=on";
my $cmd_output  = `cd \"$instrum_dir\" &&  $coll_cmd`;

my %servers;
my %instances;

sub value_print {
 my ( $desc_file, $server_app ) = @_;
        for my $instance ( keys %{ $servers{$server_app} } ) {
        my ( $val ) = $servers{$server_app}->{$instance} =~ /[0-9a-zA-Z-_ \.,]+\=\>[0-9a-zA-Z-_ \.,]+\=\>(\d+.\d+)/x;
        $val =~ s/\,/\./g;
            print {$$desc_file} ' ' . $val ;
        }
        return;
}

sub ddf_log {
 my ( $server ) = @_;
 my $cmd = "\"$instrum_dir\\ddflog.exe\" \"$dir_for_log\" WAS_ESB -s 0 -i \"$dir_for_log\\$server.dat\"";
 system "\"$cmd\"";
 return;
}


foreach my $line ( split /\n/, $cmd_output ) {
    next if !($line);
    my ( $server_name, $instance_name, $value ) =
        $line =~
        /^\w+\W+\w+\W+\w+\W+"([0-9a-zA-Z-_ \.]+)"\W+\w+\W+"([0-9a-zA-Z-_ \.,]+)"\W+\w+\W+(\d+.\d+).*/x;
    $servers{"$server_name"}{"$instance_name"} =
        $server_name . '=>' . $instance_name . '=>' . $value;
}

if ($debug) {
    for my $server ( keys %servers ) {
        for my $instance ( keys %{ $servers{$server} } ) {
            print $servers{$server}->{$instance} . "\n";
        }
    }
}

for my $server ( keys %servers ) {
    print $server . "\n" if ($debug);
    open my $desc_file_sever, '>', "$dir_for_log\\$server.dat" || die "can't open file $server.dat: $!";
    ( my $server_fn = $server ) =~ s/ /_/g ;
    print {$desc_file_sever} "$server_fn                                                                                                                                                                 " || die "can't print to $server.dat: $!";
	    value_print( \$desc_file_sever, $server );
    close $desc_file_sever;
    ddf_log( $server );
}

s_nodelistSynth.pl

Liste les managed nodes installés sur les serveurs OVOW feuilles et compare le résultat avec les noeuds du supra-manager

#! Perl\bin\Perl.exe
#
# PERL
# VERSION: "@(#)s_nodelistSynth.pl v1.0 31/08/2006"
#
# FONCTION: Liste les managed nodes installés sur les serveurs OVOW feuilles et compare le résultat avec les noeuds du supra-manager
#
# POLICY: 
#
# CONFIGURATION: N/A
#
# PARAMETRES D'APPEL: N/A
#
# SORTIE: mail
#
# FICHIERS ENTREE:
#
#
# FICHIERS SORTIE:
#
#
# COMMENTAIRES:
#	
#
#
# MODIFICATIONS:
#
#
#

use strict;
use Getopt::Std;
use Win32;
use Win32::OLE qw( in );
use Win32::OLE('in');
use Mail::Sendmail;

my $debug 	= '';

my $RepositoryDirectory = "\\Production\\log";
my $server      = '';    # connect to local machine

my $smtpserver   = '93.93.205.196'; # ibxhrv01.ctr.ibp
my $monikeraddr  = 'IBHPOE00';

my @ListeMail        = ('destinataire@mail.fr');

my (@AllNodes, @AllNodesSorted);
my %AllNodes;
my $manager;

#--------------------------------
# Récupère un objet SWbemLocator
#-------------------------------
my $lobj = Win32::OLE->new('WbemScripting.SWbemLocator')
  or die "can't create locator object: " . Win32::OLE->LastError() . "\n";

#----------------------------------------------------------------
# Prépare une connexion avec un niveau de sécurité "impersonate"
#---------------------------------------------------------------
$lobj->{Security_}->{impersonationlevel} = 3;

#-----------------------------------
# Connexion à l'objet SWbemServices
#----------------------------------
my $sobj = $lobj->ConnectServer( $server, 'root\hewlettpackard\openview\data' )
  or die "can't create server object: " . Win32::OLE->LastError() . "\n";

my $wmiquery = "Select * from OV_ManagedNode";

print "\$wmiquery=$wmiquery\n" if ($debug);

my $nodelist = $sobj->ExecQuery($wmiquery)
  or die "La requête a echouée " . Win32::OLE->LastError();


my ( $sourceName, $count );
my ( @listenoeud, @sortedlist );
foreach my $node ( in $nodelist )
  {
	  	#next if ( $node->{Caption} =~ m/(Management Server)/ );
		$sourceName = $node->{PrimaryNodeName};
		push @listenoeud, $sourceName;
  }
@sortedlist = sort @listenoeud;
foreach my $node (@sortedlist)
{
	#next if ( $node =~ /ESX/ );
	#print $node."\n" ;
	$count++;
}




my @filelist_txt = &checkFileType($RepositoryDirectory, 'txt');
print "\@filelist_txt=@filelist_txt\n" if $debug;
foreach my $file (@filelist_txt)
{
	($manager) = $file =~ m/NodesOn(.*).txt$/;
	print "\$manager=$manager\n" if $debug;;
	open (FILE, $RepositoryDirectory."\\".$file);
	while (<FILE>)
	{		
		chomp();
		#push (@AllNodes,$_);
		$AllNodes{$_}=$manager;
	}
	close(FILE);
}

@AllNodesSorted = sort @AllNodes;

if ($debug)
{
	print "\@AllNodes=@AllNodesSorted\n";
	print "\@AllNodes=>$#AllNodesSorted\n";
	print "\@sortedlist=@sortedlist\n";
	print "\@sortedlist=$#sortedlist\n";
}

my $missingCount = 0;
my $message;

for my $item (keys %AllNodes) {
	unless (grep $item eq $_,@sortedlist ) {
		print "Il manque $item <= $AllNodes{$item}.\n" if $debug;
		$message = $message."Il manque $item <= $AllNodes{$item}.\n";
		$missingCount++;
	}
}
print "Différence de $missingCount machines.\n" if $debug;
$message = $message."\n\nDifférence de $missingCount machines.\n";

$message = "Cohérence dans la déclaration des noeuds OK entre les managers OVOW" if ($missingCount == 0);

foreach my $email (@ListeMail)
{
	&SendEmail($email);
} 
    
sub checkFileType
{
    my ( $pathToCheck, $extension ) = @_;
    my $ret_value = 0;
    my @list;
    opendir DIR,$pathToCheck or die "Can't open directory $pathToCheck: $!\n";
    push @list, grep /\.$extension$/, readdir DIR;
    # $ret_value = 1 if grep /\.$extension$/, readdir DIR;
    return  @list;
}


sub SendEmail
{
    my ($email) = @_;
    #----------------
    # Envoie du mail
    #---------------
    sendmail(
        To      => $email,
        Cc      => '',
        Subject => "Rapport de cohérence sur l'installation des noeuds sur IBHPOE00",
        From    => $monikeraddr,
        Message => $message,
        Server  => $smtpserver,
        delay   => 1,
        retries => 3
    )
    || die "Cannot send mail: $Mail::Sendmail::error\n";
}