sub ScpFile
{
##########################################################################################
#
# This subroutine sftps the output file.
#
##########################################################################################
my $file = shift(@_);
print "$file\n";
my $scp;
my $source = "/opt/app/CLI_DAE/log";
my $destination = "/tmp";
$scp = Net::SCP->new("90.168.72.193");
$scp->login("fhtw5x8") or [blue]ErrorOut[/blue] $scp->{errstr};
$scp->cwd("/tmp") or ErrorOut $scp->{errstr};
#$scp->size("file");
$scp->put("/opt/app/CLI_DAE/log/CLI_log.txt") or ErrorOut $scp->{errstr};
$scp->quit or [blue]ErrorOut[/blue] $scp->{errstr};
} # End sub SftpFile
sub VistaQuery
{
##########################################################################################
#
# This subroutine Queries the InfoVista DB and builds an ip to device type to vendor HoH
# for all the devices we will be querying.
#
##########################################################################################
my $sub_vendor;
my $sub_ip;
my $sub_dev_type;
my %sub_db_results;
my $data_source = "dbi:Oracle:binvdp01";
my $dbh = DBI->connect($data_source, $orauser, $orapass)
or [blue]ErrorOut[/blue] "Can't connect to $data_source: $DBI::errstr";
my $sth = $dbh->prepare( q{
select T1.SVALUE, T2.SVALUE, T3.SVALUE from twtpropvalues T1, twtpropvalues T2,
twtpropvalues T3 where T1.PROPID=(select ID from twtproperties
where WID='00000000000000000000000000000001') and T2.PROPID=
(select ID from twtproperties where WID='72B1577C795AB24888F4462B18D8F42D')
and T3.PROPID=(select ID from twtproperties where WID='069003638BAFDA11BCB000166F0D3E5D')
and T1.INSID=T2.INSID and T2.INSID=T3.INSID
}
) or [blue]ErrorOut[/blue] "Can't prepare statement: $DBI::errstr";
my $rc = $sth->execute
or [blue]ErrorOut[/blue] "Can't execute statement: $DBI::errstr";
print LOG "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n";
print LOG "Field names: @{ $sth->{NAME} }\n";
#
# Load query results into a HoH.
#
if ($debug ==1) {print LOG "Query results returned:\n\n";}
while (($sub_ip, $sub_vendor, $sub_dev_type) = $sth->fetchrow_array) {
if ($debug ==1) {print LOG "$sub_ip\t$sub_vendor\t$sub_dev_type\n";}
$sub_db_results{$sub_vendor}->{$sub_dev_type} = $sub_ip;
}
#
# search for problems which may have terminated the fetch early, disconnect and return the HoH.
#
ErrorOut $sth->errstr if $sth->err;
$dbh->disconnect;
print LOG "\nInfoVista query completed successfully.\n\n";
return (%sub_db_results);
} # End sub VistaQuery