def release_resources():
    """Use to change SIM status to 'r' so the card can be used again in sales.
    Logic implemented in helper_functions.py"""
    incidents = get_incidents('VC3_BSS_OPTIPOS_MOBILE', '(129) OPTIPOS Mobile',
                              '(129M) UWOLNIENIE ZASOBOW', 'otsa sprzedaż')

    otsa = otsa_connection()
    sim_regex = re.compile(r'[0-9]{19,20}')
    for inc in incidents:
        sims = []
        for line in inc['notes']:
            sims.extend(sim_regex.findall(line))

        all_resolved, resolution = process_sims(sims, otsa, inc)

        if is_empty(inc):
            resolution = 'Puste zgłoszenie, prawdopodobnie duplikat.'

        if all_resolved and resolution != '':
            resolution = '\r\n'.join(list(set(
                resolution.split('\r\n')))).strip()
            close_incident(inc, resolution)
            print('{} {}: {}'.format(
                str(datetime.now()).split('.')[0], inc['inc'], resolution))
    otsa.close()
def offer_availability():
    """Add an offer to the list of available ones in case of a contract renewal."""
    incidents = []
    incidents += get_incidents('VC3_BSS_RSW', '(357) RSW / nBUK',
                               '(357B) PROBLEMY Z OFERTĄ I TERMINALAMI',
                               'Orange Mobile, B2C, B2B, Love')
    incidents += get_incidents('VC3_BSS_RSW', '(129) OPTIPOS Mobile',
                               '(129C) OFERTA UTRZYMANIOWA', 'otsa utrzymanie')

    rsw = rsw_connection()
    for inc in incidents:
        availability_inc, msisdns, offer_name = extract_data_from_rsw_inc(inc)
        if msisdns and len(msisdns) != 1:
            continue
        elif msisdns:
            msisdn = msisdns[0]
        if msisdns and availability_inc:
            offer_id = get_offer_id_by_name(rsw, offer_name)
            if offer_id:
                make_offer_available(rsw, msisdn, offer_id)
            else:
                make_offer_available(rsw, msisdn)
            resolution = 'Numer {} uprawniony.'.format(msisdn)
            close_incident(inc, resolution)
            print('{} {}: {}'.format(
                str(datetime.now()).split('.')[0], inc['inc'],
                resolution.strip()))
    rsw.close()
def empty_inc():
    """Close tickets with no content."""
    all_inc = []
    all_inc += get_all_incidents('VC3_BSS_RSW')
    all_inc += get_all_incidents('VC3_BSS_OPTIPOS_MOBILE')
    for inc in all_inc:
        if is_empty(inc):
            resolution = 'Puste zgłoszenie, prawdopodobnie duplikat.'
            close_incident(inc, resolution)
            print('{} {}: {}'.format(
                str(datetime.now()).split('.')[0], inc['inc'],
                resolution.strip()))
def close_pending_om_tp():
    incidents = get_pending_incidents(['VC3_BSS_OM_TP'])
    provik = provik_connection()
    for inc in incidents:
        resolution = ''
        tel_order_number = get_tel_order_number(inc)
        if tel_order_number:
            order_data = get_order_data(get_order_info(tel_order_number))
            if 'Stan procesu' in order_data and order_data['Stan procesu'] == 'COMPLETED':
                resolution = 'Zamówienie {} skompletowane.'.format(tel_order_number)
            elif 'Stan procesu' not in order_data:
                latest_order = get_latest_order(provik, tel_order_number)
                if latest_order and latest_order['ord_state'] == 'COMPLETED':
                    resolution = 'Zamówienie {} skompletowane.'.format(tel_order_number)
        if resolution:
            assign_incident(inc)
            close_incident(inc, resolution)
    provik.close()
