Example #1
0
    def handle_test(self, command, **options):
        """Send a test error to Opbeat"""
        self.write(LOGO, cyan)
        config = get_client_config()
        # can't be async for testing
        config['async_mode'] = False
        for key in ('organization_id', 'app_id', 'secret_token'):
            if options.get(key):
                config[key] = options[key]
        client_class = get_client_class()
        client = client_class(**config)
        client.error_logger = ColoredLogger(self.stderr)
        client.logger = ColoredLogger(self.stderr)
        client.state.logger = client.logger
        client.state.error_logger = client.error_logger
        self.write(
            "Trying to send a test error to Opbeat using these settings:\n\n"
            "ORGANIZATION_ID:\t%s\n"
            "APP_ID:\t\t\t%s\n"
            "SECRET_TOKEN:\t\t%s\n"
            "SERVERS:\t\t%s\n\n" %
            (client.organization_id, client.app_id, client.secret_token,
             ', '.join(client.servers)))

        try:
            raise OpbeatTestException('Hi there!')
        except OpbeatTestException as e:
            result = client.capture_exception()
            if not client.error_logger.errors:
                self.write(
                    'Success! We tracked the error successfully! You should be'
                    ' able to see it in a few seconds at the above URL')
Example #2
0
    def handle_test(self, command, **options):
        """Send a test error to Opbeat"""
        self.write(LOGO, cyan)
        config = get_client_config()
        # can't be async for testing
        config['async_mode'] = False
        for key in ('organization_id', 'app_id', 'secret_token'):
            if options.get(key):
                config[key] = options[key]
        client_class = get_client_class()
        client = client_class(**config)
        client.error_logger = ColoredLogger(self.stderr)
        client.logger = ColoredLogger(self.stderr)
        client.state.logger = client.logger
        client.state.error_logger = client.error_logger
        self.write(
            "Trying to send a test error to Opbeat using these settings:\n\n"
            "ORGANIZATION_ID:\t%s\n"
            "APP_ID:\t\t\t%s\n"
            "SECRET_TOKEN:\t\t%s\n"
            "SERVERS:\t\t%s\n\n" % (
                client.organization_id,
                client.app_id,
                client.secret_token,
                ', '.join(client.servers)
            )
        )

        try:
            raise OpbeatTestException('Hi there!')
        except OpbeatTestException as e:
            result = client.capture_exception()
            if not client.error_logger.errors:
                self.write(
                    'Success! We tracked the error successfully! You should be'
                    ' able to see it in a few seconds at the above URL'
                )
Example #3
0
    def handle_check(self, command, **options):
        """Check your settings for common misconfigurations"""
        self.write(LOGO, cyan)
        passed = True
        config = get_client_config()
        client_class = get_client_class()
        client = client_class(**config)
        # check if org/app and token are set:
        is_set = lambda x: x and x != 'None'
        values = [client.organization_id, client.app_id, client.secret_token]
        if all(map(is_set, values)):
            self.write('Organization, app and secret token are set, good job!',
                       green)
        else:
            passed = False
            self.write('Configuration errors detected!', red, ending='\n\n')
            if not is_set(client.organization_id):
                self.write("  * ORGANIZATION_ID not set! ", red, ending='\n')
            if not is_set(client.app_id):
                self.write("  * APP_ID not set! ", red, ending='\n')
            if not is_set(client.secret_token):
                self.write("  * SECRET_TOKEN not set!", red, ending='\n')
            self.write(CONFIG_EXAMPLE)
        self.write('')

        # check if we're disabled due to DEBUG:
        if settings.DEBUG:
            if getattr(settings, 'OPBEAT', {}).get('DEBUG'):
                self.write(
                    'Note: even though you are running in DEBUG mode, we will '
                    'send data to Opbeat, because you set OPBEAT["DEBUG"] to '
                    'True. You can disable Opbeat while in DEBUG mode like this'
                    '\n\n', yellow)
                self.write('   OPBEAT = {\n'
                           '       "DEBUG": False,\n'
                           '       # your other OPBEAT settings\n'
                           '   }')
            else:
                self.write(
                    'Looks like you\'re running in DEBUG mode. Opbeat will NOT '
                    'gather any data while DEBUG is set to True.\n\n',
                    red,
                )
                self.write(
                    'If you want to test Opbeat while DEBUG is set to True, you'
                    ' can force Opbeat to gather data by setting'
                    ' OPBEAT["DEBUG"] to True, like this\n\n'
                    '   OPBEAT = {\n'
                    '       "DEBUG": True,\n'
                    '       # your other OPBEAT settings\n'
                    '   }')
                passed = False
        else:
            self.write('DEBUG mode is disabled! Looking good!', green)
        self.write('')

        # check if middleware is set, and if it is at the first position
        middleware = list(settings.MIDDLEWARE_CLASSES)
        try:
            pos = middleware.index(
                'opbeat.contrib.django.middleware.OpbeatAPMMiddleware')
            if pos == 0:
                self.write('Opbeat APM middleware is set! Awesome!', green)
            else:
                self.write(
                    'Opbeat APM middleware is set, but not at the first '
                    'position\n', yellow)
                self.write(
                    'Opbeat APM works best if you add it at the top of your '
                    'MIDDLEWARE_CLASSES')
        except ValueError:
            self.write('Opbeat APM middleware not set!', red)
            self.write(
                '\n'
                'Add it to your MIDDLEWARE_CLASSES like this:\n\n'
                '    MIDDLEWARE_CLASSES = (\n'
                '        "opbeat.contrib.django.middleware.OpbeatAPMMiddleware",\n'
                '        # your other middleware classes\n'
                '    )\n')
        self.write('')
        if passed:
            self.write('Looks like everything should be ready!', green)
        else:
            self.write(
                'Please fix the above errors. If you have any questions, write '
                'us at [email protected]!', red)
        self.write('')
        return passed
