Exemple #1
0
    def _run(cls, config, *args, **kwargs):
        all_wa_containers = docker_utils.get_wa_containers()
        stopped_wa_container_ids = [
            wa_container.short_id
            for wa_container in all_wa_containers
            if not wa_container.is_running()
        ]

        remediation_msg = (
            "List all containers on the current host with `docker ps -a` and "
            "run `docker start #container_id` to start a container. "
            "If a container stops due to errors, "
            "refer to messages from other checks to diagnose or contact support "
            "https://developers.facebook.com/docs/whatsapp/contact-support"
        )

        if len(all_wa_containers) == len(stopped_wa_container_ids):
            return results.Problem(
                cls,
                "No WA container is running",
                "All WA containers are stopped.",
                remediation_msg,
            )

        if len(stopped_wa_container_ids) > 0:
            return results.Warning(
                cls,
                "Not all WA containers are running.",
                f"WA containers with id {', '.join(stopped_wa_container_ids)}"
                " not running.",
                f"If this is expected, please ignore. {remediation_msg}",
            )

        return results.OK(cls)
Exemple #2
0
def _result_webhook_slow_response(cls, response_time):
    return results.Warning(
        cls,
        "Slow webhook response",
        "Webhook responded in {} seconds".format(response_time),
        "Please ensure you are returning 200 OK "
        "from your webhook handler as soon as possible",
    )