def close_pending_rsw():
    """Use to close old pending tickets where there was some issue with placing an order.
    If there is a renewal order for the contract and the order date is later than the ticket creation date,
    we close the ticket as resolved."""
    incidents = get_pending_incidents(['VC3_BSS_RSW'])
    msisdn_regex = re.compile(r'\d{3}[ -]?\d{3}[ -]?\d{3}')
    rsw = rsw_connection()
    for inc in incidents:
        resolution = ''
        lines = inc['notes']
        msisdns = None
        last_order = None
        for i, line in enumerate(lines):
            if 'Numer telefonu klienta Orange / MSISDN' in line and i < len(
                    lines) - 1:
                msisdns = msisdn_regex.findall(lines[i + 1])
        if msisdns:
            msisdns = [
                msisdn.translate(''.maketrans({
                    '-': '',
                    ' ': ''
                })) for msisdn in msisdns
            ]
        if msisdns and len(msisdns) != 1:
            continue
        elif msisdns:
            msisdn = msisdns[0]
            last_order = get_latest_order(rsw, msisdn)
        if last_order and last_order['data_zamowienia'] > inc[
                'reported_date'] and last_order['ilosc_prob'] == 0:
            if last_order['status'] == 16 and last_order['status_om'] == 4:
                resolution = 'Na podanym numerze {} jest już zrealizowane zamówienie {} z {}.'. \
                    format(msisdn, last_order['id_zamowienia'], last_order['data_zamowienia'])
            elif last_order['status'] in (2, 3):
                resolution = 'Na podanym numerze {} jest już zamówienie {} w trakcie realizacji w ML.'. \
                    format(msisdn, last_order['id_zamowienia'])
        if resolution:
            assign_incident(inc)
            close_incident(inc, resolution)
            print('{} {}: {}'.format(
                str(datetime.now()).split('.')[0], inc['inc'],
                resolution.strip()))

    rsw.close()
def tester_accounts():
    incidents = get_incidents('VC3_BSS_OPTIPOS_MOBILE', '(129) OPTIPOS Mobile',
                              '(129S) TESTER - POWIĄZANIE IFS',
                              'otsa sprzedaż')
    optipot3 = optipos_sti_connection()
    for inc in incidents:
        login = None
        lines = inc['notes']
        for i, line in enumerate(lines):
            if 'Podaj login testera' in line:
                login = lines[i + 1].strip()
        if login:
            row_count = link_login_with_ifs(optipot3, login)
            if row_count == 1:
                resolution = 'Powiązano konto {} z IFS.'.format(login)
                close_incident(inc, resolution)
                print('{} {}: {}'.format(
                    str(datetime.now()).split('.')[0], inc['inc'],
                    resolution.strip()))
    optipot3.close()
def unlock_accounts():
    """Reset the password and unlock the account, if the login can be found in the ticket."""
    incidents = []
    incidents += get_incidents('VC3_BSS_OPTIPOS_MOBILE',
                               '(129) OPTIPOS Mobile',
                               '(129O) OTSA/OPTIPOS - odblokowanie konta',
                               'ota login odblokowanie')
    incidents += get_incidents('VC3_BSS_OPTIPOS_MOBILE',
                               '(129) OPTIPOS Mobile',
                               '(129RF) DEALER SUPPORT - AKTYWACJA KONTA',
                               'otsa login dealersupport DS.')

    incidents += get_incidents('VC3_BSS_OPTIPOS_MOBILE',
                               '(129) OPTIPOS Mobile',
                               '(129I) PROBLEM Z LOGOWANIEM', 'login OTSA')

    sd_tiers = [
        '(129RI) OKI i SOHO - AKTYWACJA KONTA',
        '(129RA) KKB,ADT - AKTYWACJA KONTA',
        '(129RK) ZŁD Aktywacja/Modyfikacja konta',
        '(129RH) OKB i TAM - AKTYWACJA KONTA'
    ]
    for tier2 in sd_tiers:
        incidents += get_incidents('VC3_BSS_OPTIPOS_MOBILE',
                                   '(129) OPTIPOS Mobile', tier2, 'otsa login')

    otsa = otsa_connection()

    for inc in incidents:
        login = find_login(inc)
        if login:
            rows_updated = unlock_account(otsa, login)
            if rows_updated == 1:
                resolution = 'Konto o loginie {} jest aktywne. Nowe hasło to: centertel.'.format(
                    login)
                close_incident(inc, resolution)
                print('{} {}: {}'.format(
                    str(datetime.now()).split('.')[0], inc['inc'],
                    resolution.strip()))

    otsa.close()
