def getip(): try: dbdict=get_dbinfo.getinfo()[0] dbconn=MySQLdb.connect(**dbdict) dbcur=dbconn.cursor() sql="select Center,IP_Address,Hostname from cb_config_ip where IP_Status=1" dbcur.execute(sql) data=dbcur.fetchall() dbconn.close() ipdict={} for t in data: if ipdict.has_key(t[0]): ipdict[t[0]].append(t[1:]) else: ipdict[t[0]]=[t[1:]] #print ipdict return ipdict except Exception,e: getiperr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'getip-connect db get ip falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(getiperr,e)) return getiperr
def getcmd(): try: dbdict=get_dbinfo.getinfo()[0] dbconn=MySQLdb.connect(**dbdict) dbcur=dbconn.cursor() sql="select CB_Action,CB_Command from cb_config_cmd where CMD_Status=1" dbcur.execute(sql) data=dbcur.fetchall() dbconn.close() cmddict={} for t in data: if cmddict.has_key(t[0]): cmddict[t[0]].append(t[1]) else: cmddict[t[0]]=[t[1]] #print cmddict return cmddict except Exception,e: getcmderr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'getcmd-connect db get cmd falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(getcmderr,e)) return getcmderr