def test_message(self): """ The message is extracted from the log line. """ line = "<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEquals('hello', result['message'])
def test_messageBOMAbsent(self): """ The message without leading BOM is decoded as latin1. """ line = b"<13>Jan 15 16:59:26 myhost test: ol\xe1" result = syslog.parseSyslog(line, self.tz) self.assertEqual(u'olá', result['message'])
def test_invalidFormat(self): """ If the log line cannot be parsed, it is returned as the message. """ line = "something" result = syslog.parseSyslog(line, self.tz) self.assertEquals('something', result['message'])
def test_messageBOM(self): """ The message with leading BOM is decoded as UTF-8. """ line = b"<13>Jan 15 16:59:26 myhost test: \xef\xbb\xbfol\xc3\xa1" result = syslog.parseSyslog(line, self.tz) self.assertEqual(u'olá', result['message'])
def test_hostnameEmpty(self): """ The message is extracted from the log line. """ line = b"<13>Jan 15 16:59:26 test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEqual('', result['hostname'])
def test_message(self): """ The message is extracted from the log line. """ line = b"<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEqual(u'hello', result['message'])
def test_invalidFormat(self): """ If the log line cannot be parsed, it is returned as the message. """ line = b"something" result = syslog.parseSyslog(line, self.tz) self.assertEqual(u'something', result['message'])
def test_tag(self): """ The tag is extracted. """ line = b"<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEqual('test', result['tag'])
def test_hostname(self): """ The hostname is extracted. """ line = "<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEquals('myhost', result['hostname'])
def test_hostname(self): """ The hostname is extracted. """ line = b"<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEqual('myhost', result['hostname'])
def test_tag(self): """ The tag is extracted. """ line = "<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEquals('test', result['tag'])
def test_priority(self): """ The priority is extracted and decoded into facility and severity. """ line = b"<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEqual('user', result['facility']) self.assertEqual('notice', result['severity'])
def test_tagFollowedByPID(self): """ If a tag is followed by a PID, the PID is not included. """ line = ("<29>Jan 16 15:08:58 myhost wpa_supplicant[1432]: " "wlan0: CTRL-EVENT-SCAN-STARTED ") result = syslog.parseSyslog(line, self.tz) self.assertEqual('wpa_supplicant', result['tag'])
def test_priorityInvalid(self): """ The C{'facility'} and C{'severity'} are omitted for invalid priorities. """ line = b"<192>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertNotIn('facility', result) self.assertNotIn('severity', result)
def test_timestampInvalid(self): """ Invalid dates result in no timestamp, error logged. """ line = b"<13>Foo 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertNotIn('timestamp', result) self.assertEqual(1, len(self.flushLoggedErrors(ValueError)))
def test_timestampOtherZone(self): """ Timestamp is converted to a L{datetime} in the other timezone. """ line = "<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, tz.gettz('America/Los Angeles')) timestamp = datetime.datetime(2015, 1, 16, 00, 59, 26, tzinfo=tz.tzutc()) self.assertEquals(timestamp, result['timestamp'])
def test_priorityInvalid(self): """ The C{'facility'} and C{'severity'} are omitted for invalid priorities. """ line = "<192>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertNotIn('facility', result) self.assertNotIn('severity', result)
def test_tagFollowedByPID(self): """ If a tag is followed by a PID, the PID is not included. """ line = ("<29>Jan 16 15:08:58 myhost wpa_supplicant[1432]: " "wlan0: CTRL-EVENT-SCAN-STARTED ") result = syslog.parseSyslog(line, self.tz) self.assertEquals('wpa_supplicant', result['tag'])
def test_timestampInvalid(self): """ Invalid dates result in no timestamp, error logged. """ line = "<13>Foo 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertNotIn('timestamp', result) self.assertEqual(1, len(self.flushLoggedErrors(ValueError)))
def test_timestampSingleDigitDay(self): """ Single digit days are parsed correctly. """ line = "<13>Jan 5 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) timestamp = datetime.datetime(2015, 1, 5, 15, 59, 26, tzinfo=tz.tzutc()) self.assertEquals(timestamp, result['timestamp'])
def test_timestamp(self): """ Timestamp is converted to a L{datetime} in the given timezone. """ line = "<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) timestamp = datetime.datetime(2015, 1, 15, 15, 59, 26, tzinfo=tz.tzutc()) self.assertEquals(timestamp, result['timestamp'])
def test_priority(self): """ The priority is extracted and decoded into facility and severity. """ line = "<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) self.assertEquals('user', result['facility']) self.assertEquals('notice', result['severity'])
def test_pid(self): """ The optional PID is extracted. """ line = ("<29>Jan 16 15:08:58 myhost wpa_supplicant[1432]: " "wlan0: CTRL-EVENT-SCAN-STARTED ") result = syslog.parseSyslog(line, self.tz) self.assertEqual('1432', result['pid']) self.assertEqual('wlan0: CTRL-EVENT-SCAN-STARTED ', result['message'])
def test_cee(self): """ If there's a CEE structure in the message, its fields are merged in. """ line = (b'<13>Jan 16 21:00:00 waar ralphm: ' b'blah @cee: {"event": "started"}') result = syslog.parseSyslog(line, self.tz) self.assertEqual(u'blah', result['message']) self.assertEqual('started', result['event'])
def test_timestampRFC3339(self): """ RFC3339/ISO8601 timestamp are parsed. """ line = b"<13>2015-01-15T15:59:26.341-00 myhost test: hello" result = syslog.parseSyslog(line, self.tz) timestamp = datetime.datetime(2015, 1, 15, 15, 59, 26, 341000, tzinfo=tz.tzutc()) self.assertEqual(timestamp, result['timestamp'])
def test_ceeEmptyMessage(self): """ If the message starts with the CEE marker, the message is empty. """ line = (b'<13>Jan 16 21:00:00 waar ralphm: ' b'@cee: {"event": "started"}') result = syslog.parseSyslog(line, self.tz) self.assertEqual(u'', result['message']) self.assertEqual('started', result['event'])
def test_ceeEmptyMessage(self): """ If the message starts with the CEE marker, the message is empty. """ line = ('<13>Jan 16 21:00:00 waar ralphm: ' '@cee: {"event": "started"}') result = syslog.parseSyslog(line, self.tz) self.assertEquals('', result['message']) self.assertEquals('started', result['event'])
def test_cee(self): """ If there's a CEE structure in the message, its fields are merged in. """ line = ('<13>Jan 16 21:00:00 waar ralphm: ' 'blah @cee: {"event": "started"}') result = syslog.parseSyslog(line, self.tz) self.assertEquals('blah', result['message']) self.assertEquals('started', result['event'])
def test_pid(self): """ The optional PID is extracted. """ line = ("<29>Jan 16 15:08:58 myhost wpa_supplicant[1432]: " "wlan0: CTRL-EVENT-SCAN-STARTED ") result = syslog.parseSyslog(line, self.tz) self.assertEquals('1432', result['pid']) self.assertEquals('wlan0: CTRL-EVENT-SCAN-STARTED ', result['message'])
def test_ceeInvalid(self): """ If the CEE structure is invalid, the message field includes it. """ line = (b'<13>Jan 16 21:00:00 waar ralphm: ' b'blah @cee: {"event": "started}') result = syslog.parseSyslog(line, self.tz) self.assertEqual(u'blah @cee: {"event": "started}', result['message']) self.assertNotIn('event', result) self.assertEqual(1, len(self.flushLoggedErrors(ValueError)))
def test_ceeInvalid(self): """ If the CEE structure is invalid, the message field includes it. """ line = ('<13>Jan 16 21:00:00 waar ralphm: ' 'blah @cee: {"event": "started}') result = syslog.parseSyslog(line, self.tz) self.assertEquals('blah @cee: {"event": "started}', result['message']) self.assertNotIn('event', result) self.assertEqual(1, len(self.flushLoggedErrors(ValueError)))
def test_timestamp(self): """ Timestamp is converted to a L{datetime} in the given timezone. """ line = b"<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) timestamp = datetime.datetime(2015, 1, 15, 15, 59, 26, tzinfo=tz.tzutc()) self.assertEqual(timestamp, result['timestamp'])
def test_timestampOtherZone(self): """ Timestamp is converted to a L{datetime} in the other timezone. """ line = b"<13>Jan 15 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, tz.gettz('America/Los Angeles')) timestamp = datetime.datetime(2015, 1, 16, 00, 59, 26, tzinfo=tz.tzutc()) self.assertEqual(timestamp, result['timestamp'])
def test_timestampSingleDigitDayZero(self): """ Single digit days with leading zero are parsed correctly. """ line = b"<13>Jan 05 16:59:26 myhost test: hello" result = syslog.parseSyslog(line, self.tz) timestamp = datetime.datetime(2015, 1, 5, 15, 59, 26, tzinfo=tz.tzutc()) self.assertEqual(timestamp, result['timestamp'])