Example #1
0
def run_checks(request):
    _deprecation_warnings()

    if settings.WATCHMAN_DISABLE_APM:
        _disable_apm()

    checks = {}
    ok = True

    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            _check = check()
            # Set our HTTP status code if there were any errors
            if settings.WATCHMAN_ERROR_CODE != 200:
                for _type in _check:
                    if type(_check[_type]) == dict:
                        result = _check[_type]
                        if not result['ok']:
                            ok = False
                    elif type(_check[_type]) == list:
                        for entry in _check[_type]:
                            for result in entry:
                                if not entry[result]['ok']:
                                    ok = False
            checks.update(_check)

    return checks, ok
def status(request):
    _deprecation_warnings()

    response = {}
    http_code = 200

    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            _check = check()
            # Set our HTTP status code if there were any errors
            if settings.WATCHMAN_ERROR_CODE != 200:
                for _type in _check:
                    if type(_check[_type]) == dict:
                        result = _check[_type]
                        if not result['ok']:
                            http_code = settings.WATCHMAN_ERROR_CODE
                    elif type(_check[_type]) == list:
                        for entry in _check[_type]:
                            for result in entry:
                                if not entry[result]['ok']:
                                    http_code = settings.WATCHMAN_ERROR_CODE
            response.update(_check)

    if len(response) == 0:
        raise Http404(_('No checks found'))

    return response, http_code, {WATCHMAN_VERSION_HEADER: __version__}
Example #3
0
def run_checks(request):
    _deprecation_warnings()

    if settings.WATCHMAN_DISABLE_APM:
        _disable_apm()

    checks = {}
    ok = True

    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            _check = check()
            # Set our HTTP status code if there were any errors
            if settings.WATCHMAN_ERROR_CODE != 200:
                for _type in _check:
                    if type(_check[_type]) == dict:
                        result = _check[_type]
                        if not result['ok']:
                            ok = False
                    elif type(_check[_type]) == list:
                        for entry in _check[_type]:
                            for result in entry:
                                if not entry[result]['ok']:
                                    ok = False
            checks.update(_check)

    return checks, ok
Example #4
0
def status(request):
    response = {}
    http_code = 200

    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            _check = check()
            # Set our HTTP status code if there were any errors
            if settings.WATCHMAN_ERROR_CODE != 200:
                for _type in _check:
                    if type(_check[_type]) == dict:
                        result = _check[_type]
                        if not result['ok']:
                            http_code = settings.WATCHMAN_ERROR_CODE
                    elif type(_check[_type]) == list:
                        for entry in _check[_type]:
                            for result in entry:
                                if not entry[result]['ok']:
                                    http_code = settings.WATCHMAN_ERROR_CODE
            response.update(_check)

    if len(response) == 0:
        raise Http404(_('No checks found'))

    return response, http_code, {WATCHMAN_VERSION_HEADER: __version__}
Example #5
0
 def test_get_checks_with_check_list_returns_union(self):
     check_list = ['watchman.checks.caches']
     checks = [
         check.__name__ for check in get_checks(check_list=check_list)
     ]
     expected_checks = ['caches']
     self.assert_lists_equal(checks, expected_checks)
Example #6
0
 def test_get_checks_with_check_and_skip_list(self):
     check_list = ['watchman.checks.caches', 'watchman.checks.databases']
     skip_list = ['watchman.checks.caches']
     checks = [
         check.__name__
         for check in get_checks(check_list=check_list, skip_list=skip_list)
     ]
     expected_checks = ['databases']
     self.assert_lists_equal(checks, expected_checks)
Example #7
0
 def test_get_checks_with_matching_check_and_skip_list_returns_empty_list(
         self):
     check_list, skip_list = ['watchman.checks.caches'
                              ], ['watchman.checks.caches']
     checks = [
         check.__name__
         for check in get_checks(check_list=check_list, skip_list=skip_list)
     ]
     expected_checks = []
     self.assert_lists_equal(checks, expected_checks)
