Use perl to connect to Oracle ASM as sysdba


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use perl to connect to Oracle ASM as sysdba
# 1  
Old 02-23-2012
Use perl to connect to Oracle ASM as sysdba

I am novice to perl. Can someone guide me on the below query. We have an existing perl script which connects to database to check the disk group status which i wanted to retieve directly from ASM rather than database.
This is because, a cluster has more than 4 databases running and a check on each database would report same diskgroup infiormation.

Hence had modified the exitsting script as shown below ...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/perl
#####################################################################
# #
# ASM Diskgroup space usage #
# #
#####################################################################
use lib '.';
#use lib "/opt/nagios/libexec";
use nagios_dbcheck_lib;
#use strict;
use warnings;
use Getopt::Long;
use DBI;
use DBD::Oracle qw(Smiliera_session_modes);

#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Global Variables #
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Nagios Thresholds
my %G_SETTINGS = (
asmdgspace => { warning => 15, critical => 10 }, # Free extends.
);
my %G_PARAMS; # Script parameters
my $nagios_message = " "; # Body of nagios email
my $debug = 0; # troubleshooting only, must be 0 in production!
my $warning_thresh = 0;
my $critical_thresh = 0;

#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Parameter Checks #
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
GetOptions(
"sid=s" => \$G_PARAMS{sid}, # can be a service, too. Must be defined in tnsnames.ora
);
# sanity check
foreach my $key (keys %G_PARAMS) {
if ( !defined ($G_PARAMS{$key}) ) {
print "UNKNOWN - mandatory parameters not passed to script\n";
help();
exit 3
}
}

#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Nagios Check Code #
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#

print "ASM Diskgroup space usage check\n" if $debug;
my $query = "
SELECT (CASE
WHEN (total_mb/1024) >= 2000 AND (free_mb/1024) < 150 THEN 'CRITICAL'
WHEN (total_mb/1024) < 2000 AND (free_mb/total_mb*100) < $G_SETTINGS{asmdgspace}{critical} THEN 'CRITICAL'
WHEN (free_mb/total_mb*100) between $G_SETTINGS{asmdgspace}{critical} and $G_SETTINGS{asmdgspace}{warning} THEN 'WARNING'
ELSE 'N/A'
END) Alert,
NAME,
TOTAL_MB,
FREE_MB,
ROUND(free_mb/total_mb*100, 2) pct_free,
STATE,
OFFLINE_DISKS from v\$ASM_DISKGROUP_STAT
where (free_mb/total_mb*100) <= $G_SETTINGS{asmdgspace}{warning}";


my $sth = runAsmCheck($G_PARAMS{sid}, $query);
while ( my $r = $sth->fetchrow_hashref('NAME_lc')) {
$nagios_message .= "ASM Diskgroup filling: $r->{name} Total(MB): $r->{total_mb} Free(MB): $r->{free_mb} PCT_Free: ($r->{pct_free} %) \n";
$critical_thresh = 1 if ($r->{alert} eq "CRITICAL" );
$warning_thresh = 1 if ($r->{alert} eq "WARNING" );
}
$sth->finish;
dbh_dc();

cleanup_and_exit("CRITICAL"," Priority 2: ASM Diskgroup Filling | " . $nagios_message) if $critical_thresh;
cleanup_and_exit("WARNING"," Priority 3: ASM Diskgroup Filling | " . $nagios_message) if $warning_thresh;
cleanup_and_exit("OK","No problem detected |");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note: runAsmCheck is a subroutine within the script nagios_dbcheck_lib.pm and that reads as ...


sub runAsmCheck {
my ($sid, $query) = @_;
# connect to the database
eval {
$dbh = DBI->connect(
"dbi:Oracle:sid=$sid",
"nagiosmon", "password", { ora_session_mode => 2 }, { RaiseError => 1, AutoCommit => 0 });
};
if ($@) {
print "ERROR";
my $dbi_errorstr;
if (DBI::errstr) {
$dbi_errorstr = DBI::errstr;
}else{
$dbi_errorstr = "";
}
cleanup_and_exit("CRITICAL", "Failed to connect to database $sid | " . $dbi_errorstr);
}
my $sth = $dbh->prepare($query);
$sth->execute();
return $sth;
}

It simply reports failed to connect ...