def process_transactions():
    """Process transactions on prod otsa database.
    Do so using rules that no one understands anymore (defined in otsa_processing.py)."""
    incidents = get_incidents('VC3_BSS_OPTIPOS_MOBILE', '(129) OPTIPOS Mobile',
                              '(129B) AKTYWACJA KLIENTA', 'login OTSA')
    incidents += get_incidents('VC3_BSS_OPTIPOS_MOBILE',
                               '(129) OPTIPOS Mobile',
                               '(129D) MIGRACJA KLIENTA', 'otsa sprzedaż')
    incidents += get_incidents('VC3_BSS_OPTIPOS_MOBILE',
                               '(129) OPTIPOS Mobile', '(129E) SPRZEDAZ USLUG',
                               'otsa sprzedaż')

    msisdn_regex = re.compile(r'\d{3}[ -]?\d{3}[ -]?\d{3}')
    trans_num_regex = re.compile('[A-Z0-9]{5,}?/?[0-9]{4}/[0-9]+')
    for inc in incidents:
        resolution = ''
        lines = inc['notes']
        all_resolved = True
        for i, line in enumerate(lines):
            if 'Proszę podać numer MSISDN' in line or 'Numer telefonu klienta Orange / MSISDN' in line:
                msisdns = msisdn_regex.findall(lines[i + 1])
                msisdns += msisdn_regex.findall(lines[i + 2])
                msisdns = [
                    msisdn.translate(''.maketrans({
                        '-': '',
                        ' ': ''
                    })) for msisdn in msisdns
                ]
                trans_nums = trans_num_regex.findall(lines[i + 1])
                resolution, all_resolved = process_msisdns(
                    msisdns, trans_nums, inc)
        if is_empty(inc):
            resolution = 'Puste zgłoszenie, prawdopodobnie duplikat.'
        if resolution != '' and all_resolved:
            resolution = '\r\n'.join(list(set(
                resolution.split('\r\n')))).strip()
            close_incident(inc, resolution)
            print('{} {}: {}'.format(
                str(datetime.now()).split('.')[0], inc['inc'],
                resolution.strip()))
Exemplo n.º 9
0
def process_ml_wzmuks(tier2, ml_connection, env_name):
    """Process access requests for ML system. Depending on what's in the request it can:
    create a new account, delete an old one, or change permissions for an existing account."""
    incidents = get_incidents(
        'VC3_BSS_ML', '(185) E-WZMUK-konto w SI Nowe/Modyfikacja/Likwidacja',
        tier2, '40h')
    try:
        ml_con = ml_connection()
    except cx_Oracle.DatabaseError:
        return

    for inc in incidents:
        work_info = get_work_info(inc)
        filename, contents = work_info[0]['attachment']

        xls_file = open(filename, 'wb')
        xls_file.write(contents)
        xls_file.close()
        users = get_users_data_from_xls(filename)
        os.remove(filename)

        resolution = ''
        for user in users:
            if user['typ_wniosku'] == 'Modyfikacja uprawnień':
                resolution += ml_modify_access(ml_con, user, env_name, inc)
            elif user['typ_wniosku'] == 'Nowe konto':
                resolution += ml_add_access(ml_con, user, env_name, inc)
            elif user['typ_wniosku'] == 'Likwidacja konta':
                resolution += ml_remove_access(ml_con, user, env_name, inc)

        if resolution:
            close_incident(inc, resolution.strip())
            print('{} {}: {}'.format(
                str(datetime.now()).split('.')[0], inc['inc'],
                resolution.strip()))

    ml_con.close()
def om_tp_wzmuk():
    incidents = get_incidents(
        'VC3_BSS_OM_TP',
        '(185) E-WZMUK-konto w SI Nowe/Modyfikacja/Likwidacja',
        'O30 OMTP',
        '40h'
    )
    for inc in incidents:
        work_info = get_work_info(inc)
        filename, contents = work_info[0]['attachment']

        xls_file = open(filename, 'wb')
        xls_file.write(contents)
        xls_file.close()
        users = get_users_data_from_xls(filename)
        os.remove(filename)

        for user in users:
            if not user['login_ad']:
                continue

            if user['typ_wniosku'] == 'Nowe konto':
                if user['profil'] == 'konsola zamówień OM (odczyt)':
                    password = new_ro_user(user['login_ad'])
                    close_incident(inc, f'Konto założone, hasło to: {password}')
                else:
                    pass
            elif user['typ_wniosku'] == 'Modyfikacja uprawnień':
                if user['profil'] == 'konsola zamówień OM (odczyt)':
                    password = new_ro_user(user['login_ad'])
                    close_incident(inc, f'Zrealizowano, nowe hasło to: {password}')
                else:
                    pass
            elif user['typ_wniosku'] == 'Likwidacja konta':
                disable_user(user['login_ad'])
                close_incident(inc, 'Konto wyłączone.')
