# Path: rrd/config.py
# LOG_LEVEL = os.environ.get("LOG_LEVEL",'DEBUG')
# SECRET_KEY = os.environ.get("SECRET_KEY","secret-key")
# PERMANENT_SESSION_LIFETIME = os.environ.get("PERMANENT_SESSION_LIFETIME",3600 * 24 * 30)
# SITE_COOKIE = os.environ.get("SITE_COOKIE","open-falcon-ck")
# API_ADDR = os.environ.get("API_ADDR","http://127.0.0.1:18080/api/v1")
# API_USER = os.environ.get("API_USER","admin")
# API_PASS = os.environ.get("API_PASS","password")
# PORTAL_DB_HOST = os.environ.get("PORTAL_DB_HOST","127.0.0.1")
# PORTAL_DB_PORT = int(os.environ.get("PORTAL_DB_PORT",3306))
# PORTAL_DB_USER = os.environ.get("PORTAL_DB_USER","falcon")
# PORTAL_DB_PASS = os.environ.get("PORTAL_DB_PASS","falcon")
# PORTAL_DB_NAME = os.environ.get("PORTAL_DB_NAME","falcon_portal")
# ALARM_DB_HOST = os.environ.get("ALARM_DB_HOST","127.0.0.1")
# ALARM_DB_PORT = int(os.environ.get("ALARM_DB_PORT",3306))
# ALARM_DB_USER = os.environ.get("ALARM_DB_USER","root")
# ALARM_DB_PASS = os.environ.get("ALARM_DB_PASS","")
# ALARM_DB_NAME = os.environ.get("ALARM_DB_NAME","alarms")
# LDAP_ENABLED = os.environ.get("LDAP_ENABLED",False)
# LDAP_SERVER = os.environ.get("LDAP_SERVER","ldap.forumsys.com:389")
# LDAP_BASE_DN = os.environ.get("LDAP_BASE_DN","dc=example,dc=com")
# LDAP_BINDDN = os.environ.get("LDAP_BINDDN","cn=manager,dc=example,dc=org")
# LDAP_BIND_PASS = os.environ.get("LDAP_BIND_PASS","password")
# LDAP_SEARCH_FMT = os.environ.get("LDAP_SEARCH_FMT","uid=%s")
# LDAP_ATTRS = ["cn","mail","telephoneNumber"]
# LDAP_TLS_START_TLS = False
# LDAP_TLS_CACERTDIR = ""
# LDAP_TLS_CACERTFILE = "/etc/openldap/certs/ca.crt"
# LDAP_TLS_CERTFILE = ""
# LDAP_TLS_KEYFILE = ""
# LDAP_TLS_REQUIRE_CERT = True
# LDAP_TLS_CIPHER_SUITE = ""
# BABEL_DEFAULT_LOCALE   = 'zh_CN'
# BABEL_DEFAULT_TIMEZONE = 'Asia/Shanghai'
# LANGUAGES   = {
#     'en':  'English',
#     'zh_CN':  'Chinese-Simplified',
# }
# MAINTAINERS = ['root']
# CONTACT = 'root@open-falcon.com'
# DEBUG = True
# 
# Path: rrd/utils/logger.py



import MySQLdb
from rrd import config
from rrd.utils.logger import logging


portal_db_cfg = {
        "DB_HOST": config.PORTAL_DB_HOST,
        "DB_PORT": config.PORTAL_DB_PORT,
        "DB_USER": config.PORTAL_DB_USER,
        "DB_PASS": config.PORTAL_DB_PASS,
        "DB_NAME": config.PORTAL_DB_NAME,
}

alarm_db_cfg = {
        "DB_HOST": config.ALARM_DB_HOST,
        "DB_PORT": config.ALARM_DB_PORT,
        "DB_USER": config.ALARM_DB_USER,
        "DB_PASS": config.ALARM_DB_PASS,
        "DB_NAME": config.ALARM_DB_NAME,
}

def connect_db(cfg):
    try:
        conn = MySQLdb.connect(
            host=cfg['DB_HOST'],
            port=cfg['DB_PORT'],
            user=cfg['DB_USER'],
            passwd=cfg['DB_PASS'],
            db=cfg['DB_NAME'],
            use_unicode=True,
            charset="utf8")
        return conn
    except Exception, e:

