diff --git a/jc/parsers/systeminfo.py b/jc/parsers/systeminfo.py index 4dac9ff0..1ec1a7da 100644 --- a/jc/parsers/systeminfo.py +++ b/jc/parsers/systeminfo.py @@ -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 diff --git a/tests/fixtures/windows/windows-10/systeminfo.json b/tests/fixtures/windows/windows-10/systeminfo.json index daa5a62f..385c2858 100644 --- a/tests/fixtures/windows/windows-10/systeminfo.json +++ b/tests/fixtures/windows/windows-10/systeminfo.json @@ -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." } diff --git a/tests/fixtures/windows/windows-7/systeminfo.json b/tests/fixtures/windows/windows-7/systeminfo.json index 78c264c0..04d2b8ab 100644 --- a/tests/fixtures/windows/windows-7/systeminfo.json +++ b/tests/fixtures/windows/windows-7/systeminfo.json @@ -13,7 +13,7 @@ "system_manufacturer": "LENOVO", "system_model": "11111AA", "system_type": "x64-based PC", - "processors": "1 Processor(s) Installed.\n [01]: Intel64 Family 6 Model 42 Stepping 7 GenuineIntel ~2501 Mhz", + "processors": ["Intel64 Family 6 Model 42 Stepping 7 GenuineIntel ~2501 Mhz"], "bios_version": "LENOVO 83ET67WW (1.37 ), 11/28/2011", "windows_directory": "C:\\Windows", "system_directory": "C:\\Windows\\system32", @@ -29,6 +29,6 @@ "page_file_locations": "C:\\pagefile.sys", "domain": "WORKGROUP", "logon_server": "\\\\TEST", - "hotfixs": "302 Hotfix(s) Installed.\n [01]: KB2849697\n [02]: KB2849696\n [03]: KB2841134\n [04]: KB2670838\n [05]: KB2830477\n [06]: KB2592687\n [07]: KB971033\n [08]: KB2479943\n [09]: KB2491683\n [10]: KB2506014\n [11]: KB2506212\n [12]: KB2506928\n [13]: KB2509553\n [14]: KB2511455\n [15]: KB2515325\n [16]: KB2532531\n [17]: KB2533552\n [18]: KB2533623\n [19]: KB2534366\n [20]: KB2536275\n [21]: KB2536276\n [22]: KB2544893\n [23]: KB2545698\n [24]: KB2547666\n [25]: KB2552343\n [26]: KB2560656\n [27]: KB2562937\n [28]: KB2563227\n [29]: KB2564958\n [30]: KB2570947\n [31]: KB2574819\n [32]: KB2579686\n [33]: KB2585542\n [34]: KB2603229\n [35]: KB2604115\n [36]: KB2619339\n [37]: KB2620704\n [38]: KB2621440\n [39]: KB2631813\n [40]: KB2639308\n [41]: KB2640148\n [42]: KB2647753\n [43]: KB2653956\n [44]: KB2654428\n [45]: KB2656356\n [46]: KB2660075\n [47]: KB2667402\n [48]: KB2676562\n [49]: KB2685811\n [50]: KB2685813\n [51]: KB2685939\n [52]: KB2690533\n [53]: KB2698365\n [54]: KB2705219\n [55]: KB2706045\n [56]: KB2709630\n [57]: KB2712808\n [58]: KB2718704\n [59]: KB2719857\n [60]: KB2726535\n [61]: KB2727528\n [62]: KB2729094\n [63]: KB2729452\n [64]: KB2731771\n [65]: KB2732059\n [66]: KB2732487\n [67]: KB2732500\n [68]: KB2736422\n [69]: KB2742599\n [70]: KB2750841\n [71]: KB2758857\n [72]: KB2761217\n [73]: KB2763523\n [74]: KB2770660\n [75]: KB2773072\n [76]: KB2786081\n [77]: KB2789645\n [78]: KB2791765\n [79]: KB2798162\n [80]: KB2799926\n [81]: KB2800095\n [82]: KB2803821\n [83]: KB2807986\n [84]: KB2808679\n [85]: KB2813347\n [86]: KB2813430\n [87]: KB2820331\n [88]: KB2832414\n [89]: KB2834140\n [90]: KB2836942\n [91]: KB2836943\n [92]: KB2839894\n [93]: KB2840149\n [94]: KB2840631\n [95]: KB2843630\n [96]: KB2846960\n [97]: KB2847077\n [98]: KB2847311\n [99]: KB2847927\n [100]: KB2852386\n [101]: KB2853952\n [102]: KB2855844\n [103]: KB2857650\n [104]: KB2861191\n [105]: KB2861698\n [106]: KB2862152\n [107]: KB2862330\n [108]: KB2862335\n [109]: KB2862966\n [110]: KB2862973\n [111]: KB2864058\n [112]: KB2864202\n [113]: KB2868038\n [114]: KB2868116\n [115]: KB2868626\n [116]: KB2871997\n [117]: KB2872339\n [118]: KB2882822\n [119]: KB2884256\n [120]: KB2887069\n [121]: KB2888049\n [122]: KB2891804\n [123]: KB2892074\n [124]: KB2893294\n [125]: KB2893519\n [126]: KB2894844\n [127]: KB2900986\n [128]: KB2908783\n [129]: KB2911501\n [130]: KB2912390\n [131]: KB2913152\n [132]: KB2918077\n [133]: KB2918614\n [134]: KB2919469\n [135]: KB2922229\n [136]: KB2923545\n [137]: KB2926765\n [138]: KB2928562\n [139]: KB2929733\n [140]: KB2931356\n [141]: KB2937610\n [142]: KB2939576\n [143]: KB2943357\n [144]: KB2952664\n [145]: KB2957189\n [146]: KB2957503\n [147]: KB2957509\n [148]: KB2961072\n [149]: KB2965788\n [150]: KB2966583\n [151]: KB2968294\n [152]: KB2970228\n [153]: KB2971850\n [154]: KB2972100\n [155]: KB2972211\n [156]: KB2972280\n [157]: KB2973112\n [158]: KB2973201\n [159]: KB2973351\n [160]: KB2976627\n [161]: KB2976897\n [162]: KB2977292\n [163]: KB2977728\n [164]: KB2978092\n [165]: KB2978120\n [166]: KB2978668\n [167]: KB2978742\n [168]: KB2979570\n [169]: KB2980245\n [170]: KB2984972\n [171]: KB2984976\n [172]: KB2984981\n [173]: KB2985461\n [174]: KB2991963\n [175]: KB2992611\n [176]: KB2993651\n [177]: KB2993958\n [178]: KB2994023\n [179]: KB2999226\n [180]: KB3001554\n [181]: KB3002885\n [182]: KB3003057\n [183]: KB3003743\n [184]: KB3004361\n [185]: KB3004375\n [186]: KB3005607\n [187]: KB3006121\n [188]: KB3006226\n [189]: KB3006625\n [190]: KB3008627\n [191]: KB3008923\n [192]: KB3009736\n [193]: KB3010788\n [194]: KB3011780\n [195]: KB3012176\n [196]: KB3013126\n [197]: KB3013410\n [198]: KB3014406\n [199]: KB3019215\n [200]: KB3020369\n [201]: KB3020388\n [202]: KB3021674\n [203]: KB3022777\n [204]: KB3023215\n [205]: KB3025390\n [206]: KB3030377\n [207]: KB3031432\n [208]: KB3032655\n [209]: KB3033889\n [210]: KB3033890\n [211]: KB3033929\n [212]: KB3035126\n [213]: KB3035132\n [214]: KB3037574\n [215]: KB3042058\n [216]: KB3042553\n [217]: KB3045685\n [218]: KB3046017\n [219]: KB3046269\n [220]: KB3055642\n [221]: KB3059317\n [222]: KB3060716\n [223]: KB3061518\n [224]: KB3067903\n [225]: KB3069114\n [226]: KB3069392\n [227]: KB3069762\n [228]: KB3071756\n [229]: KB3072305\n [230]: KB3072630\n [231]: KB3072633\n [232]: KB3074543\n [233]: KB3075226\n [234]: KB3076895\n [235]: KB3076949\n [236]: KB3077715\n [237]: KB3078601\n [238]: KB3080446\n [239]: KB3081320\n [240]: KB3083710\n [241]: KB3084135\n [242]: KB3086255\n [243]: KB3087039\n [244]: KB3087918\n [245]: KB3088195\n [246]", + "hotfixs": ["KB2849697", "KB2849696", "KB2841134", "KB2670838", "KB2830477", "KB2592687", "KB971033", "KB2479943", "KB2491683", "KB2506014", "KB2506212", "KB2506928", "KB2509553", "KB2511455", "KB2515325", "KB2532531", "KB2533552", "KB2533623", "KB2534366", "KB2536275", "KB2536276", "KB2544893", "KB2545698", "KB2547666", "KB2552343", "KB2560656", "KB2562937", "KB2563227", "KB2564958", "KB2570947", "KB2574819", "KB2579686", "KB2585542", "KB2603229", "KB2604115", "KB2619339", "KB2620704", "KB2621440", "KB2631813", "KB2639308", "KB2640148", "KB2647753", "KB2653956", "KB2654428", "KB2656356", "KB2660075", "KB2667402", "KB2676562", "KB2685811", "KB2685813", "KB2685939", "KB2690533", "KB2698365", "KB2705219", "KB2706045", "KB2709630", "KB2712808", "KB2718704", "KB2719857", "KB2726535", "KB2727528", "KB2729094", "KB2729452", "KB2731771", "KB2732059", "KB2732487", "KB2732500", "KB2736422", "KB2742599", "KB2750841", "KB2758857", "KB2761217", "KB2763523", "KB2770660", "KB2773072", "KB2786081", "KB2789645", "KB2791765", "KB2798162", "KB2799926", "KB2800095", "KB2803821", "KB2807986", "KB2808679", "KB2813347", "KB2813430", "KB2820331", "KB2832414", "KB2834140", "KB2836942", "KB2836943", "KB2839894", "KB2840149", "KB2840631", "KB2843630", "KB2846960", "KB2847077", "KB2847311", "KB2847927", "KB2852386", "KB2853952", "KB2855844", "KB2857650", "KB2861191", "KB2861698", "KB2862152", "KB2862330", "KB2862335", "KB2862966", "KB2862973", "KB2864058", "KB2864202", "KB2868038", "KB2868116", "KB2868626", "KB2871997", "KB2872339", "KB2882822", "KB2884256", "KB2887069", "KB2888049", "KB2891804", "KB2892074", "KB2893294", "KB2893519", "KB2894844", "KB2900986", "KB2908783", "KB2911501", "KB2912390", "KB2913152", "KB2918077", "KB2918614", "KB2919469", "KB2922229", "KB2923545", "KB2926765", "KB2928562", "KB2929733", "KB2931356", "KB2937610", "KB2939576", "KB2943357", "KB2952664", "KB2957189", "KB2957503", "KB2957509", "KB2961072", "KB2965788", "KB2966583", "KB2968294", "KB2970228", "KB2971850", "KB2972100", "KB2972211", "KB2972280", "KB2973112", "KB2973201", "KB2973351", "KB2976627", "KB2976897", "KB2977292", "KB2977728", "KB2978092", "KB2978120", "KB2978668", "KB2978742", "KB2979570", "KB2980245", "KB2984972", "KB2984976", "KB2984981", "KB2985461", "KB2991963", "KB2992611", "KB2993651", "KB2993958", "KB2994023", "KB2999226", "KB3001554", "KB3002885", "KB3003057", "KB3003743", "KB3004361", "KB3004375", "KB3005607", "KB3006121", "KB3006226", "KB3006625", "KB3008627", "KB3008923", "KB3009736", "KB3010788", "KB3011780", "KB3012176", "KB3013126", "KB3013410", "KB3014406", "KB3019215", "KB3020369", "KB3020388", "KB3021674", "KB3022777", "KB3023215", "KB3025390", "KB3030377", "KB3031432", "KB3032655", "KB3033889", "KB3033890", "KB3033929", "KB3035126", "KB3035132", "KB3037574", "KB3042058", "KB3042553", "KB3045685", "KB3046017", "KB3046269", "KB3055642", "KB3059317", "KB3060716", "KB3061518", "KB3067903", "KB3069114", "KB3069392", "KB3069762", "KB3071756", "KB3072305", "KB3072630", "KB3072633", "KB3074543", "KB3075226", "KB3076895", "KB3076949", "KB3077715", "KB3078601", "KB3080446", "KB3081320", "KB3083710", "KB3084135", "KB3086255", "KB3087039", "KB3087918", "KB3088195"], "network_cards": "5 NIC(s) Installed.\n [01]: Bluetooth Device (Personal Area Network)\n Connection Name: Bluetooth Network Connection\n Status: Media disconnected\n [02]: Intel(R) 82579LM Gigabit Network Connection\n Connection Name: Local Area Connection\n Status: Media disconnected\n [03]: Intel(R) Centrino(R) Advanced-N 6205\n Connection Name: Wireless Network Connection\n DHCP Enabled: Yes\n DHCP Server: 192.168.2.1\n IP address(es)\n [01]: 192.168.2.2\n [04]: Microsoft Virtual WiFi Miniport Adapter\n Connection Name: Wireless Network Connection 2\n Status: Hardware not present\n [05]: Microsoft Virtual WiFi Miniport Adapter\n Connection Name: Wireless Network Connection 3\n Status: Hardware not present" }