Esempio n. 1
0
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
# auther:keve
from server.core.getconfig import get_conf
import MySQLdb
import MySQLdb.cursors

DB_HOST=get_conf('db','DB_HOST').strip()
DB_PORT=int(get_conf('db','DB_PORT'))
DB_NAME=get_conf('db','DB_NAME')
DB_USER=get_conf('db','DB_USER')
DB_PAWD=get_conf('db','DB_PAWD')

class Pymysql:
    def __init__(self):
        self.conn = None
    def _connect(self):
        '''建立一个新的连接,从config.ini 获取mysql信息'''
        try:
            self.conn=MySQLdb.connect(host=DB_HOST,port =DB_PORT,user =DB_USER,passwd=DB_PAWD,db=DB_NAME)
            return self.conn
        except MySQLdb.Error,err:
            print err[1]
            self.conn = None
            return self.conn
    def close_connect(self):
        """
        关闭连接
        """
        if (self.conn.open) == True:
            self.conn.close()
Esempio n. 2
0
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
# auther:F.W

import connect_db
from server.template import templates
from server.core import getconfig
from server.utils import xpickle
from server.cache import redisengine

redis_server = eval(getconfig.get_conf("redis",'all_redis'))
r = redisengine.RedisEngine(redis_server)
def get_status():

    status =r.get_data("1","status")
    return status


def get_host_config(address):
    """
    get monitor configuration info for host server
    :args address:
    :return: dict
    """

    db = connect_db.Pymysql()
    host_data = db.findall("host_ip",where="ip",val=address)
    if host_data:
        for i in host_data:
            port = i['port']
            hostname = i['hostname']