Esempio n. 1
0
def startBusiness():
    dblist = connectDb.getConnectInfo(configurl + "dbConnect")
    if type(dblist) is str:
        return dblist
    
    #VOP库连接
    dbconn = connectDb.connectDb(dblist[0])
    
    if type(dbconn) is str:
        return dbconn
    cursor = connectDb.getCursor(dbconn)
    if type(cursor) is str:
        connectDb.closeConnect(dbconn)
        return cursor
    insert_log = ''
    try:
        deal_err = dealBusiness(dbconn,cursor)
        insert_log = insert_log + deal_err
    except Exception,e:
        
        Errdict = {'sqlErr':"监控程序异常,请查看报错日志信息,路径:" + err_log}
        arm_err = armErr(cursor,Errdict)
        insert_log = insert_log + arm_err
        is_err = connectDb.sqlcommit(dbconn)
        if type(is_err) is str:
            insert_log = insert_log +  "【异常信息告警插入日志数据," + is_err + "】"         
        with open(r'%s'%err_log,'a') as error_log:
        	print >> error_log,('%s 监控程序异常,%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),e))        
Esempio n. 2
0
def checkDB():
    resultlist = []
    dblists = connectDb.getConnectInfo()
    if type(dblists) is list :
        for dblist in dblists:
            #VOP库连接
            dbconn = connectDb.connectDb(dblist)
            if type(dbconn) is str:
                resultlist.append('数据库主机:%s ,登陆用户:%s, %s'%(dblist[2],dblist[0],dbconn))
                continue
            else:
                try:
                    dbconncr = dbconn.cursor()
                except Exception,e:
                    connectDb.closeCursor(dbconncr)
                    connectDb.closeConnect(dbconn)
                    getCurEX = '%s dealSql get cursor Faild'%(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                    with open(r'error.log','a') as error_log:
                    	print >> error_log,('%s %s' % (getCurEX,e))	                    
                    resultlist.append('数据库主机:%s ,登陆用户:%s, %s'%(dblist[2],dblist[0],getCurEX))
                    continue            
                try:
                    dbconncr.execute("select 1 from dual")
                    seqrst = dbconncr.fetchall()
                except Exception,e:
                    connectDb.sqlrollback(dbconn)
                    connectDb.closeCursor(dbconncr)
                    connectDb.closeConnect(dbconn)
                    exeSqlEX = '%s sql执行失败'%(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                    with open(r'error.log','a') as error_log:
                    	print >> error_log,('%s %s' % (exeSqlEX,e))	                    
                    resultlist.append('数据库主机:%s ,登陆用户:%s, %s'%(dblist[2],dblist[0],exeSqlEX))
                    continue

            try:
                if dbconn:
                    dbconn.commit()
                    dbconncr.close()
                    dbconn.close()
                    #print 'dbconn is closed'
            except Exception,e:
                exrst = '%s 数据库连接Close Faild'%(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                with open(r'error.log','a') as error_log:
                	print >> error_log,('%s %s' % (exrst,e))	                
                resultlist.append('数据库主机:%s ,登陆用户:%s, %s'%(dblist[2],dblist[0],exrst))
                continue
Esempio n. 3
0
    insert_log = ''
    try:
        deal_err = dealBusiness(dbconn,cursor)
        insert_log = insert_log + deal_err
    except Exception,e:
        
        Errdict = {'sqlErr':"监控程序异常,请查看报错日志信息,路径:" + err_log}
        arm_err = armErr(cursor,Errdict)
        insert_log = insert_log + arm_err
        is_err = connectDb.sqlcommit(dbconn)
        if type(is_err) is str:
            insert_log = insert_log +  "【异常信息告警插入日志数据," + is_err + "】"         
        with open(r'%s'%err_log,'a') as error_log:
        	print >> error_log,('%s 监控程序异常,%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),e))        

    clsCor = connectDb.closeCursor(cursor)
    clsCnt = connectDb.closeConnect(dbconn)
    
    if type(clsCor) is str:
        insert_log = insert_log + clsCor
    if type(clsCnt) is str:
        insert_log = insert_log + clsCnt
    
    if len(insert_log) == 0:
        pass
    else:
        with open(r'%s'%err_log,'a') as error_log:
        	print >> error_log,('%s 监控程序存在异常信息未处理,%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),insert_log))