def handle_brm_errors():
    incidents = get_all_incidents('VC3_BSS_OM_TP')
    provik = provik_connection()

    for inc in incidents:
        if to_cancel(inc):
            continue

        work_info = get_work_info(inc)
        tel_order_number = get_tel_order_number(inc)
        order_info = get_order_info(tel_order_number)
        order_data = get_order_data(order_info)
        if 'OM zamowienie (ORD_ID)' in order_data:
            ord_id = order_data['OM zamowienie (ORD_ID)']

        if 'BRM3' in inc['summary']:
            if is_gbill_out_for_order(provik, ord_id):
                update_summary(inc, 'CRM')
                add_work_info(inc, 'OM_TP', 'Poprawione.')
                reassign_incident(inc, 'VC3_BSS_CRM_FIX')

        elif 'BRM2' in inc['summary']:
            if is_gbill_out_for_order(provik, ord_id):
                resolution = 'Zamówienie {} przekazane do realizacji.'.format(tel_order_number)
                close_incident(inc, resolution)

        elif 'BRM' in inc['summary'] or 'PK' in inc['summary']:
            promotion_regex = re.compile(r'pro[0-9]{14}')
            promotion_ids = []
            return_flag = get_return_flag(work_info)

            for entry in work_info[::-1]:
                notes = '\r\n'.join(entry['notes']).lower()
                summary = entry['summary'].lower()
                promotion_ids += promotion_regex.findall(notes)

                if 'crm' in summary and \
                        ('bez kary' in notes or 'bez naliczania kary' in notes or 'bez naliczenia kary' in notes):
                    if ord_id:
                        fine_flag_value_replace(ord_id, inc)
                        resubmit_successful = resubmit_goal(tel_order_number)
                        if resubmit_successful:
                            update_summary(inc, 'BRM3') if return_flag else update_summary(inc, 'BRM2')

                elif 'crm' in summary and ('promo' in notes or 'pro000' in notes) and \
                        ('bez' in notes or 'usunięcie' in notes or 'do usunięcia' in notes):
                    promotion_ids_from_crm = promotion_regex.findall(notes)
                    promotion_id = None
                    # promotion_ids = list(set(promotion_ids))
                    # if len(promotion_ids) == 1:
                    #     promotion_id = promotion_ids[0].upper()
                    if len(promotion_ids_from_crm) == 1:
                        promotion_id = promotion_ids_from_crm[0].upper()
                    if promotion_id:
                        update_cf_service(ord_id, promotion_id, inc)
                        resubmit_successful = resubmit_goal(tel_order_number)
                        if resubmit_successful:
                            update_summary(inc, 'BRM3') if return_flag else update_summary(inc, 'BRM2')

                elif 'crm' in summary and \
                        ('bez ins000' in notes or 'usunięcie ins000' in notes or 'do usunięcia ins000' in notes):
                    ins_regex = re.compile(r'ins[0-9]{14}')
                    ins_ids = ins_regex.findall(notes)
                    ins_id = None
                    if len(ins_ids) == 1:
                        ins_id = ins_ids[0].upper()
                    if ins_id:
                        delete_cf_service(ord_id, ins_id, inc)
                        resubmit_successful = resubmit_goal(tel_order_number)
                        if resubmit_successful:
                            update_summary(inc, 'BRM3') if return_flag else update_summary(inc, 'BRM2')

        elif tel_order_number and (is_work_info_empty(work_info) or has_exactly_one_entry(work_info)):
            if to_cancel(inc):
                continue
            process_errors = get_process_errors(order_info)
            if has_brm_process_error(process_errors) or has_brm_error(work_info):
                logs = get_logs_for_order(tel_order_number)
                logs_string = '\r\n'.join(logs)
                if len(logs) == 2:
                    update_summary(inc, 'BRM')
                    add_work_info(inc, 'OM_TP', logs_string)
                    reassign_incident(inc, 'APLIKACJE_OBRM_DOSTAWCA')
                    sleep(30)
                elif len(logs) == 1 and not is_gbill_out_for_order(provik, ord_id):
                    resubmit_successful = resubmit_goal(tel_order_number)
                    if resubmit_successful:
                        print('{} Zamówienie {} ponowione w OM TP'.format(inc['inc'], tel_order_number),
                              file=sys.stderr)
                else:
                    process_errors = get_process_errors(get_order_info(tel_order_number))
                    error_id = ''
                    if process_errors and process_errors[0]:
                        error_id = process_errors[0][0]
                    print('{} {} {} {}'.format(inc['inc'], error_id, tel_order_number, logs_string), file=sys.stderr)

    provik.close()