1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

add epoch_utc field to timedatectl parser

This commit is contained in:
Kelly Brazil
2021-03-29 21:16:40 -07:00
parent 3c96bc3196
commit daec4ab0a7
5 changed files with 20 additions and 4 deletions

View File

@ -11,6 +11,9 @@ jc changelog
- Update uptime parser to add uptime_days, uptime_hours, uptime_minutes, uptime_total_seconds, time_hour, - Update uptime parser to add uptime_days, uptime_hours, uptime_minutes, uptime_total_seconds, time_hour,
time_minute, and time_second fields time_minute, and time_second fields
- Update last parser to use new timestamp function - 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 -h option to display the help text. Piping errors no longer show the help text.
- Add -v option to display version information. - Add -v option to display version information.
- Make all external python library dependencies optional: pygments, ruamel.yaml, xmltodict - Make all external python library dependencies optional: pygments, ruamel.yaml, xmltodict

View File

@ -2656,7 +2656,8 @@ timedatectl | jc --timedatectl -p # or: jc -p timedatectl
"ntp_enabled": true, "ntp_enabled": true,
"ntp_synchronized": true, "ntp_synchronized": true,
"rtc_in_local_tz": false, "rtc_in_local_tz": false,
"dst_active": true "dst_active": true,
"epoch_utc": 1583888001
} }
``` ```
### tracepath ### tracepath

View File

@ -2,6 +2,8 @@
# jc.parsers.timedatectl # jc.parsers.timedatectl
jc - JSON CLI output utility `timedatectl` command output parser 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): Usage (cli):
$ timedatectl | jc --timedatectl $ timedatectl | jc --timedatectl
@ -30,7 +32,8 @@ Examples:
"ntp_enabled": true, "ntp_enabled": true,
"ntp_synchronized": true, "ntp_synchronized": true,
"rtc_in_local_tz": false, "rtc_in_local_tz": false,
"dst_active": true "dst_active": true,
"epoch_utc": 1583888001
} }
$ timedatectl | jc --timedatectl -p -r $ timedatectl | jc --timedatectl -p -r
@ -70,6 +73,7 @@ Returns:
{ {
"local_time": string, "local_time": string,
"universal_time": string, "universal_time": string,
"epoch_utc": integer, # timezone-aware timestamp
"rtc_time": string, "rtc_time": string,
"time_zone": string, "time_zone": string,
"ntp_enabled": boolean, "ntp_enabled": boolean,

View File

@ -1,5 +1,7 @@
"""jc - JSON CLI output utility `timedatectl` command output parser """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): Usage (cli):
$ timedatectl | jc --timedatectl $ timedatectl | jc --timedatectl
@ -28,7 +30,8 @@ Examples:
"ntp_enabled": true, "ntp_enabled": true,
"ntp_synchronized": true, "ntp_synchronized": true,
"rtc_in_local_tz": false, "rtc_in_local_tz": false,
"dst_active": true "dst_active": true,
"epoch_utc": 1583888001
} }
$ timedatectl | jc --timedatectl -p -r $ timedatectl | jc --timedatectl -p -r
@ -47,7 +50,7 @@ import jc.utils
class info(): class info():
version = '1.1' version = '1.2'
description = 'timedatectl status command parser' description = 'timedatectl status command parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -76,6 +79,7 @@ def process(proc_data):
{ {
"local_time": string, "local_time": string,
"universal_time": string, "universal_time": string,
"epoch_utc": integer, # timezone-aware timestamp
"rtc_time": string, "rtc_time": string,
"time_zone": string, "time_zone": string,
"ntp_enabled": boolean, "ntp_enabled": boolean,
@ -96,6 +100,9 @@ def process(proc_data):
except (ValueError): except (ValueError):
proc_data[key] = None 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 return proc_data

View File

@ -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': 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': 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': 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 # 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': 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 {'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