cx_Oracle and LD_LIBRARY_PATH

Hi,

I just started to use Nagios to help monitoring our systems and i’m kind of new using linux too. I’m having some headaches getting one python script working with cx_Oracle lib, maybe u can help me solving this one. I’m using Debian Lenny with Nagios 3.0.6. The purpose is to check tablespaces avaiability. The problem begins when i execute it with a normal user giving me the result i want but when i try to run it as sudo i don’t have LD_LIBRARY_PATH set then it fails as i show in this 2 examples:

(running with su)

svmlinagiosdeb:/usr/lib/nagios/plugins# ./check_tablespace -u system -p change_on_install -s srvinfordb02.world INFORDB SYSTEM
Traceback (most recent call last):
  File "./check_tablespace", line 3, in <module>
    import cx_Oracle
ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory

The result i want is (running as normal user):

administrator@svmlinagiosdeb:/usr/lib/nagios/plugins$ ./check_tablespace -u system -p change_on_install -s srvinfordb02.world INFORDB SYSTEM
OK: Tablespace SYSTEM 'ONLINE' com 74.21% de ocupacao.
OK: Tablespace INFORDB 'ONLINE' com 52.35% de ocupacao.

commands.cfg

define command{ command_name check_tablespace command_line /usr/lib/nagios/plugins/check_tablespace -u $ARG1$ -p $ARG2$ -s $ARG3$ -w 85 -c 90 $ARG4$ $ARG5$ $ARG6$ $ARG7$ $ARG7$ }

host.cfg

define service{ use generic-service host_name srvinfordb02 service_description TABLESPACES check_command check_tablespace!system!change_on_install!srvinfordb02.world!INFORDB!SYSTEM }

check_tablespace

[code]#!/usr/bin/python

import cx_Oracle
import sys
import getopt

def usage():
print 'Ex: check_tablespaces -h|–help] -u] $USERNAME -p] $PASSWORD -s] $SID -w] $VALUE -c] $VALUE $TSPC1 $TSPC2 $TSPC3 $TSPC4 … '
sys.exit(3)

try:
options, args = getopt.getopt(sys.argv[1:],‘hu:p:s:w:c:’)
except getopt.GetoptError, err:
usage()
sys.exit(3)

l_w = 85
l_c = 90

for name, value in options:
if name in (’-u’):
l_user = value

if name in ('-p'):
	l_pass = value

if name in ('-s'):
	l_sid = value

if name in ('-w'):
	l_w = int(value)

if name in ('-c'):
	l_c = int(value)

l_comma = 0
l_tblspc = ‘’

for l_item in args:
if l_comma == 0:
l_tblspc = ‘’’ + l_item + ‘’‘
l_comma = 1
else:
l_tblspc += ‘,’’ + l_item + ‘’’

if l_tblspc == ‘’:
usage()

conn = cx_Oracle.connect(l_user + ‘/’ + l_pass + ‘@’ + l_sid)
cursor = conn.cursor()

query = ‘select a.TABLESPACE_NAME, c.status, round(((a.BYTES-b.BYTES)/a.BYTES)*100,2) percent_used
from
(
select TABLESPACE_NAME,
sum(BYTES) BYTES
from dba_data_files
where tablespace_name in (’ + l_tblspc + ‘)
group by TABLESPACE_NAME
) a,
(
select TABLESPACE_NAME, sum(BYTES) BYTES, max(BYTES) largest
from dba_free_space
where tablespace_name in (’ + l_tblspc + ‘)
group by TABLESPACE_NAME
) b,
(
select STATUS, TABLESPACE_NAME
from dba_tablespaces
where tablespace_name in (’ + l_tblspc + ‘)
) c
where a.TABLESPACE_NAME = b.TABLESPACE_NAME
and b.TABLESPACE_NAME = c.TABLESPACE_NAME
order by ((a.BYTES-b.BYTES)/a.BYTES) desc’

cursor.execute(query)

erro = 0

for row in cursor:
alert = ‘OK’

if row[2] >= l_w:
	erro = 1
	alert = 'WARNING'

if row[2] >= l_c:
	erro = 2
	alert = 'CRITICAL'

if row[1] == 'OFFLINE':
	erro = 2
	alert = 'CRITICAL'

print alert + ': Tablespace ' + row[0] + ' \'' + row[1] + '\' com ' + str(row[2]) + '% de ocupacao.'

sys.exit(erro)

cursor.close()
conn.close()[/code]

Nagios is giving me an warning alert with “(null)” on status information.

Is there a way i can solve this?

Thank you for your help.

Best regards,

Bruno Marinho

assuming solaris os :
run ldd on the check_tablespace

Add the path of the missing lib to LD_LIBRARY_PATH.

you should be fine after that.