def test_parse_timestamp_handles_cloud_init_default_format(self): """Logs with cloud-init detailed formats will be properly parsed.""" trusty_fmt = '%Y-%m-%d %H:%M:%S,%f' trusty_stamp = '2016-09-12 14:39:20,839' dt = datetime.strptime(trusty_stamp, trusty_fmt) self.assertEqual( float(dt.strftime('%s.%f')), parse_timestamp(trusty_stamp))
def test_parse_timestamp_handles_syslog_adding_year(self): """Syslog timestamps lack a year. Add year and properly parse.""" syslog_fmt = "%b %d %H:%M:%S %Y" syslog_stamp = "Aug 08 15:12:51" # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(syslog_stamp + " " + str(year), syslog_fmt) self.assertEqual(float(dt.strftime("%s.%f")), parse_timestamp(syslog_stamp))
def test_parse_timestamp_handles_journalctl_format_adding_year(self): """Journalctl precise timestamps lack a year. Add year and parse.""" journal_fmt = '%b %d %H:%M:%S.%f %Y' journal_stamp = 'Aug 08 17:15:50.606811' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(journal_stamp + " " + str(year), journal_fmt) self.assertEqual( float(dt.strftime('%s.%f')), parse_timestamp(journal_stamp))
def test_parse_timestamp_handles_journalctl_format_adding_year(self): """Journalctl precise timestamps lack a year. Add year and parse.""" journal_fmt = '%b %d %H:%M:%S.%f %Y' journal_stamp = 'Aug 08 17:15:50.606811' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(journal_stamp + " " + str(year), journal_fmt) self.assertEqual( float(dt.strftime('%s.%f')), parse_timestamp(journal_stamp))
def test_parse_timestamp_handles_syslog_adding_year(self): """Syslog timestamps lack a year. Add year and properly parse.""" syslog_fmt = '%b %d %H:%M:%S %Y' syslog_stamp = 'Aug 08 15:12:51' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(syslog_stamp + " " + str(year), syslog_fmt) self.assertEqual( float(dt.strftime('%s.%f')), parse_timestamp(syslog_stamp))
def test_parse_unexpected_timestamp_format_with_date_command(self): """Dump sends unexpected timestamp formats to date for processing.""" new_fmt = '%H:%M %m/%d %Y' new_stamp = '17:15 08/08' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(new_stamp + " " + str(year), new_fmt) # use date(1) with self.allow_subp(["date"]): self.assertEqual(float(dt.strftime('%s.%f')), parse_timestamp(new_stamp))
def test_parse_unexpected_timestamp_format_with_date_command(self): """Dump sends unexpected timestamp formats to date for processing.""" new_fmt = '%H:%M %m/%d %Y' new_stamp = '17:15 08/08' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(new_stamp + " " + str(year), new_fmt) # use date(1) with self.allow_subp(["date"]): self.assertEqual( float(dt.strftime('%s.%f')), parse_timestamp(new_stamp))
def test_parse_unexpected_timestamp_format_with_date_command(self): """Dump sends unexpected timestamp formats to data for processing.""" new_fmt = '%H:%M %m/%d %Y' new_stamp = '17:15 08/08' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(new_stamp + " " + str(year), new_fmt) expected = float(dt.strftime('%s.%f')) parsed = parse_timestamp(new_stamp) # use date(1) out, _ = subp(['date', '+%s.%6N', '-d', new_stamp]) timestamp = out.strip() date_ts = float(timestamp) self.assertEqual(expected, parsed) self.assertEqual(expected, date_ts) self.assertEqual(date_ts, parsed)
def test_parse_timestamp_handles_journalctl_format_adding_year(self): """Journalctl precise timestamps lack a year. Add year and parse.""" journal_fmt = '%b %d %H:%M:%S.%f %Y' journal_stamp = 'Aug 08 17:15:50.606811' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(journal_stamp + " " + str(year), journal_fmt) expected = float(dt.strftime('%s.%f')) parsed = parse_timestamp(journal_stamp) # use date(1) out, _ = subp(['date', '+%s.%6N', '-d', journal_stamp]) timestamp = out.strip() date_ts = float(timestamp) self.assertEqual(expected, parsed) self.assertEqual(expected, date_ts) self.assertEqual(date_ts, parsed)
def test_parse_timestamp_handles_syslog_adding_year(self): """Syslog timestamps lack a year. Add year and properly parse.""" syslog_fmt = '%b %d %H:%M:%S %Y' syslog_stamp = 'Aug 08 15:12:51' # convert stamp ourselves by adding the missing year value year = datetime.now().year dt = datetime.strptime(syslog_stamp + " " + str(year), syslog_fmt) expected = float(dt.strftime('%s.%f')) parsed = parse_timestamp(syslog_stamp) # use date(1) out, _ = subp(['date', '+%s.%3N', '-d', syslog_stamp]) timestamp = out.strip() date_ts = float(timestamp) self.assertEqual(expected, parsed) self.assertEqual(expected, date_ts) self.assertEqual(date_ts, parsed)
def test_parse_timestamp_handles_cloud_init_default_format(self): """Logs with cloud-init detailed formats will be properly parsed.""" trusty_fmt = '%Y-%m-%d %H:%M:%S,%f' trusty_stamp = '2016-09-12 14:39:20,839' parsed = parse_timestamp(trusty_stamp) # convert ourselves dt = datetime.strptime(trusty_stamp, trusty_fmt) expected = float(dt.strftime('%s.%f')) # use date(1) out, _err = subp(['date', '+%s.%3N', '-d', trusty_stamp]) timestamp = out.strip() date_ts = float(timestamp) self.assertEqual(expected, parsed) self.assertEqual(expected, date_ts) self.assertEqual(date_ts, parsed)