Example #8
0
def status(request):
    response = {}

    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            response.update(check())

    if len(response) == 0:
        raise Http404(_('No checks found'))

    return response, 200, {WATCHMAN_VERSION_HEADER: __version__}
Example #9
0
    def handle(self, *args, **options):
        check_list = None
        skip_list = None

        checks = options['checks']
        skips = options['skips']

        if checks is not None:
            check_list = checks.split(',')

        if skips is not None:
            skip_list = skips.split(',')

        for check in get_checks(check_list=check_list, skip_list=skip_list):
            if callable(check):
                resp = json.dumps(check())
                if '"ok": false' in resp:
                    raise CommandError(resp)
                # Cast to int for Django < 1.8 (used to be a string value)
                elif int(options['verbosity']) >= 2:
                    self.stdout.write(resp)
Example #10
0
    def handle(self, *args, **options):
        check_list = None
        skip_list = None

        checks = options['checks']
        skips = options['skips']

        if checks is not None:
            check_list = checks.split(',')

        if skips is not None:
            skip_list = skips.split(',')

        for check in get_checks(check_list=check_list, skip_list=skip_list):
            if callable(check):
                resp = json.dumps(check())
                if '"ok": false' in resp:
                    raise CommandError(resp)
                # Cast to int for Django < 1.8 (used to be a string value)
                elif int(options['verbosity']) >= 2:
                    self.stdout.write(resp)
Example #11
0
    def handle(self, *args, **options):
        check_list = None
        skip_list = None
        verbosity = options['verbosity']
        print_all_checks = verbosity == '2' or verbosity == '3'

        checks = options['checks']
        skips = options['skips']

        if checks is not None:
            check_list = checks.split(',')

        if skips is not None:
            skip_list = skips.split(',')

        for check in get_checks(check_list=check_list, skip_list=skip_list):
            if callable(check):
                resp = json.dumps(check())
                if '"ok": false' in resp:
                    raise CommandError(resp)
                elif print_all_checks:
                    self.stdout.write(resp)
Example #12
0
    def handle(self, *args, **options):
        check_list = None
        skip_list = None
        verbosity = options['verbosity']
        print_all_checks = verbosity in ['2', '3', ]

        checks = options['checks']
        skips = options['skips']

        if checks is not None:
            check_list = checks.split(',')

        if skips is not None:
            skip_list = skips.split(',')

        for check in get_checks(check_list=check_list, skip_list=skip_list):
            if callable(check):
                resp = json.dumps(check())
                if '"ok": false' in resp:
                    raise CommandError(resp)
                elif print_all_checks:
                    self.stdout.write(resp)
Example #13
0
 def test_get_checks_with_check_and_skip_list(self):
     check_list = ['watchman.checks.caches', 'watchman.checks.databases']
     skip_list = ['watchman.checks.caches']
     checks = [check.__name__ for check in get_checks(check_list=check_list, skip_list=skip_list)]
     expected_checks = ['databases']
     self.assertListsEqual(checks, expected_checks)
Example #14
0
 def test_get_checks_with_skip_list_returns_difference(self):
     skip_list = ['watchman.checks.caches']
     checks = [check.__name__ for check in get_checks(skip_list=skip_list)]
     expected_checks = ['databases', 'storage']
     self.assert_lists_equal(checks, expected_checks)
