Beispiel #1
0
    def send_to_admins(subject, message):
        if settings.DEBUG:
            return

        mail_admins_async.delay(
            subject=subject,
            message=message,
        )
Beispiel #2
0
    def send_to_admins(subject, message):
        if settings.DEBUG:
            return

        mail_admins_async.delay(
            subject=subject,
            message=message,
        )
Beispiel #3
0
    def send_to_admins(subject, message):
        from corehq.apps.hqwebapp.tasks import mail_admins_async

        if settings.DEBUG:
            return

        mail_admins_async.delay(
            subject=subject,
            message=message,
        )
Beispiel #4
0
    def send_to_admins(subject, message):
        from corehq.apps.hqwebapp.tasks import mail_admins_async

        if settings.DEBUG:
            return

        mail_admins_async.delay(
            subject=subject,
            message=message,
        )
Beispiel #5
0
def check_for_sql_cases_without_existing_domain():
    missing_domains_with_cases = set()
    for domain in set(
            _get_all_domains_that_have_ever_had_subscriptions()) - set(
                Domain.get_all_names()):
        if CaseAccessorSQL.get_case_ids_in_domain(domain):
            missing_domains_with_cases |= {domain}

    if missing_domains_with_cases:
        mail_admins_async.delay(
            'There exist SQL cases belonging to a missing domain',
            six.text_type(missing_domains_with_cases))
    elif _is_monday():
        mail_admins_async.delay('All SQL cases belong to valid domains', '')
Beispiel #6
0
def check_for_sql_cases_without_existing_domain():
    missing_domains_with_cases = set()
    for domain in set(_get_all_domains_that_have_ever_had_subscriptions()) - set(Domain.get_all_names()):
        if CaseAccessorSQL.get_case_ids_in_domain(domain):
            missing_domains_with_cases |= {domain}

    if missing_domains_with_cases:
        mail_admins_async.delay(
            'There exist SQL cases belonging to a missing domain',
            six.text_type(missing_domains_with_cases)
        )
    elif _is_monday():
        mail_admins_async.delay(
            'All SQL cases belong to valid domains', ''
        )
Beispiel #7
0
def fix_xforms_with_missing_xmlns():
    log_file_name = 'undefined_xmlns.{}-timestamp.log'.format(int(time()))
    log_file_path = os.path.join(UNDEFINED_XMLNS_LOG_DIR, log_file_name)

    call_command('fix_xforms_with_undefined_xmlns', log_file_path, noinput=True)

    with open(log_file_path, "r") as f:
        stats = get_summary_stats_from_stream(f)

    mail_admins_async.delay(
        'Summary of fix_xforms_with_undefined_xmlns',
        json.dumps(stats, sort_keys=True, indent=4, default=json_handler)
    )

    return stats, log_file_path
Beispiel #8
0
def fix_xforms_with_missing_xmlns():
    log_file_name = 'undefined_xmlns.{}-timestamp.log'.format(int(time()))
    log_file_path = os.path.join(UNDEFINED_XMLNS_LOG_DIR, log_file_name)

    call_command('fix_xforms_with_undefined_xmlns', log_file_path, noinput=True)

    with open(log_file_path, "r") as f:
        stats = get_summary_stats_from_stream(f)

    mail_admins_async.delay(
        'Summary of fix_xforms_with_undefined_xmlns',
        json.dumps(stats, sort_keys=True, indent=4, default=json_handler)
    )

    return stats, log_file_path
Beispiel #9
0
def check_for_elasticsearch_data_without_existing_domain():
    issue_found = False
    for domain_name in _get_missing_domains():
        for hqESQuery in [
                AppES, CaseES, CaseSearchES, FormES, GroupES, UserES
        ]:
            query = hqESQuery().domain(domain_name)
            count = query.count()
            if query.count() != 0:
                issue_found = True
                mail_admins_async.delay(
                    'ES index "%s" contains %s items belonging to missing domain "%s"'
                    % (query.index, count, domain_name), '')
    if not issue_found and _is_monday():
        mail_admins_async.delay('All data in ES belongs to valid domains', '')
Beispiel #10
0
def check_for_sql_forms_without_existing_domain():
    missing_domains_with_forms = set()
    for domain in set(
            _get_all_domains_that_have_ever_had_subscriptions()) - set(
                Domain.get_all_names()):
        for doc_type in doc_type_to_state:
            if FormAccessorSQL.get_form_ids_in_domain_by_type(
                    domain, doc_type):
                missing_domains_with_forms |= {domain}

    if missing_domains_with_forms:
        mail_admins_async.delay(
            'There exist SQL forms belonging to a missing domain',
            six.text_type(missing_domains_with_forms))
    elif _is_monday():
        mail_admins_async.delay('All SQL forms belong to valid domains', '')
Beispiel #11
0
def check_for_sql_forms_without_existing_domain():
    missing_domains_with_forms = set()
    for domain in set(_get_all_domains_that_have_ever_had_subscriptions()) - set(Domain.get_all_names()):
        for doc_type in doc_type_to_state:
            if FormAccessorSQL.get_form_ids_in_domain_by_type(domain, doc_type):
                missing_domains_with_forms |= {domain}

    if missing_domains_with_forms:
        mail_admins_async.delay(
            'There exist SQL forms belonging to a missing domain',
            six.text_type(missing_domains_with_forms)
        )
    elif _is_monday():
        mail_admins_async.delay(
            'All SQL forms belong to valid domains', ''
        )
