Ejemplo n.º 1
0
def farm_exists(farm_id):
    connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
    cursor = connection.cursor()
    try:
        cursor.execute("SELECT id FROM farms WHERE id=%s" % farm_id)
        return bool(cursor.fetchall())
    finally:
        cursor.close()
        connection.close()
Ejemplo n.º 2
0
 def _get_events_count(self):
     connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
     cursor = connection.cursor()
     try:
         cursor.execute("""SELECT count(*) FROM events WHERE events.ishandled=0""")
         return cursor.fetchone()['count(*)']
     finally:
         cursor.close()
         connection.close()
Ejemplo n.º 3
0
def get_farms():
    connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
    cursor = connection.cursor()
    try:
        cursor.execute("SELECT id FROM farms")
        return cursor.fetchall()
    finally:
        cursor.close()
        connection.close()
Ejemplo n.º 4
0
 def _get_events_count(self):
     connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
     cursor = connection.cursor()
     try:
         cursor.execute(
             """SELECT count(*) FROM events WHERE events.ishandled=0""")
         return cursor.fetchone()['count(*)']
     finally:
         cursor.close()
         connection.close()
Ejemplo n.º 5
0
def clean():
    connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
    cursor = connection.cursor()
    try:
        cursor.execute("""SELECT `id` FROM `farms`""")
        farms_id = cursor.fetchall()
    finally:
        cursor.close()
        connection.close()
    for dir_ in os.listdir(CONFIG['rrd_db_dir']):
        for farm_id in os.listdir('%s/%s' % (CONFIG['rrd_db_dir'], dir_)):
            if farm_id not in farms_id:
                LOG.debug('Delete farm %s' % farm_id)
                if not CONFIG['test']:
                    dir_to_delete = '%s/%s/%s' % (CONFIG['rrd_db_dir'], dir_, farm_id),
                    shutil.rmtree(dir_to_delete, ignore_errors=True)
Ejemplo n.º 6
0
def clean():
    connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
    cursor = connection.cursor()
    try:
        cursor.execute("""SELECT `id` FROM `farms`""")
        farms_id = cursor.fetchall()
    finally:
        cursor.close()
        connection.close()
    for dir_ in os.listdir(CONFIG['rrd_db_dir']):
        for farm_id in os.listdir('%s/%s' % (CONFIG['rrd_db_dir'], dir_)):
            if farm_id not in farms_id:
                LOG.debug('Delete farm %s' % farm_id)
                if not CONFIG['test']:
                    dir_to_delete = '%s/%s/%s' % (CONFIG['rrd_db_dir'], dir_,
                                                  farm_id),
                    shutil.rmtree(dir_to_delete, ignore_errors=True)
Ejemplo n.º 7
0
 def _get_messages_count(self):
     connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
     cursor = connection.cursor()
     try:
         query = """SELECT count(*) """ +\
                 """FROM messages """ +\
                 """WHERE messages.type='out' AND """ +\
                 """messages.status=0 AND """ +\
                 """messages.message_version=2 AND """ +\
                 """messages.message_format='xml' AND """ +\
                 """UNIX_TIMESTAMP(messages.dtlasthandleattempt)+ """ +\
                 """messages.handle_attempts*%s<UNIX_TIMESTAMP()"""
         query = query % CONFIG['cratio']
         cursor.execute(query)
         return cursor.fetchone()['count(*)']
     finally:
         cursor.close()
         connection.close()
Ejemplo n.º 8
0
 def _get_messages_count(self):
     connection = dbmanager.make_connection(CONFIG['connections']['mysql'])
     cursor = connection.cursor()
     try:
         query = """SELECT count(*) """ +\
                 """FROM messages """ +\
                 """WHERE messages.type='out' AND """ +\
                 """messages.status=0 AND """ +\
                 """messages.message_version=2 AND """ +\
                 """messages.message_format='xml' AND """ +\
                 """UNIX_TIMESTAMP(messages.dtlasthandleattempt)+ """ +\
                 """messages.handle_attempts*%s<UNIX_TIMESTAMP()"""
         query = query % CONFIG['cratio']
         cursor.execute(query)
         return cursor.fetchone()['count(*)']
     finally:
         cursor.close()
         connection.close()