# Path: rrd/config.py
# LOG_LEVEL = os.environ.get("LOG_LEVEL",'DEBUG')
# SECRET_KEY = os.environ.get("SECRET_KEY","secret-key")
# PERMANENT_SESSION_LIFETIME = os.environ.get("PERMANENT_SESSION_LIFETIME",3600 * 24 * 30)
# SITE_COOKIE = os.environ.get("SITE_COOKIE","open-falcon-ck")
# API_ADDR = os.environ.get("API_ADDR","http://127.0.0.1:18080/api/v1")
# API_USER = os.environ.get("API_USER","admin")
# API_PASS = os.environ.get("API_PASS","password")
# PORTAL_DB_HOST = os.environ.get("PORTAL_DB_HOST","127.0.0.1")
# PORTAL_DB_PORT = int(os.environ.get("PORTAL_DB_PORT",3306))
# PORTAL_DB_USER = os.environ.get("PORTAL_DB_USER","falcon")
# PORTAL_DB_PASS = os.environ.get("PORTAL_DB_PASS","falcon")
# PORTAL_DB_NAME = os.environ.get("PORTAL_DB_NAME","falcon_portal")
# ALARM_DB_HOST = os.environ.get("ALARM_DB_HOST","127.0.0.1")
# ALARM_DB_PORT = int(os.environ.get("ALARM_DB_PORT",3306))
# ALARM_DB_USER = os.environ.get("ALARM_DB_USER","root")
# ALARM_DB_PASS = os.environ.get("ALARM_DB_PASS","")
# ALARM_DB_NAME = os.environ.get("ALARM_DB_NAME","alarms")
# LDAP_ENABLED = os.environ.get("LDAP_ENABLED",False)
# LDAP_SERVER = os.environ.get("LDAP_SERVER","ldap.forumsys.com:389")
# LDAP_BASE_DN = os.environ.get("LDAP_BASE_DN","dc=example,dc=com")
# LDAP_BINDDN = os.environ.get("LDAP_BINDDN","cn=manager,dc=example,dc=org")
# LDAP_BIND_PASS = os.environ.get("LDAP_BIND_PASS","password")
# LDAP_SEARCH_FMT = os.environ.get("LDAP_SEARCH_FMT","uid=%s")
# LDAP_ATTRS = ["cn","mail","telephoneNumber"]
# LDAP_TLS_START_TLS = False
# LDAP_TLS_CACERTDIR = ""
# LDAP_TLS_CACERTFILE = "/etc/openldap/certs/ca.crt"
# LDAP_TLS_CERTFILE = ""
# LDAP_TLS_KEYFILE = ""
# LDAP_TLS_REQUIRE_CERT = True
# LDAP_TLS_CIPHER_SUITE = ""
# BABEL_DEFAULT_LOCALE   = 'zh_CN'
# BABEL_DEFAULT_TIMEZONE = 'Asia/Shanghai'
# LANGUAGES   = {
#     'en':  'English',
#     'zh_CN':  'Chinese-Simplified',
# }
# MAINTAINERS = ['root']
# CONTACT = 'root@open-falcon.com'
# DEBUG = True
# 
# Path: rrd/utils/logger.py



# Path: rrd/store.py
import MySQLdb
from rrd import config
from rrd.utils.logger import logging



portal_db_cfg = {
        "DB_HOST": config.PORTAL_DB_HOST,
        "DB_PORT": config.PORTAL_DB_PORT,
        "DB_USER": config.PORTAL_DB_USER,
        "DB_PASS": config.PORTAL_DB_PASS,
        "DB_NAME": config.PORTAL_DB_NAME,
}

alarm_db_cfg = {
        "DB_HOST": config.ALARM_DB_HOST,
        "DB_PORT": config.ALARM_DB_PORT,
        "DB_USER": config.ALARM_DB_USER,
        "DB_PASS": config.ALARM_DB_PASS,
        "DB_NAME": config.ALARM_DB_NAME,
}

def connect_db(cfg):
    try:
        conn = MySQLdb.connect(
            host=cfg['DB_HOST'],
            port=cfg['DB_PORT'],
            user=cfg['DB_USER'],
            passwd=cfg['DB_PASS'],
            db=cfg['DB_NAME'],
            use_unicode=True,
            charset="utf8")
        return conn
    except Exception, e:

        logging.getLogger().critical('connect db: %s' % e)