$ perl check_asm_diskgroup_space_usage.pl -s whqa
ERRORCRITICAL - Failed to connect to database whqa


Thanks
# 2  
Old 07-31-2012
Progress

Did you ever get this figured out? I have been tasked with monitoring ASM through nagios. It looks like your script is what I'm looking for.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Oracle ASM on Solaris 11.3

Hi Folks, I've just built a Solaris 11.3 server with a number of LDOM's, all good and well and not any serious issues so far. On our older Solaris 10 systems we ran Oracle 11g using ASM disks, these disks were the raw device meta disks and came in very nicely as "/dev/md/rdsk/dnn" all worked... (4 Replies)
Discussion started by: gull04
4 Replies

2. Shell Programming and Scripting

Connect to Oracle with Perl through Cygwin

I try to connect to Oracle through cygwin, but it fails. The Oracle version 11.2 is installed on a Windows 2003 server. Cygwin and Perl is installed on the same server. cygwin>uname -a CYGWIN_NT-5.2 N0871 1.7.9(0.237/5/3) 2011-03-29 10:10 i686 Cygwin cygwin>perl -v This is perl, v5.10.1... (3 Replies)
Discussion started by: MSiipola
3 Replies

3. Shell Programming and Scripting

Switching user to oracle to connect Oracle 11g DB with 'sysdba'

I need to connect my Oracle 11g DB from shell script with 'sysdba' permissions. To do this I have to switch user from 'root' to 'oracle'. I've tried the following with no success. su - oracle -c "<< EOF1 sqlplus -s "/ as sysdba" << EOF2 whenever sqlerror exit sql.sqlcode;... (2 Replies)
Discussion started by: NetBear
2 Replies

4. Programming

Help on a perl script to connect to oracle ASM as sysdba

I am novice to perl. Can someone guide me on the below query. We have an existing perl script which connects to database to check the disk group status which i wanted to retieve directly from ASM rather than database. This is because, a cluster has more than 4 databases running and a check on... (0 Replies)
Discussion started by: sai_rsk
0 Replies

5. AIX

Oracle ASM accidentally messed with my hdisk

I have AIX 5.3 with oracle 10g ( test server). While trying to create RAW disk for Oracle ASM I have accidentally messed with rootvg (hdisk0 & hdisk1) When I do # lspv hdisk0 0516-066 : Physical volume is not a volume group member. Check the physical volume name specified. ... (4 Replies)
Discussion started by: George_Samaan
4 Replies

6. Shell Programming and Scripting

Perl connect to remote oracle db without local oracle installation

I want to use Perl to connect to a remote Oracle DB I have no oracle installation on my server (and dont plan on installing one) I am using solaris 9 on x86 server. Is this possible? I basically want to run some basic sql queries on the remote oracle db which I have access to using perl on my... (0 Replies)
Discussion started by: frustrated1
0 Replies

7. Shell Programming and Scripting

How to connect ORACLE using PERL

Hi Friends, I am having Perl 5 and Oracle 9i. I just wanna to connect Oracle DB & to perform some select query statement. Could anyone pls let me know. I've tried below command which i found in some website, But it throws some error.:confused: Executed: perl -e 'use DBI; print... (1 Reply)
Discussion started by: Vijayakumarpc
1 Replies

8. Red Hat

ORACLE RAC ASM disk question

Perhaps someone here has some experience with this. machine os RHE 4 6 oracle 10g RAC disk is SAN attached clariion. I have presented new disks to the host, so the machine sees all needed LUNS. powermt shows them, they are labeled and i have fdisk'd them. They are visible across all RAC... (5 Replies)
Discussion started by: Eronysis
5 Replies

9. Solaris

asm vs disksuite for oracle

I'm running solaris, with solstice disksuite. With other systems, i run veritas volume manager. My dba want to implement ASM with oracle 10g. Is it possible to create volumes with disksuite for ASM. Oracle want a volume name ex: vol1 My question is, what is the best STANDARD solution. ... (5 Replies)
Discussion started by: simquest
5 Replies

10. Shell Programming and Scripting

HOw to connect oracle using ksh and perl script

HI, So far i have been worked on sybase with perl and ksh scripts, i don't know how to connect using oralce, if any body could explain that is great. Thanks in advance. chendra (3 Replies)
Discussion started by: chendra.putta
3 Replies
Login or Register to Ask a Question