diff options
author | Jannik Schönartz | 2021-09-08 19:24:17 +0200 |
---|---|---|
committer | Jannik Schönartz | 2021-09-08 19:24:17 +0200 |
commit | 5fd9cefcaa79d88e9386307479aa9e99cf674cce (patch) | |
tree | 29d5c6180fd170b3cfe1ef7bcbb6f791d9aeb748 | |
parent | [bas-hw-collect] Use idoit username instead of first-/lastname for contacts (diff) | |
download | systemd-init-5fd9cefcaa79d88e9386307479aa9e99cf674cce.tar.gz systemd-init-5fd9cefcaa79d88e9386307479aa9e99cf674cce.tar.xz systemd-init-5fd9cefcaa79d88e9386307479aa9e99cf674cce.zip |
[bas-hw-collect] Add iommu groups to lspci and add uuid url replace parameter to automatically replace a UUID in an url with the clients uuid
-rwxr-xr-x | modules.d/bas-hw-collect/scripts/collect_hw_info_json.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/modules.d/bas-hw-collect/scripts/collect_hw_info_json.py b/modules.d/bas-hw-collect/scripts/collect_hw_info_json.py index 742c94d5..3d73d0f7 100755 --- a/modules.d/bas-hw-collect/scripts/collect_hw_info_json.py +++ b/modules.d/bas-hw-collect/scripts/collect_hw_info_json.py @@ -109,6 +109,16 @@ def get_disk_info(): def get_lspci(): lspci = [] lspci_raw = run_subprocess('lspci -mmn').split('\n') + + # Prepare addition of iommu group + iommu_raw = run_subprocess('find /sys/kernel/iommu_groups/*/devices/*').split('\n') + iommu_groups = {} + for iommu_path in iommu_raw: + if iommu_path == "": + continue + iommu = iommu_path.split('/') + iommu_groups[iommu[6][5:]] = iommu[4] + for line in lspci_raw: if len(line) <= 0: continue @@ -135,6 +145,10 @@ def get_lspci(): lspci_parsed['subsystem_vendor'] = values[4] lspci_parsed['subsystem'] = values[5] + # Additional add iommu group + if values[0] in iommu_groups: + lspci_parsed['iommu_group'] = iommu_groups[values[0]] + # Prepare arguments if len(arguments) > 0: for arg in arguments: @@ -208,6 +222,10 @@ def get_lshw(): result = json.loads(lshw_raw) return result +def get_uuid(): + uuid = run_subprocess('cat /sys/class/dmi/id/product_uuid') + return uuid.rstrip() + def prepare_location(parent, bay, slot): location = {} if parent: @@ -244,12 +262,13 @@ def main(): parser = argparse.ArgumentParser(description='Collects hardware data from different tools and returns it as json.') parser.add_argument('-d', '--debug', action='store_true', help='Prints all STDERR messages. (Non critical included)') parser.add_argument('-u', '--url', action='append', help='[multiple] If given, a post request with the generated JSON is sent to the given URLs') + parser.add_argument('-uu', '--uuidurl', action='append', help='[multiple] Same as -u but UUID in the url is replaced with the actual uuid of the client') parser.add_argument('-p', '--print', action='store_true', help='Prints the generated JSON') - parser.add_argument('-l', '--location', action='store', help='<location>: Room-/Rackname where the client is located') - parser.add_argument('-s', '--slot', action='store', help='<slot> The slot number (int) where the client is located in the rack') - parser.add_argument('-b', '--bay', action='store', help='<bay> The bay number (int) where the client is located in the slot (segment)') - parser.add_argument('-c', '--contact', action='append', help='[multiple] <idoit_username> of the person responsible for this machine', nargs=1) - parser.add_argument('-n', '--name', action='store', help='<name>: Name of the client') + parser.add_argument('-l', '--location', action='store', help='Room-/Rackname where the client is located') + parser.add_argument('-s', '--slot', action='store', help='The slot number (int) where the client is located in the rack') + parser.add_argument('-b', '--bay', action='store', help='The bay number (int) where the client is located in the slot (segment)') + parser.add_argument('-c', '--contact', action='append', help='[multiple] The idoit_username of the person responsible for this machine', nargs=1) + parser.add_argument('-n', '--name', action='store', help='Name of the client') parser.add_argument('-S', '--SERVER', action='store_true', help='Defines the type of the client to be a server') args = parser.parse_args() @@ -264,11 +283,14 @@ def main(): # Includes smartctl, lsblk, readlink and sfdisk _collecthw['drives'] = get_disk_info() + # Includes iommu group _collecthw['lspci'] = get_lspci() + _collecthw['ip'] = get_ip() _collecthw['edid'] = get_edid() _collecthw['lshw'] = get_lshw() _collecthw['net'] = get_net_fallback() + _collecthw['location'] = prepare_location(args.location, args.bay, args.slot) _collecthw['contacts'] = prepare_contacts(args.contact) @@ -282,6 +304,11 @@ def main(): if args.url: for url in args.url: send_post(url, _collecthw) + if args.uuidurl: + uuid = get_uuid() + for uuidurl in args.uuidurl: + url = uuidurl.replace("UUID", uuid) + send_post(url, _collecthw) # Print out the final json if args.print: |