class RedisHostTestCase( unittest.TestCase ):

    def setUp( self ):
        config = {
            'module': 'scalyr_agent.builtin_monitors.syslog_monitor'
            }
        self.logger = DummyLogger()
        self.host = RedisHost( 'localhost', 6379, '', 1000 )

        self.entry = { 'command' : '',
                  'start_time' : time.time(),
                  'duration' : 100,
                  'id' : 1
                }


    def test_truncated_utf8_message( self ):
        expected = 'abc... (4 more bytes)'

        self.entry['command'] = pack( '3sB18s', 'abc', 0xce, '... (4 more bytes)' )

        self.host.log_entry( self.logger, self.entry )
        self.assertEquals( expected, self.logger.command )

    def test_non_truncated_utf8_message( self ):

        expected = 'abc... (4 more bytes)'
        self.entry['command'] = 'abc... (4 more bytes)'

        self.host.log_entry( self.logger, self.entry )

        self.assertEquals( expected, self.logger.command )
    def setUp(self):
        self.logger = DummyLogger()
        self.host = RedisHost("localhost", 6379, "", 1000)

        self.entry = {
            "command": "",
            "start_time": time.time(),
            "duration": 100,
            "id": 1,
        }
Example #3
0
    def setUp(self):
        config = {'module': 'scalyr_agent.builtin_monitors.syslog_monitor'}
        self.logger = DummyLogger()
        self.host = RedisHost('localhost', 6379, '', 1000)

        self.entry = {
            'command': '',
            'start_time': time.time(),
            'duration': 100,
            'id': 1
        }
Example #4
0
    def setUp(self):
        config = {"module": "scalyr_agent.builtin_monitors.syslog_monitor"}
        self.logger = DummyLogger()
        self.host = RedisHost("localhost", 6379, "", 1000)

        self.entry = {
            "command": "",
            "start_time": time.time(),
            "duration": 100,
            "id": 1,
        }
    def setUp( self ):
        config = {
            'module': 'scalyr_agent.builtin_monitors.syslog_monitor'
            }
        self.logger = DummyLogger()
        self.host = RedisHost( 'localhost', 6379, '', 1000 )

        self.entry = { 'command' : '',
                  'start_time' : time.time(),
                  'duration' : 100,
                  'id' : 1
                }
Example #6
0
class RedisHostTestCase(unittest.TestCase):
    def setUp(self):
        config = {'module': 'scalyr_agent.builtin_monitors.syslog_monitor'}
        self.logger = DummyLogger()
        self.host = RedisHost('localhost', 6379, '', 1000)

        self.entry = {
            'command': '',
            'start_time': time.time(),
            'duration': 100,
            'id': 1
        }

    def test_invalild_utf8_message(self):
        expected = u'abc\ufffddef'

        self.entry['command'] = pack('3sB13s', 'abc', 0xce, 'def').rstrip('\0')

        self.host.utf8_warning_interval = 1
        self.host.log_entry(self.logger, self.entry)
        self.assertEquals(expected, self.logger.command)
        self.assertTrue(
            self.logger.warning.startswith(
                "Redis command contains invalid utf8"))

    def test_truncated_utf8_message(self):
        expected = 'abc... (4 more bytes)'

        self.entry['command'] = pack('3sB18s', 'abc', 0xce,
                                     '... (4 more bytes)').rstrip('\0')

        self.host.log_entry(self.logger, self.entry)
        self.assertEquals(expected, self.logger.command)

    def test_non_truncated_utf8_message(self):

        expected = 'abc... (4 more bytes)'
        self.entry['command'] = 'abc... (4 more bytes)'

        self.host.log_entry(self.logger, self.entry)

        self.assertEquals(expected, self.logger.command)
