02-Install DBDOracle Perl Modules in Linux (Redhat-Centos-Debian-Ubuntu)
02-Install DBDOracle Perl Modules in Linux (Redhat-Centos-Debian-Ubuntu)
Install
We are going yo test with Oracle Instant Client 12. Software client can be downloaded from Oracle.
If you have not an Oracle account, you need register one previously. We must download packages
basic, sqlplus and devel. For Oracle client 12 in Redhat / Centos there are RPM packages
available. For Debian / Ubuntu we can convert packages from rpm format to deb format with
alien tool.
Example packages version to download:
oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-devel-12.1.0.1.0-1.x86_64.rpm
http://www.aboutmonitoring.com/
20/04/14
Debian / Ubuntu:
apt-get install libdbi-perl
Or with CPAN:
cpan> install DBI.pm
DBD::Oracle. Problem is this library. It's necessary download library source package and compile.
This perl library need use installed oracle libraries. Correct steps are:
1.- Oracle client or instant client installed and tested with tnsnames (environment variables
configured). CPAN is going to use this environment variables to find and oracle modules to
compile perl library.
2.- CPAN installed (yum install cpan)
3. With CPAN we must download DBD module
cpan> get DBD::Oracle
perl Makefile.PL
make
make install
http://www.aboutmonitoring.com/
20/04/14
Make must find oracle libraries and compile and install correctly.
At this point can be interesting to add library paths to /etc/ld.so.conf.d. Example paths:
/usr/local/lib64/perl5/auto/DBD
/usr/lib/oracle/12.1/client64/lib
We can now test nagios perl plugins for Oracle or another perl script to connect to Oracle. Try with
this script copied from http://www.idevelopment.info/
#!/usr/bin/perl
# TO CHANGE VARIABLES IN -> sub declareGlobalVariables
require "ctime.pl";
require "flush.pl";
use DBI;
&declareGlobalVariables;
&printHeader;
$dbh = &getOracleLogin("$ORACLE_SID", "$ORACLE_USERID", "$ORACLE_PASSWORD");
$dbh->{LongReadLen} = 64000;
&logoffOracle($dbh);
&printFooter;
exit;
# +--------------+
# | SUB ROUTINES |
# +--------------+
sub declareGlobalVariables {
# Change SID, USERID, PASSWORD and HOME!
$ORACLE_SID
= "SID_IN_TNSNAMES";
$ORACLE_USERID
= "user";
$ORACLE_PASSWORD
= "pass";
$ENV{'ORACLE_SID'}
= "$ORACLE_SID";
$ENV{'ORACLE_HOME'}
= "/usr/lib/oracle/11.2/client641";
}
sub printHeader {
print "\n";
print "Running testDBDOracle.pl...\n";
print "\n";
}
sub printFooter {
print "Ending testDBDOracle.pl...\n";
print "\n";
}
sub getOracleLogin {
local ($oracle_sid, $username, $password) = @_;
local ($temp_dbh);
http://www.aboutmonitoring.com/
20/04/14
http://www.aboutmonitoring.com/
20/04/14