Exemple #1
0
 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'])
Exemple #2
0
 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'])
Exemple #3
0
 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'])
Exemple #4
0
 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'])
Exemple #5
0
 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'])
Exemple #6
0
 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'])
Exemple #7
0
 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'])
Exemple #8
0
 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'])
Exemple #9
0
 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'])
Exemple #10
0
 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'])
Exemple #11
0
 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'])
Exemple #12
0
 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'])
Exemple #13
0
 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'])
Exemple #14
0
 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'])
Exemple #15
0
 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'])
Exemple #16
0
 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'])
Exemple #17
0
 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)
Exemple #18
0
 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)))
Exemple #19
0
 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'])
Exemple #20
0
 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)
Exemple #21
0
 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'])
Exemple #22
0
 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)))
Exemple #23
0
 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'])
Exemple #24
0
 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'])
Exemple #25
0
 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'])
Exemple #26
0
 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'])
Exemple #27
0
 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'])
Exemple #28
0
 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'])
Exemple #29
0
 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'])
Exemple #30
0
 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'])
Exemple #31
0
 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'])
Exemple #32
0
 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'])
Exemple #33
0
 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)))
Exemple #34
0
 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)))
Exemple #35
0
 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'])
Exemple #36
0
 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'])
Exemple #37
0
 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'])
Exemple #38
0
 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'])