Example #7
0
class RedisHostTestCase(unittest.TestCase):
    def setUp(self):
        config = {"module": "scalyr_agent.builtin_monitors.syslog_monitor"}
        self.logger = DummyLogger()
        self.host = RedisHost("localhost", 6379, "", 1000)

        self.entry = {
            "command": "",
            "start_time": time.time(),
            "duration": 100,
            "id": 1,
        }

    def test_invalild_utf8_message(self):
        expected = u"abc\ufffddef"

        self.entry["command"] = pack("3sB13s", "abc", 0xCE, "def").rstrip("\0")

        self.host.utf8_warning_interval = 1
        self.host.log_entry(self.logger, self.entry)
        self.assertEquals(expected, self.logger.command)
        self.assertTrue(
            self.logger.warning.startswith(
                "Redis command contains invalid utf8"))

    def test_truncated_utf8_message(self):
        expected = "abc... (4 more bytes)"

        self.entry["command"] = pack("3sB18s", "abc", 0xCE,
                                     "... (4 more bytes)").rstrip("\0")

        self.host.log_entry(self.logger, self.entry)
        self.assertEquals(expected, self.logger.command)

    def test_non_truncated_utf8_message(self):

        expected = "abc... (4 more bytes)"
        self.entry["command"] = "abc... (4 more bytes)"

        self.host.log_entry(self.logger, self.entry)

        self.assertEquals(expected, self.logger.command)
class RedisHostTestCase( unittest.TestCase ):

    def setUp( self ):
        config = {
            'module': 'scalyr_agent.builtin_monitors.syslog_monitor'
            }
        self.logger = DummyLogger()
        self.host = RedisHost( 'localhost', 6379, '', 1000 )

        self.entry = { 'command' : '',
                  'start_time' : time.time(),
                  'duration' : 100,
                  'id' : 1
                }

    def test_invalild_utf8_message( self ):
        expected = u'abc\ufffddef'

        self.entry['command'] = pack( '3sB13s', 'abc', 0xce, 'def' ).rstrip( '\0' )

        self.host.utf8_warning_interval = 1
        self.host.log_entry( self.logger, self.entry )
        self.assertEquals( expected, self.logger.command )
        self.assertTrue( self.logger.warning.startswith( "Redis command contains invalid utf8" ) )


    def test_truncated_utf8_message( self ):
        expected = 'abc... (4 more bytes)'

        self.entry['command'] = pack( '3sB18s', 'abc', 0xce, '... (4 more bytes)' ).rstrip( '\0' )

        self.host.log_entry( self.logger, self.entry )
        self.assertEquals( expected, self.logger.command )

    def test_non_truncated_utf8_message( self ):

        expected = 'abc... (4 more bytes)'
        self.entry['command'] = 'abc... (4 more bytes)'

        self.host.log_entry( self.logger, self.entry )

        self.assertEquals( expected, self.logger.command )
class RedisHostTestCase(unittest.TestCase):
    def setUp(self):
        self.logger = DummyLogger()
        self.host = RedisHost("localhost", 6379, "", 1000)

        self.entry = {
            "command": "",
            "start_time": time.time(),
            "duration": 100,
            "id": 1,
        }

    def test_invalild_utf8_message(self):
        expected = "abc\ufffddef"

        self.entry["command"] = compat.struct_pack_unicode(
            "3sB13s", b"abc", 0xCE, b"def").rstrip(b"\0")

        self.host.utf8_warning_interval = 1
        self.host.log_entry(self.logger, self.entry)
        self.assertEquals(expected, self.logger.command)
        self.assertTrue(
            self.logger.warning.startswith(
                "Redis command contains invalid utf8"))

    def test_truncated_utf8_message(self):
        expected = "abc... (4 more bytes)"

        self.entry["command"] = compat.struct_pack_unicode(
            "3sB18s", b"abc", 0xCE, b"... (4 more bytes)").rstrip(b"\0")

        self.host.log_entry(self.logger, self.entry)
        self.assertEquals(expected, self.logger.command)

    def test_non_truncated_utf8_message(self):

        expected = "abc... (4 more bytes)"
        self.entry["command"] = b"abc... (4 more bytes)"

        self.host.log_entry(self.logger, self.entry)

        self.assertEquals(expected, self.logger.command)