# used to lookup_values from the CSSD database sub lookup_NTSD_val { LogIt( $fhDEBUG, "=x" x 40 ); # so we can see the start of a new "run" LogIt( $fhDEBUG,"Entering sub:lookup_NTSD_val args: @_") if $CONFIG{DEBUG} > 3; my $cols = shift; # comma sep my $table = shift; my $criteria = shift; LogIt( $fhDEBUG,"calling: lookup( $cols, $table, $criteria);") if $CONFIG{DEBUG}>1; my $NTSDval = lookup($CONFIG{"NTSD_DB_DSN"}, $cols, $table, $criteria); LogIt( $fhDEBUG, "lookup_NTSD_val got result \"" . $NTSDval->{$cols} . "\"") if $CONFIG{DEBUG}>1; if ($NTSDval->{$cols} == ""){ ++$EVENT->{'slots'}->{'NTSD_DATA'}; } LogIt( $fhDEBUG, "NTSD_DATA now equals \"" . $EVENT->{'slots'}->{'NTSD_DATA'} . "\"") if $CONFIG{DEBUG}>1; return( $NTSDval->{ $cols }); } sub lookup { LogIt( $fhDEBUG, "Entering sub:lookup args: @_") if $CONFIG{DEBUG} > 3; my $DSN = shift; # comma sep my $cols = shift; my $table = shift; my $criteria = shift; my $LookupResult; # Let's create the Connection object used to establish the connection # my $conn = Win32::OLE->CreateObject('ADODB.Connection'); # Open a connection using the SQL Server OLE DB Provider LogIt( $fhDEBUG, "Opening ADODB connection") if $CONFIG{DEBUG} > 3; $conn->Open(< 3; # changed above line to log status of connection # LogIt( $fhDEBUG, $connStatus) if $CONFIG{DEBUG} > 3; # End of 07/04/09 changes my $sql =< 3; my $rs = $conn->Execute($sql); LogIt( $fhDEBUG, "COMPLETE: executing SQL") if $CONFIG{DEBUG} > 3; if( !defined( $rs ) ){ LogIt( $fhDEBUG,"something went wrong: ", Win32::OLE->LastError()); LogIt( $fhERROR, "something went wrong: ", Win32::OLE->LastError()); die " died something went wrong: ", Win32::OLE->LastError(),"\n"; } while( ! $rs->EOF) { my $i= 0; COL: foreach my $col (split /,/, $cols) { next COL unless $col =~ /\w+/; LogIt( $fhDEBUG,"getting val for \$col $col") if $CONFIG{DEBUG} > 3; LogIt( $fhDEBUG,"Value: ". $rs->Fields($i)->value) if $CONFIG{DEBUG} > 3; $LookupResult->{$col} = $rs->Fields($i)->value; trim( $LookupResult->{$col}); $i++; } $rs->MoveNext; } LogIt( $fhDEBUG, "Closing ADODB connection") if $CONFIG{DEBUG} > 3; $conn->Close(); ( map { LogIt( $fhDEBUG,"". $_ ) } split /\n/, Dumper $LookupResult ) if $CONFIG{DEBUG} > 3; return( $LookupResult ); } sub trim { LogIt( $fhDEBUG,"Entering sub:trim args: @_") if $CONFIG{DEBUG} > 3; for(@_) { s/^\s+//; s/\s+$//; } } #### main::Entering sub:lookup_NTSD_val args: [Highest Site Category] [Servers] left([Server], 9) = 'ServerXXX' main::lookup Opening ADODB connection main::lookup COMPLETE: Opening ADODB connection main::lookup SELECT [Highest Site Category] main::lookup FROM [Servers] main::lookup WHERE left([Server], 9) = 'ServerXXX' main::lookup COMPLETE: executing SQL main::lookup getting val for $col [Highest Site Category] main::lookup Value: D main::trim Entering sub:trim args: D main::lookup Closing ADODB connection main::lookup $VAR1 = { '[Highest Site Category]' => 'D' }; main::lookup_NTSD_val lookup_NTSD_val got result "D" #### main::lookup_NTSD_val Entering sub:lookup_NTSD_val args: '[ServerDescription]','[ServerLocation]','[ServerDomain]','[ServerServiceNo]','[AsstNo]','[ApproxUsers]','[IPAddress1]','[SvrStatus]','[OSVersion]' [ServerComp] left([ServerName], 9) = 'ServerXXX' main::lookup Opening ADODB connection main::lookup COMPLETE: Opening ADODB connection main::lookup SELECT '[ServerDescription]','[ServerLocation]','[ServerDomain]','[ServerServiceNo]','[AsstNo]','[ApproxUsers]','[IPAddress1]','[SvrStatus]','[OSVersion]' main::lookup FROM [ServerComp] main::lookup WHERE left([ServerName], 9) = 'ServerXXX' main::lookup COMPLETE: executing SQL main::lookup getting val for $col '[ServerDescription]' main::lookup Value: [ServerDescription] main::trim Entering sub:trim args: [ServerDescription] main::lookup getting val for $col '[ServerLocation]' main::lookup Value: [ServerLocation] main::trim Entering sub:trim args: [ServerLocation] main::lookup getting val for $col '[ServerDomain]' main::lookup Value: [ServerDomain] main::trim Entering sub:trim args: [ServerDomain] main::lookup getting val for $col '[ServerServiceNo]' main::lookup Value: [ServerServiceNo] main::trim Entering sub:trim args: [ServerServiceNo] main::lookup getting val for $col '[AsstNo]' main::lookup Value: [AsstNo] main::trim Entering sub:trim args: [AsstNo] main::lookup getting val for $col '[ApproxUsers]' main::lookup Value: [ApproxUsers] main::trim Entering sub:trim args: [ApproxUsers] main::lookup getting val for $col '[IPAddress1]' main::lookup Value: [IPAddress1] main::trim Entering sub:trim args: [IPAddress1] main::lookup getting val for $col '[SvrStatus]' main::lookup Value: [SvrStatus] main::trim Entering sub:trim args: [SvrStatus] main::lookup getting val for $col '[OSVersion]' main::lookup Value: [OSVersion] main::trim Entering sub:trim args: [OSVersion] main::lookup Closing ADODB connection main::lookup $VAR1 = { '\'[ServerServiceNo]\'' => '[ServerServiceNo]', '\'[ServerDomain]\'' => '[ServerDomain]', '\'[ServerLocation]\'' => '[ServerLocation]', '\'[OSVersion]\'' => '[OSVersion]', '\'[ApproxUsers]\'' => '[ApproxUsers]', '\'[AsstNo]\'' => '[AsstNo]', '\'[ServerDescription]\'' => '[ServerDescription]', '\'[SvrStatus]\'' => '[SvrStatus]', '\'[IPAddress1]\'' => '[IPAddress1]' }; main::lookup_NTSD_val lookup_NTSD_val got result ""