File: //usr/lib/python2.7/site-packages/lap/check-oracle-processes.py
import cx_Oracle
import os
import datetime
from time import localtime, strftime, strptime
import ConfigParser
# check-oracle-locksm.py
#
# to cx_Oracle work, you need:
# 1. set LIBRARY_PATH correctly
# 2. configure yaml file
# 3. echo /u01/app/oracle/product/11.2.0.3/db/lib > /etc/ld.so.conf.d/oracle.conf
# ldconfig
def __run__(params):
conn = None
cf = ConfigParser.ConfigParser()
config_file = params.get('config_file')
cf.readfp(open(config_file))
user = cf.get('oracle', 'user')
password = cf.get('oracle', 'passwd')
oracle_home = cf.get('oracle', 'oracle_home')
instances = cf.get('oracle','instances')
os.environ['ORACLE_HOME'] = oracle_home
try:
instances = instances.split();
check_message = ''
has_critical = 0
has_warning = 0
for instance in instances:
os.environ['ORACLE_SID'] = instance
conn = cx_Oracle.connect(user, password, mode=cx_Oracle.SYSDBA)
cursor = conn.cursor()
cursor.execute("""select CURRENT_UTILIZATION, LIMIT_VALUE, CURRENT_UTILIZATION*100/LIMIT_VALUE
from v$resource_limit
where resource_name='processes'
""")
result = cursor.fetchall()
rowcount = cursor.rowcount
cursor.close()
for row in result:
curr_proc=row[0]
limit_proc=row[1]
perc_util_proc=row[2]
if perc_util_proc >= 90 :
check_message = check_message + '(!!) % in use of processes in instance: ' + instance + ' is ' + str(curr_proc) + '/' + str(perc_util_proc) + '% of ' + str(limit_proc)
has_critical = has_critical + 1
elif perc_util_proc >=80:
check_message = check_message + '(!) % in use of processes in instance: ' + instance + ' is ' + str(curr_proc) + '/' + str(perc_util_proc) + '% of ' + str(limit_proc)
has_warning= has_warning + 1
else:
check_message = check_message + '% in use of processes in instance:' + instance + ' is ' + str(curr_proc) + '/' + str(perc_util_proc) + '% of ' + str(limit_proc)
if has_critical <> 0:
return [2, str(check_message) ]
elif has_warning <> 0:
return [1, str(check_message) ]
else:
return [0, str(check_message) ]
except Exception, e:
return [2, '{0}'.format(str(e))]