[Arsperl-users] Problems with arsperl_182
Brought to you by:
jeffmurphy
|
From: Thanh Q L. <tha...@al...> - 2005-06-01 16:12:54
|
#!perl -w # # %W% %G% # # NAME # addGeneric - Adds the specifed software generic to the object form in PTS. # # SYNOPSIS # addGeneric [-h] [-d desc] [-j proj] [-p prod] <generic> # # DESCRIPTION # addgeneric will insert the given generic into the object form of PTS, and # will set the top level project and top level product fields to the values # specified. # # OPTIONS # -h - help # -d desc - Description of the generic being added. # -j proj - Highest level project that the generic will be associated with # -p prod - Highest level product that the generic will be associated with # # PARAMETERS # generic - The software generic to be added to the object table in PTS # # RETURNS # 0 - Completed # != 0 - Error # # BUGS # None ############################################################################### # # Modules used by this script # The ARS modules is a non standard Perl module. For information about how # to use this module go to http://arsinfo.cit.buffalo.edu/perl/index.html use ARS; # API to PTS (Action Request System) use Getopt::Std; use strict; # # Globals # use vars qw($ProgName $opt_h $opt_d $opt_p $opt_j $opt_n); # Pick up the program name, strip off leading garbage my @pName = split (/\//, $0);; $ProgName = $pName[$#pName]; # Process command line arguments # opt_d - description of generic # opt_h - help # opt_j - top level project # opt_p - top level product ProcCmdLine(); # Do mainline main(); # # Usage - Checks to ensure that command usage is correct # # Parameters # None - Examines ARGV # # Returns # None - None, aborts on error # sub Usage { # Must be one argument if ( @ARGV != 1 ) { # Display help text $opt_h = 1; GiveHelp(); } } # # ProcCmdLine - Process command line arguments # # Parameters # None # # Returns # None # sub ProcCmdLine { # Process arguments if Getopts fails then display help text. if ( !getopts('d:j:p:h') ) { $opt_h = 1; } # Make sure that usage is correct Usage(); # Provide help? GiveHelp(); } # # GiveHelp - Provide help if necessary # # Parameters # None # # Returns # None - Aborts on help display # sub GiveHelp { if ( defined ($opt_h) ) { print "$ProgName: $ProgName [-h] [-p prod] [-j proj] [-d \"desc\"] <generic> Options: -h - print out help. -d<\"desc\"> - Description of the generic being added. -j<proj> - Highest level project that this generic will be associated with. -p<prod> - Highest level product that this generic will be associated with.\n\n"; # All done exit 3; } } # # main # # Parameters # None # # Returns # 0 - Success # anything else - Error # sub main() { # Variable declarations my ($arHndl); # Contains handle used to communicate with the ARServer my ($svr) = "pts"; # Name of ARServer to connect to my ($user) = "olive"; # Remedy user account to use my ($passwd) = "abc123"; # Remedy account password my ($objId) = "536870912"; # Field id of the Object field on object form my ($fullId) = "8"; # Field id of the Object Full Name field my ($pathId) = "536870914"; # Field id of the Status field my ($prodId) = "536870913"; # Field id of the Top Level Product field my ($projId) = "536870915"; # Field id of the Top Level Project field my ($id); # Unique id of the generic in the PTS-Object form my ($desc); # Description of generic to be added my ($error) = 0; # $topProd and $topProj stores the highest level product/project that the # generics to be inserted will be associated with. my ($topProd) = "5620_SAM"; my ($topProj) = "5620_SAM"; # Get generic from command line my ($generic) = @ARGV; # Connect to the ARServer print error message if connection refused unless ($arHndl = ars_Login($svr, $user, $passwd)) { print ("$ProgName: $ars_errstr \n $generic was not inserted. \n\n"); exit 1; } # Verify that generic is formated properly if ($generic !~ /^SAM[0-9][0-9]_|^SAM_|^NMS_/) { print "ERROR: Invalid generic <$generic>\n"; exit 1; } # Was the -p option used if yes then set $topProd if (defined($opt_p)) { $topProd = $opt_p; } # Was the -j option used if yes then set $topProj if (defined($opt_j)) { $topProj = $opt_j; } # Was the -d option used if yes then set $desc $desc = $generic; if (defined($opt_d)) { $desc = $opt_d; } # Add generic to PTS-Object form if ($id = ars_CreateEntry($arHndl, "PTS-Object", "$objId", "$generic", "$fullId", "$desc", "$pathId", "(SYSTEM)", "$prodId", "$topProd", "$projId", "$topProj")) { print("$ProgName: Successfully inserted $generic into PTS.\n\n"); } else { print("$ProgName: $ars_errstr \n"); print("Unable to add $generic to PTS.\n\n"); $error += 1; } # Log off of PTS ars_Logoff($arHndl); # Exit exit $error; } |