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-alert.py
import cx_Oracle
import os
import datetime
from time import localtime, strftime, strptime
import ConfigParser


# check-oracle-alert.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 = ''
    nerros = 0
    for instance in instances:
      os.environ['ORACLE_SID'] = instance
      conn = cx_Oracle.connect(user, password, mode=cx_Oracle.SYSDBA)
      cursor = conn.cursor()
      sql = """select to_char(ORIGINATING_TIMESTAMP,'dd/mm/yyyy hh24:mi:ss'), MESSAGE_TEXT
          from X$DBGALERTEXT 
          where (message_text like '%ORA-%'
            or message_text like '%Corrupt%')
           and ORIGINATING_TIMESTAMP >= sysdate-1/24/60*10        
            order by 1"""
      cursor.execute(sql)
      result = cursor.fetchall()
      rowcount = cursor.rowcount
      cursor.close()
      if rowcount <> 0:
        check_message = check_message + ' (!!) Error found on database : ' + instance 
        for row in result:
          mess = str(row[1])
          check_message = check_message + ' ' + row[0] + ' - ' + mess + '\n'
          nerros += 1
      else:
          check_message = check_message + ' No error found on database : ' + instance
    check_message = check_message.split('\n')
    if nerros <> 0:
      return [2, str(check_message) ]
    else:
      return [0, str(check_message) ]
  except Exception, e:
    return [2, '{0}'.format(str(e)) ]