Exemple #3
0
def _result_webhook_not_set(cls):
    return results.Warning(
        cls,
        "Unable to check webhook",
        "Webhook has not been set",
        "Set up webhook via App Settings "
        "https://developers.facebook.com/docs/whatsapp/api/settings/app",
        "",
    )
    def _run(cls, config, *args, **kwargs):
        wacore_containers = docker_utils.get_running_wacore_containers()

        short_error_message = 'Network connectivity check fails'

        if not wacore_containers:
            return results.Problem(
                cls, short_error_message,
                'There is no wacore container running',
                'Please check results from other actions to diagnose')

        container = wacore_containers[0]

        hosts_in_warning_state = []
        hosts_in_error_state = []

        for host in HOSTS_USING_DEFAULT_PORT:
            hostname = host[0]
            if is_server_in_warning_state(container, hostname):
                hosts_in_warning_state.append(host)
            elif is_server_in_error_state(container, hostname):
                hosts_in_error_state.append(host)

        for host in HOSTS_USING_HTTPS_PORT:
            hostname = host[0]
            if is_server_in_error_state(container, hostname):
                hosts_in_error_state.append(host)

        TROUBLESHOOTING_URL = \
            'https://developers.facebook.com/docs/whatsapp/network-debugging'

        if hosts_in_error_state:
            error_message = format_error_message(hosts_in_error_state) + \
                format_warning_message(hosts_in_warning_state)
            return results.Problem(
                cls, 'Network connectivity check fails', error_message,
                'Please refer to {} for network requirements details.'.format(
                    TROUBLESHOOTING_URL))

        if hosts_in_warning_state:
            warning_message = format_warning_message(hosts_in_warning_state)
            return results.Warning(
                cls, 'Network connectivity check fails', warning_message,
                'Please refer to {} for network requirements details.'.format(
                    TROUBLESHOOTING_URL))

        return results.OK(cls)
    def _run(cls, config, *args, **kwargs):

        stopped_containers = []
        stopped_sql_containers = []

        def get_all_running_wa_containers():
            containers = docker_utils.get_wa_containers()
            versions_to_wa_containers_dict = defaultdict(
                lambda: defaultdict(list))
            for wa_container in containers:
                container = wa_container.container
                container_type = wa_container.container_type
                if (docker_utils.is_container_running(container)):
                    if (docker_utils.WA_WEBAPP_CONTAINER_TAG == container_type
                            or docker_utils.WA_COREAPP_CONTAINER_TAG
                            == container_type):
                        version = docker_utils.get_wa_version_from_container(
                            container)
                        versions_to_wa_containers_dict[
                            version[1]][container_type].append(container)
                else:
                    if docker_utils.MYSQL_CONTAINER_TAG == container_type:
                        stopped_sql_containers.append(container)
                    else:
                        stopped_containers.append(container)
            return versions_to_wa_containers_dict

        errors = []
        warnings = []

        running_wa_containers = get_all_running_wa_containers()
        if not running_wa_containers:
            errors.append("Either core container or web container is missing")
        no_of_working_versions = 0
        for key, value in running_wa_containers.items():
            if (len(value) != 2):
                errors.append(
                    "Either web container or core container missing for version {}"
                    .format(key))
            elif (len(value[docker_utils.WA_COREAPP_CONTAINER_TAG]) != len(
                    value[docker_utils.WA_WEBAPP_CONTAINER_TAG])):
                errors.append(
                    'The number of running coreapp containers, for version {}, is not'
                    'same as number of running web containers'.format(key))
            else:
                no_of_working_versions = no_of_working_versions + 1
                if (no_of_working_versions > 1):
                    warnings.append(
                        'More than one set of Web app and Core app are running. '
                        'It may be fine, but worth noticing.')

        if errors or stopped_sql_containers:
            err_str = 'Message: {}\n'
            container_details = "Container - ID: {}, Name: {}, Status: {}"
            stopped_containers.extend(stopped_sql_containers)
            return results.Problem(
                cls,
                'Some of your WhatsApp containers are missing or not running.',
                '{}\n{}'.format(
                    '\n'.join([err_str.format(e) for e in errors]), '\n'.join([
                        container_details.format(c.short_id, c.name, c.status)
                        for c in stopped_containers
                    ])),
                'Use the following commands to learn more:\n'
                '\tdocker ps -a\n'
                '\tdocker inspect <CONTAINER_ID>',
            )

        if warnings:
            warning_str = 'Message: {}\n'
            return results.Warning(
                cls,
                'More than one set(coreapp,webapp) of containers are running',
                '\n'.join([warning_str.format(w) for w in warnings]),
                'Use the following commands to learn more:\n'
                '\tdocker ps -a\n')

        return results.OK(cls)
    def _run(cls, config, *args, **kwargs):
        errors = []
        warnings = []
        expiration_date_map = docker_utils.get_expiration_map()

        def get_all_running_wa_containers():
            wa_containers = docker_utils.get_wa_containers()
            versions_to_wa_containers_dict = defaultdict(
                lambda: defaultdict(list))
            for wa_container in wa_containers:
                container = wa_container.container
                container_type = wa_container.get_container_type()
                if docker_utils.is_container_running(container):
                    if wa_container.is_webapp() or wa_container.is_coreapp():
                        version = docker_utils.get_wa_version_from_container(
                            container)
                        versions_to_wa_containers_dict[version][
                            container_type].append(container)
            return versions_to_wa_containers_dict

        def is_valid_version(version, wa_containers_dict):
            containers = []
            for container in wa_containers_dict.values():
                containers.extend(container)
            valid_version = True
            cur = datetime.utcnow().strftime(docker_utils.DATE_FORMAT)
            try:
                days_delta = days_between(cur, expiration_date_map[version[0]])
                if days_delta < 0:
                    valid_version = False
                    error_str = (
                        "{}: Current version of your container {} has expired on {} UTC"
                    )
                    for container in containers:
                        errors.append(
                            error_str.format(
                                container.name,
                                version[1],
                                expiration_date_map[version[0]],
                            ))
                elif days_delta < 7:
                    warnings_str = "{}: Current version of your software ({}) "
                    "is expiring on {} UTC, please consider upgrading soon"
                    for container in containers:
                        warnings.append(
                            warnings_str.format(
                                container.name,
                                version[1],
                                expiration_date_map[version[0]],
                            ))
            except KeyError:
                valid_version = False
                error_str = (
                    "{}: Current version of your container ({}) is deprecated or "
                )
                "wadebug tool is not up-to-date"
                for container in containers:
                    errors.append(error_str.format(container.name, version[1]))
            return valid_version

        running_wa_containers = get_all_running_wa_containers()

        valid_versions = []
        for key, value in running_wa_containers.items():
            if len(value[docker_utils.WA_COREAPP_CONTAINER_TAG]) != len(
                    value[docker_utils.WA_WEBAPP_CONTAINER_TAG]):
                errors.append(
                    "Number of coreapp containers for version {} is not same as "
                    "number of webapp containers".format(key))
            elif is_valid_version(key, value):
                valid_versions.append(key[1])

        if len(valid_versions) > 1:
            warnings.append(
                "More than one set of valid software versions({}) are running. "
                "It may be fine, but worth noticing.".format(valid_versions))

        if errors:
            error_str = "Error Message: {}\n"
            warning_str = "Warning Message: {}\n"

            return results.Problem(
                cls,
                "Some of your WhatsApp container versions are expired "
                "or there is mismatch between versions"
                " of coreapp and webapp",
                "{}\n{}".format(
                    "\n".join([error_str.format(e) for e in errors]),
                    "\n".join([warning_str.format(w) for w in warnings]),
                ),
                "Please find the following link to find latest version: "
                "https://developers.facebook.com/docs/whatsapp/changelog\n"
                "and please find upgrade instructions here:"
                "https://developers.facebook.com/docs/whatsapp/guides/installation\n",
            )

        if warnings:
            warning_str = "Warning Message: {}\n"
            return results.Warning(
                cls,
                "Some of your WhatsApp conatiners are nearing expiration or "
                "more than one valid version is running",
                "\n".join([warning_str.format(w) for w in warnings]),
                "Please find the following link to find latest version: "
                "https://developers.facebook.com/docs/whatsapp/changelog\n"
                "and please find upgrade instructions here:"
                "https://developers.facebook.com/docs/whatsapp/guides/installation\n",
            )

        return results.OK(cls)
