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


# check-oracle-asm.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('asm', 'user')
  password = cf.get('asm', 'passwd')
  oracle_home = cf.get('asm', 'oracle_home')
  pct_critical = cf.getint('oracle', 'pct_critical')
  pct_warning = cf.getint('oracle', 'pct_warning')
  instances = cf.get('asm','instances')

  os.environ['ORACLE_HOME'] = oracle_home
  try:
    instances = instances.split();
    check_message = ''
    criticals = 0
    warnings = 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 name, (case when total_mb <> 0 then round(total_mb,2) end), 
       (case when total_mb <> 0 then round(free_mb/total_mb*100,2) end),
       (case when total_mb <> 0 then round(free_mb/1024,2) end)
       FROM V$ASM_DISKGROUP
       where total_mb <> 0 and free_mb <> 0"""
      cursor.execute(sql)
      result = cursor.fetchall()
      rowcount = cursor.rowcount
      cursor.close()
      if rowcount <> 0:
        for row  in result:
          grp_name = row[0]
          pct_free = row[2]
          size_free = row[3]

          if pct_free <= pct_critical :
            criticals = criticals + 1
            check_message = check_message + '(!!)' + grp_name + ' Livre(' + str("%.2f" % pct_free) + '%/' + str("%u" % size_free) + 'GB)\\n'
          elif pct_free <= pct_warning:
            warnings = warnings + 1
            check_message = check_message + '(!)' + grp_name + ' Livre(' + str("%.2f" % pct_free) + '%/' + str("%u" % size_free) + 'MB)\\n'
          else:
            check_message = check_message + grp_name + ' Livre(' + str("%.2f" % pct_free) + '%/' + str("%u" % size_free) + 'MB)\\n'  
    if criticals > 0:
      final_message = 'Existem diskgroups em estado critico!\\n' + check_message
      return [2, '%s' % (final_message) ]
    
    elif warnings > 0:
      final_message = 'Existem diskgroups em estado warning!\\n' + check_message
      return [1, '%s' % (final_message) ]
    
    elif warnings == 0 and criticals == 0:
      final_message = 'Diskgroups sem alarme de espaco\\n' + check_message
      return [0, '%s' % (final_message) ]

  except Exception, e:
    return [2, '{0}'.format(str(e)) ]