diff --git a/CHANGELOG b/CHANGELOG index 1b612a03..f1e6a760 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,9 @@ jc changelog - Update uptime parser to add uptime_days, uptime_hours, uptime_minutes, uptime_total_seconds, time_hour, time_minute, and time_second fields - Update last parser to use new timestamp function +- Update stat parser to add access_time_epoch, access_time_epoch_utc, modify_time_epoch, modify_time_epoch_utc, + change_time_epoch, change_time_epoch_utc, birth_time_epoch, birth_time_epoch_utc fields +- Update timedatectl parser to add epoch_utc field - Add -h option to display the help text. Piping errors no longer show the help text. - Add -v option to display version information. - Make all external python library dependencies optional: pygments, ruamel.yaml, xmltodict diff --git a/EXAMPLES.md b/EXAMPLES.md index 9cad32b7..fad038c4 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -2656,7 +2656,8 @@ timedatectl | jc --timedatectl -p # or: jc -p timedatectl "ntp_enabled": true, "ntp_synchronized": true, "rtc_in_local_tz": false, - "dst_active": true + "dst_active": true, + "epoch_utc": 1583888001 } ``` ### tracepath diff --git a/docs/parsers/timedatectl.md b/docs/parsers/timedatectl.md index 4cd48d31..3b6583c4 100644 --- a/docs/parsers/timedatectl.md +++ b/docs/parsers/timedatectl.md @@ -2,6 +2,8 @@ # jc.parsers.timedatectl jc - JSON CLI output utility `timedatectl` command output parser +The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the universal_time field is available. + Usage (cli): $ timedatectl | jc --timedatectl @@ -30,7 +32,8 @@ Examples: "ntp_enabled": true, "ntp_synchronized": true, "rtc_in_local_tz": false, - "dst_active": true + "dst_active": true, + "epoch_utc": 1583888001 } $ timedatectl | jc --timedatectl -p -r @@ -70,6 +73,7 @@ Returns: { "local_time": string, "universal_time": string, + "epoch_utc": integer, # timezone-aware timestamp "rtc_time": string, "time_zone": string, "ntp_enabled": boolean, diff --git a/jc/parsers/timedatectl.py b/jc/parsers/timedatectl.py index fdb22d6c..438e310c 100644 --- a/jc/parsers/timedatectl.py +++ b/jc/parsers/timedatectl.py @@ -1,5 +1,7 @@ """jc - JSON CLI output utility `timedatectl` command output parser +The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the universal_time field is available. + Usage (cli): $ timedatectl | jc --timedatectl @@ -28,7 +30,8 @@ Examples: "ntp_enabled": true, "ntp_synchronized": true, "rtc_in_local_tz": false, - "dst_active": true + "dst_active": true, + "epoch_utc": 1583888001 } $ timedatectl | jc --timedatectl -p -r @@ -47,7 +50,7 @@ import jc.utils class info(): - version = '1.1' + version = '1.2' description = 'timedatectl status command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -76,6 +79,7 @@ def process(proc_data): { "local_time": string, "universal_time": string, + "epoch_utc": integer, # timezone-aware timestamp "rtc_time": string, "time_zone": string, "ntp_enabled": boolean, @@ -96,6 +100,9 @@ def process(proc_data): except (ValueError): proc_data[key] = None + if 'universal_time' in proc_data: + proc_data['epoch_utc'] = jc.utils.parse_datetime_to_timestamp(proc_data['universal_time'])['timestamp_utc'] + return proc_data diff --git a/jc/utils.py b/jc/utils.py index fc965613..570ec3cf 100644 --- a/jc/utils.py +++ b/jc/utils.py @@ -143,6 +143,7 @@ def parse_datetime_to_timestamp(data): {'id': 7000, 'format': '%a %b %d %H:%M:%S %Z %Y', 'locale': None}, # C locale format (found in date cli): Wed Mar 24 11:11:30 UTC 2021 {'id': 7100, 'format': '%b %d %H:%M:%S %Y', 'locale': None}, # C locale format (found in stat cli output - osx): # Mar 29 11:49:05 2021 {'id': 7200, 'format': '%Y-%m-%d %H:%M:%S.%f %z', 'locale': None}, # C locale format (found in stat cli output - linux): 2019-08-13 18:13:43.555604315 -0400 + {'id': 7300, 'format': '%a %Y-%m-%d %H:%M:%S %Z', 'locale': None}, # C locale format (found in timedatectl cli output): # Wed 2020-03-11 00:53:21 UTC # attempt locale changes last {'id': 8000, 'format': '%a %d %b %Y %H:%M:%S %Z', 'locale': ''}, # current locale format (found in upower cli output): # mar. 23 mars 2021 23:12:11 UTC {'id': 8100, 'format': '%a %d %b %Y %H:%M:%S', 'locale': ''}, # current locale format with non-UTC tz (found in upower cli output): # mar. 23 mars 2021 19:12:11 EDT