Exemple #7
0
    def _run(cls, config, *args, **kwargs):
        errors = []
        warnings = []
        expiration_date_map = docker_utils.get_expiration_map()

        def get_all_running_wa_containers():
            wa_containers = docker_utils.get_wa_containers()
            versions_to_wa_containers_dict = defaultdict(
                lambda: defaultdict(list))
            for wa_container in wa_containers:
                container = wa_container.container
                container_type = wa_container.container_type
                if (docker_utils.is_container_running(container)):
                    if (docker_utils.WA_WEBAPP_CONTAINER_TAG == container_type
                            or docker_utils.WA_COREAPP_CONTAINER_TAG
                            == container_type):
                        version = docker_utils.get_wa_version_from_container(
                            container)
                        versions_to_wa_containers_dict[version][
                            container_type].append(container)
            return versions_to_wa_containers_dict

        def is_valid_version(version, wa_containers_dict):
            containers = []
            for container in wa_containers_dict.values():
                containers.extend(container)
            valid_version = True
            cur = datetime.utcnow().strftime(docker_utils.DATE_FORMAT)
            try:
                days_delta = days_between(cur, expiration_date_map[version[0]])
                if days_delta < 0:
                    valid_version = False
                    error_str = '{}: Current version of your container {} has expired on {} UTC'
                    for container in containers:
                        errors.append(
                            error_str.format(container.name, version[1],
                                             expiration_date_map[version[0]]))
                elif days_delta < 7:
                    warnings_str = '{}: Current version of your software ({}) is expiring on {} UTC, '
                    'please consider upgrading soon'
                    for container in containers:
                        warnings.append(
                            warnings_str.format(
                                container.name, version[1],
                                expiration_date_map[version[0]]))
            except KeyError:
                valid_version = False
                error_str = '{}: Current version of your container ({}) is not supported anymore or '
                'wadebug tool is not up-to-date'
                for container in containers:
                    errors.append(error_str.format(container.name, version[1]))
            return valid_version

        running_wa_containers = get_all_running_wa_containers()

        valid_versions = []
        for key, value in running_wa_containers.items():
            if (len(value[docker_utils.WA_COREAPP_CONTAINER_TAG]) != len(
                    value[docker_utils.WA_WEBAPP_CONTAINER_TAG])):
                errors.append(
                    'Number of coreapp containers for version {} is not same as '
                    'number of webapp containers'.format(key))
            elif is_valid_version(key, value):
                valid_versions.append(key[1])

        if (len(valid_versions) > 1):
            warnings.append(
                'More than one set of valid software versions({}) are running. '
                'It may be fine, but worth noticing.'.format(valid_versions))

        if errors:
            error_str = 'Error Message: {}\n'
            warning_str = 'Warning Message: {}\n'

            return results.Problem(
                cls,
                'Some of your WhatsApp container versions are expired or there is mismatch between versions'
                ' of coreapp and webapp',
                '{}\n{}'.format(
                    '\n'.join([error_str.format(e) for e in errors]),
                    '\n'.join([warning_str.format(w) for w in warnings])),
                'Please find the following link to find latest version: '
                'https://developers.facebook.com/docs/whatsapp/changelog\n'
                'and please find upgrade instructions here:'
                'https://developers.facebook.com/docs/whatsapp/guides/installation\n',
            )

        if warnings:
            warning_str = 'Warning Message: {}\n'
            return results.Warning(
                cls,
                'Some of your WhatsApp conatiners are nearing expiration or '
                'more than one valid version is running',
                '\n'.join([warning_str.format(w) for w in warnings]),
                'Please find the following link to find latest version: '
                'https://developers.facebook.com/docs/whatsapp/changelog\n'
                'and please find upgrade instructions here:'
                'https://developers.facebook.com/docs/whatsapp/guides/installation\n',
            )

        return results.OK(cls)