Example #4
0
    def handle_check(self, command, **options):
        """Check your settings for common misconfigurations"""
        self.write(LOGO, cyan)
        passed = True
        config = get_client_config()
        client_class = get_client_class()
        client = client_class(**config)
        # check if org/app and token are set:
        is_set = lambda x: x and x != 'None'
        values = [client.organization_id, client.app_id, client.secret_token]
        if all(map(is_set, values)):
            self.write(
                'Organization, app and secret token are set, good job!',
                green
            )
        else:
            passed = False
            self.write(
                'Configuration errors detected!', red, ending='\n\n'
            )
            if not is_set(client.organization_id):
                self.write(
                    "  * ORGANIZATION_ID not set! ", red, ending='\n'
                )
            if not is_set(client.app_id):
                self.write("  * APP_ID not set! ", red, ending='\n')
            if not is_set(client.secret_token):
                self.write("  * SECRET_TOKEN not set!", red, ending='\n')
            self.write(CONFIG_EXAMPLE)
        self.write('')

        # check if we're disabled due to DEBUG:
        if settings.DEBUG:
            if getattr(settings, 'OPBEAT', {}).get('DEBUG'):
                self.write(
                    'Note: even though you are running in DEBUG mode, we will '
                    'send data to Opbeat, because you set OPBEAT["DEBUG"] to '
                    'True. You can disable Opbeat while in DEBUG mode like this'
                    '\n\n',
                    yellow
                )
                self.write(
                    '   OPBEAT = {\n'
                    '       "DEBUG": False,\n'
                    '       # your other OPBEAT settings\n'
                    '   }'

                )
            else:
                self.write(
                    'Looks like you\'re running in DEBUG mode. Opbeat will NOT '
                    'gather any data while DEBUG is set to True.\n\n',
                    red,
                )
                self.write(
                    'If you want to test Opbeat while DEBUG is set to True, you'
                    ' can force Opbeat to gather data by setting'
                    ' OPBEAT["DEBUG"] to True, like this\n\n'
                    '   OPBEAT = {\n'
                    '       "DEBUG": True,\n'
                    '       # your other OPBEAT settings\n'
                    '   }'
                )
                passed = False
        else:
            self.write(
                'DEBUG mode is disabled! Looking good!',
                green
            )
        self.write('')

        # check if middleware is set, and if it is at the first position
        middleware = list(settings.MIDDLEWARE_CLASSES)
        try:
            pos = middleware.index(
                'opbeat.contrib.django.middleware.OpbeatAPMMiddleware'
            )
            if pos == 0:
                self.write(
                    'Opbeat APM middleware is set! Awesome!',
                    green
                )
            else:
                self.write(
                    'Opbeat APM middleware is set, but not at the first '
                    'position\n',
                    yellow
                )
                self.write(
                    'Opbeat APM works best if you add it at the top of your '
                    'MIDDLEWARE_CLASSES'
                )
        except ValueError:
            self.write(
                'Opbeat APM middleware not set!', red
            )
            self.write(
                '\n'
                'Add it to your MIDDLEWARE_CLASSES like this:\n\n'
                '    MIDDLEWARE_CLASSES = (\n'
                '        "opbeat.contrib.django.middleware.OpbeatAPMMiddleware",\n'
                '        # your other middleware classes\n'
                '    )\n'
            )
        self.write('')
        if passed:
            self.write('Looks like everything should be ready!', green)
        else:
            self.write(
                'Please fix the above errors. If you have any questions, write '
                'us at [email protected]!',
                red
            )
        self.write('')
        return passed