python通过cx_Oracle模块监控oracle业务

1、要想通过python监控Oracle,可以使用cx_Oracle模块,还需配置环境变量,此处不做详解
关于cx_Oracle的版本,一定要和linux机器上的oracle版本以及python版本符合;

此处我的oracle版本是11g,python是2.7,因此我的cx_Oracle版本是cx_Oracle-5.2.1-11g-py27-1.x86_64.rpm,否则会报libcublas.so.12.1 cannot open shared object file no such file or directory类似的错误;

下面附python3脚本

cat /u01/app/oracle/scripts/unionpay.py

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import cx_Oracle,sys,os

'''
脚本备注
'''


sql = {
    'unionpay_success': "sql1",
    'unionpay_failed': "sql2'"
}


def Get_Item(itemkey):
    conn = None
    result = None

    try:
        conn = cx_Oracle.connect(‘数据库账号/密码@IP:端口/库名')
        cursor = conn.cursor()
        cursor.execute(sql[itemkey])
        rows = cursor.fetchall()
        if len(rows) == 1:

            result = rows[0][0]
        else:
            result = None

        cursor.close()
        conn.close()

    except Exception as e:
        print(e)
    finally:

        if not conn:
            conn.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值