HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //usr/lib/python2.7/site-packages/lap/check-oracle-locks.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')
  lock_critical = cf.getint('oracle', 'lock_critical')
  lock_warning = cf.getint('oracle', 'lock_warning')
  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 count(1) FROM gv$session a , gv$session b WHERE a.BLOCKING_SESSION = b.sid AND a.blocking_instance = b.inst_id""")
      result = cursor.fetchall()
      rowcount = cursor.rowcount
      cursor.close()
      for row in result:
        locks_count = row[0]
        # Se locks_count >= entao alarma critico
        if locks_count >= lock_critical :
          check_message = check_message + '(!!) Number of locks in instance: ' + instance + ': ' + locks_count
          has_critical = has_critical + 1
        # Se locks_count >= lock_warning entao alarma warning
        elif locks_count >= lock_warning:
          check_message = check_message + '(!) Number of locks in instance: ' + instance + ': ' + locks_count
          has_warning= has_warning + 1
        else:
          check_message = check_message + 'Nenhum lock encontrado na instance: ' + instance + ' '
    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))]