def test_severityCrit(self): """ The syslog severity 'crit' is mapped to 'CRITICAL'. """ eventDict = {'severity': 'crit'} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('CRITICAL', eventDict['logLevel'])
def test_categoryDefault(self): """ If the category is not set, it is set to C{'syslog'}. """ eventDict = {} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('syslog', eventDict['category'])
def test_severityEmerg(self): """ The syslog severity 'emerg' is mapped to 'EMERGENCY'. """ eventDict = {'severity': 'emerg'} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('EMERGENCY', eventDict['logLevel'])
def test_categoryAlreadySet(self): """ If the category is set, it is left unchanged. """ eventDict = {'category': 'test'} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('test', eventDict['category'])
def test_hostnames(self): """ A matching hostname in the hostname mapping overrides. """ eventDict = {'hostname': 'test'} eventDict = syslog.syslogToUDPLogEvent( eventDict, hostnames={'test': 'test.example.org'}) self.assertEqual('test.example.org', eventDict['hostname'])
def test_severityWarn(self): """ The syslog severity 'warn' is mapped to 'WARNING'. """ eventDict = {'severity': 'warn'} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('WARNING', eventDict['logLevel']) self.assertNotIn('severity', eventDict)
def test_severity(self): """ If the syslog event has a severity, it is renamed, mapped to logLevel. """ eventDict = {'severity': 'debug'} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('DEBUG', eventDict['logLevel']) self.assertNotIn('severity', eventDict)
def test_tag(self): """ If the syslog event has a tag, it is renamed to appname. """ eventDict = {'tag': 'test'} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('test', eventDict['appname']) self.assertNotIn('tag', eventDict)
def test_severityErr(self): """ The syslog severity 'err' is mapped to 'ERROR'. """ eventDict = {'severity': 'err'} eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual('ERROR', eventDict['logLevel']) self.assertNotIn('severity', eventDict)
def test_defaultHostnameNoMatch(self): """ A non-matching hostname in the hostname mapping remains unchanged. """ eventDict = {'hostname': 'foo'} eventDict = syslog.syslogToUDPLogEvent( eventDict, hostnames={'test': 'test.example.org'}) self.assertEqual('foo', eventDict['hostname'])
def test_timestampSubSecond(self): """ Datetimes with microseconds yield a fractional timestamp. """ eventDict = { 'timestamp': datetime.datetime(2015, 1, 15, 15, 59, 26, 341000, tzinfo=tz.tzutc()) } eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual(1421337566.341, eventDict['timestamp'])
def test_timestamp(self): """ The event timestamp is converted to a POSIX timestamp. """ eventDict = { 'timestamp': datetime.datetime(2015, 1, 15, 15, 59, 26, tzinfo=tz.tzutc()) } eventDict = syslog.syslogToUDPLogEvent(eventDict) self.assertEqual(1421337566, eventDict['timestamp'])