When I say weird, I mean I tried to print the variable .i.e.
The value passed to the $grp was CIC
print "START~" . $grp . "~END\n";
which should have produced an output of START~CIC~END but it did not...it printed something like ENDsCIC
As I stated earlier the block of code being used to query the database works if I just put it in a simple script and pass the value into say $grp = $ARGV[0];
The only real difference I see between what I am doing in the LISTENER and the straight perl script is assigning initial groups array to begin
push(@groups, $buf)
versus
@groups = $ARGV[0];
Here is the rest of the code from the SOCK_DBI.pl<br/><br/>
# +--------------+
# | SUB ROUTINES |
# +--------------+
# SOCK_DBI.p
#
sub declareGlobalVariables {
$ORACLE_SID = "D0TALRT1";
$ORACLE_USERID = "dunnyuser";
$ORACLE_PASSWORD = "applesauce";
$ENV{'ORACLE_SID'} = "$ORACLE_SID";
$ENV{'ORACLE_HOME'} = "/opt/app/talertdb/oracle/9.2.0";
}
sub getOracleLogin {
local ($oracle_sid, $username, $password) = @_;
local ($temp_dbh);
local($tempID, $tempPassword, $tempKey);
local $conn = "dbi:Oracle:HOST=windsordb.wdc.gdc.net;SID=D0TALRT1;po
+rt=1521";
# unless ( $temp_dbh = DBI->connect( "DBI:Oracle:$oracle_sid"
unless ( $temp_dbh = DBI->connect( $conn
, "$username"
, $password
, {AutoCommit => 0}) ) {
&programError( "Oracle Login Failed as $username"
, ""
, "$DBI::errstr"
, "dba-mail"
, "dba-pager");
exit;
}
}
sub programError {
$logfile = "/opt/app/telalert/tmp/dbi_error";
open(ELOG, ">>$logfile") || die "Can't open filename: $logfile - $!\
+n";
local($message, $sql_statement, $ora_errstr) = @_;
print ELOG "+--------------------------+\n";
print ELOG "| SUB: programError |\n";
print ELOG "+--------------------------+\n";
print ELOG "\n";
unless($message) {$message = "No message provided from calling modul
+e.";}
print ELOG "+-------------------------------------------------------
++\n";
print ELOG "| ******************* PROGRAM ERROR *******************
+|\n";
print ELOG "+-------------------------------------------------------
++\n";
print ELOG "\n";
print ELOG "\n";
print ELOG "Message:\n";
print ELOG "--------------------------------------------------------
+\n";
print ELOG "$message\n";
print ELOG "\n";
if ($sql_statement) {
print ELOG "SQL:\n";
print ELOG "------------------------------------------------------
+--\n";
print ELOG "$sql_statement\n";
print ELOG "\n";
}
if ($ora_errstr) {
print ELOG "Oracle Error:\n";
print ELOG "------------------------------------------------------
+--\n";
print ELOG "$ora_errstr\n";
}
close(ELOG);
}
sub logoffOracle {
($dbh) = @_;
unless ($dbh->disconnect) {
1;
}
}
sub getGrpMembers {
my ($groupName) = @_;
my @members = ();
$sql_statement = "SELECT b.DISPLAY_NAME, b.MEMBER_TYPE FROM GR
+OUPS a, MEMBERS b WHERE a.NAME=\'$groupName\' AND a.ID=b.GROUP_ID";
unless ($cursor = $dbh->prepare("$sql_statement")) {
&programError( "Could not prepare SELECT_getGrpMembers_DBI c
+ursor"
, "$sql_statement"
, "$DBI::errstr");
$dbh->rollback;
&logoffOracle($dbh);
exit;
}
unless ($cursor->execute) {
&programError( "Could not execute SELECT_getGrpMembe
+rs_DBI cursor"
, "$sql_statement"
, "$DBI::errstr");
$dbh->rollback;
&logoffOracle($dbh);
exit;
}
while (($display_name, $member_type) = $cursor->fetchrow_array
+) {
push(@members, "$display_name~$member_type");
}
unless ($cursor->finish) {
&programError( "Could not finish SELECT_getGrpMember
+s_DBI cursor"
, "$sql_statement"
, "$DBI::errstr");
$dbh->rollback;
&logoffOracle($dbh);
exit;
}
return (@members);
}
1;
And if I take the same SOCK_DBI.pl and use the same functions in the next section of code it properly connects to the database and recursively extracts all the objects it is suppose to and therefore the ONLY difference I can determine is the fact that I am trying to use this function from within the IO::Socket object but for whatever reason it appears to be returning the value of the $grp variable in some weird way but I am not sure....
This code works well using the the exact same SOCK_DBI.pl
#!/opt/app/telalert/perl5.8.8/bin/perl
use DBI;
require "SOCK_DBI.pl";
&declareGlobalVariables;
# DBI->trace(1,'/tmp/dbi.log');
$dbh = &getOracleLogin("$ORACLE_SID", "$ORACLE_USERID", "$ORACLE_PASSW
+ORD");
$dbh->{LongReadLen} = 64000;
@groups = $ARGV[0];
$scale = scalar(@groups);
while( $scale > 0 ){
$grp = shift(@groups);
@members = &getGrpMembers($grp);
foreach $member (@members){
if( $member =~ /Destination/ ){($device, $trash) = split(/~/,
+$member); push(@dest, $device);}
if( $member =~ /User/ ){ ($user, $trash) = split(/~/, $member)
+; push(@dest, $user);}
if( $member =~ /Group/ ){($mem, $trash) = split(/~/, $member);
+ push(@groups, $mem);}
}
$scale = scalar(@groups);
}
$out = join("\n", @dest);
print $out;
&logoffOracle($dbh);
|