Date parsers

This module provides processing for the output of the date command in various formats.

Date - command date

Class Date parses the output of the date command. Sample output of this command looks like:

Fri Jun 24 09:13:34 CST 2016

DateUTC - command date --utc

Class DateUTC parses the output of the date --utc command. Output is similar to the date command except that the Timezone column uses UTC.

All classes utilize the same base class DateParser so the following examples apply to all classes in this module.

Examples

>>> from insights.parsers.date import Date, DateUTC
>>> from insights.tests import context_wrap
>>> date_content = "Mon May 30 10:49:14 CST 2016"
>>> shared = {Date: Date(context_wrap(date_content))}
>>> date_info = shared[Date]
>>> date_info.data
'Mon May 30 10:49:14 CST 2016'
>>> date_info.datetime is not None
True
>>> date_info.timezone
'CST'
>>> date_content = "Mon May 30 10:49:14 UTC 2016"
>>> shared = {DateUTC: DateUTC(context_wrap(date_content))}
>>> date_info = shared[DateUTC]
>>> date_info.data
'Mon May 30 10:49:14 UTC 2016'
>>> date_info.datetime
datetime.datetime(2016, 5, 30, 10, 49, 14)
>>> date_info.timezone
'UTC'
class insights.parsers.date.Date(context, extra_bad_lines=None)[source]

Bases: insights.parsers.date.DateParser

Class to parse date command output.

Sample: Fri Jun 24 09:13:34 CST 2016

exception insights.parsers.date.DateParseException[source]

Bases: Exception

class insights.parsers.date.DateParser(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Base class implementing shared code.

parse_content(content)[source]

Parses the output of the date and date --utc command.

Sample: Fri Jun 24 09:13:34 CST 2016 Sample: Fri Jun 24 09:13:34 UTC 2016

datetime

A native datetime.datetime of the parsed date string

Type

datetime.datetime

timezone

The string portion of the date string containing the timezone

Type

str

Raises

DateParseException: Raised if any exception occurs parsing the content.

class insights.parsers.date.DateUTC(context, extra_bad_lines=None)[source]

Bases: insights.parsers.date.DateParser

Class to parse date --utc command output.

Sample: Fri Jun 24 09:13:34 UTC 2016