1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-25 00:37:31 +02:00

Add parsing of processors/hotfixs

This commit is contained in:
Jon Smith
2021-04-05 09:29:42 -05:00
parent 89a88e186e
commit 660c59129c
3 changed files with 41 additions and 9 deletions

View File

@ -146,7 +146,7 @@ def parse(data, raw=False, quiet=False):
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
delim = ":" # k/v delimiter
delim = ":" # k/v delimiter
raw_data = {} # intermediary output
if jc.utils.has_data(data):
@ -177,17 +177,20 @@ def parse(data, raw=False, quiet=False):
raw_output = {}
for k, v in raw_data.items():
# lowercase and replace spaces with underscores
k = k.strip().lower().replace(' ', '_')
k = k.strip().lower().replace(" ", "_")
# remove invalid key characters
for c in ';:!@#$%^&*()-':
k = k.replace(c, '')
for c in ";:!@#$%^&*()-":
k = k.replace(c, "")
# since we split on start_value_pos, the delimiter
# is still in the key field. Remove it.
k = k.rstrip(delim)
raw_output[k] = v.strip()
if k in ["hotfixs", "processors"]:
raw_output[k] = parse_hotfixs_or_processors(v)
else:
raw_output[k] = v.strip()
if raw:
return raw_output
@ -195,6 +198,35 @@ def parse(data, raw=False, quiet=False):
return process(raw_output)
def parse_hotfixs_or_processors(data):
"""
Turns a list of return-delimited hotfixes or processors
with [x] as a prefix into an array of hotfixes
Note that if a high number of items exist, the list may cutoff
and this list may not contain all items installed on the system
IRL, this likely applies to hotfixes more than processors
Parameters:
data: (string) Input string
"""
arr_output = []
for i, l in enumerate(data.splitlines()):
# skip line that says how many are installed
if i == 0:
continue
# we have to make sure this is a complete line
# as data could cutoff. Make sure the delimiter
# exists. Otherwise, skip it.
if ":" in l:
k, v = l.split(":")
# discard the number sequence
arr_output.append(v.strip())
return arr_output
def get_value_pos(line, delim):
"""
Finds the first non-whitespace character after the delimiter

View File

@ -13,7 +13,7 @@
"system_manufacturer": "VMware, Inc.",
"system_model": "VMware7,1",
"system_type": "x64-based PC",
"processors": "1 Processor(s) Installed.\n [01]: Intel64 Family 6 Model 158 Stepping 13 GenuineIntel ~2400 Mhz",
"processors": ["Intel64 Family 6 Model 158 Stepping 13 GenuineIntel ~2400 Mhz"],
"bios_version": "VMware, Inc. VMW71.00V.11111111.B64.2008100111, 8/10/2020",
"windows_directory": "C:\\Windows",
"system_directory": "C:\\Windows\\system32",
@ -29,7 +29,7 @@
"page_file_locations": "C:\\pagefile.sys",
"domain": "TEST.local",
"logon_server": "\\\\WIN-AA1A1A11AAA",
"hotfixs": "6 Hotfix(s) Installed.\n [01]: KB4578968\n [02]: KB4562830\n [03]: KB4570334\n [04]: KB4580325\n [05]: KB4586864\n [06]: KB4594440",
"hotfixs": ["KB4578968", "KB4562830", "KB4570334", "KB4580325", "KB4586864", "KB4594440"],
"network_cards": "1 NIC(s) Installed.\n [01]: Intel(R) 82574L Gigabit Network Connection\n Connection Name: Ethernet0\n DHCP Enabled: Yes\n DHCP Server: 192.168.133.250\n IP address(es)\n [01]: 192.168.133.3\n [02]: fe80::192:eb64:1fcf:86eb",
"hyperv_requirements": "A hypervisor has been detected. Features required for Hyper-V will not be displayed."
}

File diff suppressed because one or more lines are too long