Example #15
0
def dashboard(request):
    _deprecation_warnings()

    check_types = []

    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            _check = check()

            for _type in _check:
                # For other systems (eg: email, storage) _check[_type] is a
                # dictionary of status
                #
                # Example:
                # {
                #     'ok': True,  # Status
                # }
                #
                # Example:
                # {
                #     'ok': False,  # Status
                #     'error': "RuntimeError",
                #     'stacktrace': "...",
                # }
                #
                # For some systems (eg: cache, database) _check[_type] is a
                # list of dictionaries of dictionaries of statuses
                #
                # Example:
                # [
                #     {
                #         'default': {  # Cache/database name
                #             'ok': True,  # Status
                #         }
                #     },
                #     {
                #         'non-default': {  # Cache/database name
                #             'ok': False,  # Status
                #             'error': "RuntimeError",
                #             'stacktrace': "...",
                #         }
                #     },
                # ]
                #
                statuses = []

                if type(_check[_type]) == dict:
                    result = _check[_type]
                    statuses = [{
                        'name':
                        '',
                        'ok':
                        result['ok'],
                        'error':
                        '' if result['ok'] else result['error'],
                        'stacktrace':
                        '' if result['ok'] else result['stacktrace'],
                    }]

                    type_overall_status = _check[_type]['ok']

                elif type(_check[_type]) == list:
                    for result in _check[_type]:
                        for name in result:
                            statuses.append({
                                'name':
                                name,
                                'ok':
                                result[name]['ok'],
                                'error':
                                '' if result[name]['ok'] else
                                result[name]['error'],
                                'stacktrace':
                                '' if result[name]['ok'] else
                                result[name]['stacktrace'],
                            })

                    type_overall_status = all(s['ok'] for s in statuses)

                check_types.append({
                    'type':
                    _type,
                    'type_singular':
                    _type[:-1] if _type.endswith('s') else _type,
                    'ok':
                    type_overall_status,
                    'statuses':
                    statuses
                })

    overall_status = all(type_status['ok'] for type_status in check_types)

    response = render(request, 'watchman/dashboard.html', {
        'checks': check_types,
        'overall_status': overall_status
    })

    response[WATCHMAN_VERSION_HEADER] = __version__
    return response
Example #16
0
 def test_get_checks_returns_all_available_checks_by_default(self):
     checks = [check.__name__ for check in get_checks()]
     expected_checks = ['caches', 'databases', 'storage']
     self.assert_lists_equal(checks, expected_checks)
Example #17
0
def dashboard(request):
    _deprecation_warnings()

    check_types = []

    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            _check = check()

            for _type in _check:
                # For other systems (eg: email, storage) _check[_type] is a
                # dictionary of status
                #
                # Example:
                # {
                #     'ok': True,  # Status
                # }
                #
                # Example:
                # {
                #     'ok': False,  # Status
                #     'error': "RuntimeError",
                #     'stacktrace': "...",
                # }
                #
                # For some systems (eg: cache, database) _check[_type] is a
                # list of dictionaries of dictionaries of statuses
                #
                # Example:
                # [
                #     {
                #         'default': {  # Cache/database name
                #             'ok': True,  # Status
                #         }
                #     },
                #     {
                #         'non-default': {  # Cache/database name
                #             'ok': False,  # Status
                #             'error': "RuntimeError",
                #             'stacktrace': "...",
                #         }
                #     },
                # ]
                #
                statuses = []

                if type(_check[_type]) == dict:
                    result = _check[_type]
                    statuses = [{
                        'name': '',
                        'ok': result['ok'],
                        'error': '' if result['ok'] else result['error'],
                        'stacktrace': '' if result['ok'] else result['stacktrace'],
                    }]

                    type_overall_status = _check[_type]['ok']

                elif type(_check[_type]) == list:
                    for result in _check[_type]:
                        for name in result:
                            statuses.append({
                                'name': name,
                                'ok': result[name]['ok'],
                                'error': '' if result[name]['ok'] else result[name]['error'],
                                'stacktrace': '' if result[name]['ok'] else result[name]['stacktrace'],
                            })

                    type_overall_status = all(s['ok'] for s in statuses)

                check_types.append({
                    'type': _type,
                    'type_singular': _type[:-1] if _type.endswith('s') else _type,
                    'ok': type_overall_status,
                    'statuses': statuses})

    overall_status = all(type_status['ok'] for type_status in check_types)

    response = render(request, 'watchman/dashboard.html', {
        'checks': check_types,
        'overall_status': overall_status
    })

    response[WATCHMAN_VERSION_HEADER] = __version__
    return response