Beispiel #12
0
def check_for_sql_forms_without_existing_domain():
    missing_domains_with_forms = set()
    for domain in set(
            _get_all_domains_that_have_ever_had_subscriptions()) - set(
                Domain.get_all_names()):
        accessor = FormReindexAccessor(domain=domain, include_deleted=True)
        for db_name in accessor.sql_db_aliases:
            if _has_docs(accessor, db_name):
                missing_domains_with_forms |= {domain}
                break

    if missing_domains_with_forms:
        mail_admins_async.delay(
            'There exist SQL forms belonging to a missing domain',
            str(missing_domains_with_forms))
    elif _is_monday():
        mail_admins_async.delay('All SQL forms belong to valid domains', '')
Beispiel #13
0
def check_for_sql_forms_without_existing_domain():
    form_count_by_missing_domain = {}
    for domain in _get_missing_domains():
        form_count = 0
        for db_name in get_db_aliases_for_partitioned_query():
            form_count += XFormInstanceSQL.objects.using(db_name).filter(
                domain=domain).count()
        if form_count:
            form_count_by_missing_domain[domain] = form_count

    if form_count_by_missing_domain:
        mail_admins_async.delay(
            'There exist SQL forms belonging to a missing domain',
            f'{form_count_by_missing_domain}\nConsider hard_delete_forms_and_cases_in_domain'
        )
    elif _is_monday():
        mail_admins_async.delay('All SQL forms belong to valid domains', '')
Beispiel #14
0
def check_for_elasticsearch_data_without_existing_domain():
    issue_found = False
    deleted_domain_names = set(
        _get_all_domains_that_have_ever_had_subscriptions()) - set(
            Domain.get_all_names())
    for domain_name in deleted_domain_names:
        for hqESQuery in [
                AppES, CaseES, CaseSearchES, FormES, GroupES, LedgerES, UserES
        ]:
            query = hqESQuery().domain(domain_name)
            count = query.count()
            if query.count() != 0:
                issue_found = True
                mail_admins_async.delay(
                    'ES index "%s" contains %s items belonging to missing domain "%s"'
                    % (query.index, count, domain_name), '')
    if not issue_found and _is_monday():
        mail_admins_async.delay('All data in ES belongs to valid domains', '')
Beispiel #15
0
def check_for_elasticsearch_data_without_existing_domain():
    issue_found = False
    deleted_domain_names = set(_get_all_domains_that_have_ever_had_subscriptions()) - set(Domain.get_all_names())
    for domain_name in deleted_domain_names:
        for hqESQuery in [AppES, CaseES, CaseSearchES, FormES, GroupES, LedgerES, UserES]:
            query = hqESQuery().domain(domain_name)
            count = query.count()
            if query.count() != 0:
                issue_found = True
                mail_admins_async.delay(
                    'ES index "%s" contains %s items belonging to missing domain "%s"' % (
                        query.index, count, domain_name
                    ), ''
                )
    if not issue_found and _is_monday():
        mail_admins_async.delay(
            'All data in ES belongs to valid domains', ''
        )
Beispiel #16
0
def check_for_ucr_tables_without_existing_domain():
    all_domain_names = Domain.get_all_names()

    connection_name = ConnectionManager().get_django_db_alias(UCR_ENGINE_ID)
    table_names = connections[connection_name].introspection.table_names()
    ucr_table_names = [name for name in table_names if name.startswith('config_report')]

    missing_domains_to_tables = defaultdict(list)

    for ucr_table_name in ucr_table_names:
        table_domain = ucr_table_name.split('_')[2]
        if table_domain not in all_domain_names:
            missing_domains_to_tables[table_domain].append(ucr_table_name)

    if missing_domains_to_tables:
        for missing_domain in missing_domains_to_tables:
            mail_admins_async.delay(
                'Missing domain "%s" has remaining UCR tables' % missing_domain,
                six.text_type(missing_domains_to_tables[missing_domain])
            )
    elif _is_monday():
        mail_admins_async.delay('All UCR tables belong to valid domains', '')
Beispiel #17
0
def check_for_ucr_tables_without_existing_domain():
    all_domain_names = Domain.get_all_names()

    connection_name = ConnectionManager().get_django_db_alias(UCR_ENGINE_ID)
    table_names = connections[connection_name].introspection.table_names()
    ucr_table_names = [name for name in table_names if name.startswith('config_report')]

    missing_domains_to_tables = defaultdict(list)

    for ucr_table_name in ucr_table_names:
        table_domain = ucr_table_name.split('_')[2]
        if table_domain not in all_domain_names:
            missing_domains_to_tables[table_domain].append(ucr_table_name)

    if missing_domains_to_tables:
        for missing_domain in missing_domains_to_tables:
            mail_admins_async.delay(
                'Missing domain "%s" has remaining UCR tables' % missing_domain,
                six.text_type(missing_domains_to_tables[missing_domain])
            )
    elif _is_monday():
        mail_admins_async.delay('All UCR tables belong to valid domains', '')
Beispiel #18
0
 def send_to_admins(subject, message):
     mail_admins_async.delay(
         subject=subject,
         message=message,
     )
Beispiel #19
0
 def send_to_admins(subject, message):
     mail_admins_async.delay(
         subject=subject,
         message=message,
     )