Ejemplo n.º 1
0
def main():
    dslam_ok = 0
    dslam_bad = []
    # Создание таблицы(если еще нет)
    SQL.create_data_dsl()

    # Запуск основного кода
    current_time = datetime.datetime.now()
    arguments = [(current_time, host) for host in Settings.hosts]
    with ThreadPoolExecutor(max_workers=Settings.threads) as executor:
        results = executor.map(run, arguments)

    for result in results:
        if result is None:
            continue
        elif result[0] == 1:
            dslam_ok += 1
        else:
            dslam_bad.append(result[1])

    print('Время: {}'.format(current_time.strftime('%Y-%m-%d %H:%M')))
    print('Всего DSLAM: {}'.format(len(Settings.hosts)))
    print('Обработано: {}'.format(dslam_ok))
    print('Необработанные: {}'.format(', '.join(dslam_bad)))
    print('---------\n')

    # Удаление старых записей
    options = {
        'table_name':
        'data_dsl',
        'str1':
        'CAST(datetime AS DATE) < DATE_ADD(CURRENT_DATE(), INTERVAL -{} DAY)'.
        format(Settings.days)
    }
    SQL.delete_table(**options)
def main():

    print('Начало работы: {}'.format(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    count_processed = 0
    count_insert = 0
    count_update = 0
    count_tv = 0
    count_tech_data = 0
    SQL.create_data_sessions()
    SQL.create_abon_onyma()
    options = {
        'table_name': 'abon_dsl',
        'str1': 'account_name, tv, hostname, board, port',
        'str2': 'account_name IS NOT NULL'
    }
    account_list = SQL.get_table_data(**options)
    if len(account_list) == 0:
        print('\n!!! Необходимо сформировать таблицу abon_dsl !!!\n')
        return
    onyma_param_list = get_onyma_params()
    arguments = [(account_list[x::Settings.threads_count], onyma_param_list)
                 for x in range(0, Settings.threads_count)]
    while True:
        try:
            arguments.remove(((), onyma_param_list))
        except:
            break

    with ThreadPoolExecutor(max_workers=Settings.threads_count) as executor:
        result = executor.map(run, arguments)

    for count in result:
        count_processed += count[0]
        count_insert += count[1]
        count_update += count[2]
        count_tv += count[3]
        count_tech_data += count[4]

    print('Обработано: {}'.format(count_processed))
    print('Добавлено: {}'.format(count_insert))
    print('Обновлено данных Онимы: {}'.format(count_update))
    print('Обнаружено ТВ: {}'.format(count_tv))
    print('Обновлено тех. данных: {}'.format(count_tech_data))

    options = {
        'table_name':
        'data_sessions',
        'str1':
        'date < DATE_ADD(CURRENT_DATE(), INTERVAL -{} DAY)'.format(
            Settings.days)
    }
    SQL.delete_table(**options)
    print('Завершение работы: {}'.format(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    print('---------\n')
Ejemplo n.º 3
0
def main():
    print('Время запуска: {}'.format(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M')))
    # Загрузка списка DSLAM
    dslams = load_dslams()
    if len(dslams) == 0:
        print('Не найден dslams.db!')
        return
    dslam_ok = 0
    dslam_repeat = []
    dslam_bad = []
    # Создание таблицы(если еще нет)
    SQL.create_data_dsl()
    # Запуск основного кода
    #current_time = datetime.datetime.now()
    #arguments = [(current_time, host) for host in dslams]
    with ThreadPoolExecutor(max_workers=Settings.threads) as executor:
        results = executor.map(run, dslams)

    for result in results:
        if result is None:
            continue
        elif result[0] == 1:
            dslam_ok += 1
        else:
            dslam_repeat.append(result[1])
    if len(dslam_repeat) > 0:
        print('Пауза 5 мин, и повторная обработка DSLAM:')
        for dslam in dslam_repeat:
            print(dslam[0])
        print()
        # Задержка
        time.sleep(60 * 5)

        # Повторная обработка DSLAM
        with ThreadPoolExecutor(max_workers=Settings.threads) as executor:
            results = executor.map(run, dslam_repeat)

        for result in results:
            if result is None:
                continue
            elif result[0] == 1:
                dslam_ok += 1
            else:
                dslam_bad.append(result[1][0])

    # Распечатка результатов
    print('Время окончания: {}'.format(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M')))
    print('Всего DSLAM: {}'.format(len(dslams)))
    print('Обработано: {}'.format(dslam_ok))
    print('Необработанные: {}'.format(', '.join(dslam_bad)))
    print('---------\n')

    # Удаление старых записей (раз в день в 0 часов)
    hour_now = datetime.datetime.now().hour
    #if (hour_now >= 0) and (hour_now < 2):
    if hour_now == 0:
        options = {
            'table_name':
            'data_dsl',
            'str1':
            'CAST(datetime AS DATE) <= DATE_ADD(CURRENT_DATE(), INTERVAL -{} DAY)'
            .format(Settings.days)
        }
        SQL.delete_table(**options)