Example #18
0
def get_statuses(request):
    check_types = []
    check_list, skip_list = _get_check_params(request)

    for check in get_checks(check_list=check_list, skip_list=skip_list):
        if callable(check):
            _check = check()

            for _type in _check:
                # For other systems (eg: email, storage) _check[_type] is a
                # dictionary of status
                #
                # Example:
                # {
                #     'ok': True,  # Status
                # }
                #
                # Example:
                # {
                #     'ok': False,  # Status
                #     'error': "RuntimeError",
                #     'stacktrace': "...",
                # }
                #
                # For some systems (eg: cache, database) _check[_type] is a
                # list of dictionaries of dictionaries of statuses
                #
                # Example:
                # [
                #     {
                #         'default': {  # Cache/database name
                #             'ok': True,  # Status
                #         }
                #     },
                #     {
                #         'non-default': {  # Cache/database name
                #             'ok': False,  # Status
                #             'error': "RuntimeError",
                #             'stacktrace': "...",
                #         }
                #     },
                # ]
                #
                statuses = []

                if type(_check[_type]) == dict:
                    result = _check[_type]
                    statuses = [{
                        'name': '',
                        'ok': result['ok'],
                        'error': '' if result['ok'] else result['error'],
                        'stacktrace': '' if result['ok'] else result['stacktrace'],
                    }]

                    type_overall_status = _check[_type]['ok']

                elif type(_check[_type]) == list:
                    for result in _check[_type]:
                        for name in result:
                            statuses.append({
                                'name': name,
                                'ok': result[name]['ok'],
                                'error': '' if result[name]['ok'] else result[name]['error'],
                                'stacktrace': '' if result[name]['ok'] else result[name]['stacktrace'],
                            })

                    type_overall_status = all([s['ok'] for s in statuses])

                check_types.append({
                    'type': _type,
                    'ok': type_overall_status,
                    'statuses': statuses})

    overall_status = all([type_status['ok'] for type_status in check_types])
    return check_types, overall_status
Example #19
0
 def test_get_checks_returns_all_available_checks_by_default(self):
     checks = [check.__name__ for check in get_checks()]
     expected_checks = ['caches', 'databases', 'storage']
     self.assertListsEqual(checks, expected_checks)
Example #20
0
 def test_get_checks_with_check_list_returns_union(self):
     check_list = ['watchman.checks.caches']
     checks = [check.__name__ for check in get_checks(check_list=check_list)]
     expected_checks = ['caches']
     self.assertListsEqual(checks, expected_checks)
Example #21
0
 def test_get_checks_with_matching_check_and_skip_list_returns_empty_list(self):
     check_list, skip_list = ['watchman.checks.caches'], ['watchman.checks.caches']
     checks = [check.__name__ for check in get_checks(check_list=check_list, skip_list=skip_list)]
     expected_checks = []
     self.assertListsEqual(checks, expected_checks)
Example #22
0
 def test_get_checks_with_skip_list_returns_difference(self):
     skip_list = ['watchman.checks.caches']
     checks = [check.__name__ for check in get_checks(skip_list=skip_list)]
     expected_checks = ['databases', 'storage']
     self.assertListsEqual(checks, expected_checks)
Example #23
0
 def test_get_checks_with_paid_checks_disabled_returns_expected_checks(
         self):
     expected_checks = ['caches', 'databases', 'storage']
     checks = [check.__name__ for check in get_checks()]
     self.assert_lists_equal(checks, expected_checks)
Example #24
0
 def test_get_checks_with_paid_checks_disabled_returns_expected_checks(self):
     expected_checks = ['caches', 'databases', 'storage']
     checks = [check.__name__ for check in get_checks()]
     self.assertListsEqual(checks, expected_checks)