From a7cc1461a94f909224129b018814d1836a91cf25 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 12 Jan 2021 10:18:59 +0100 Subject: Add sending post request and arguments for the location of the client --- .../bas-python/scripts/00collect_hw_info_json.py | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/modules.d/bas-python/scripts/00collect_hw_info_json.py b/modules.d/bas-python/scripts/00collect_hw_info_json.py index c22e5f36..8c1d14e8 100755 --- a/modules.d/bas-python/scripts/00collect_hw_info_json.py +++ b/modules.d/bas-python/scripts/00collect_hw_info_json.py @@ -6,6 +6,7 @@ import shlex import sys import argparse from os import listdir +import requests __debug = False @@ -141,7 +142,11 @@ def get_net_fallback(): # Get and convert EDID data to hex def get_edid(): edid = [] - display_paths = run_subprocess('ls /sys/class/drm/*/edid').split('\n') + display_paths = run_subprocess('ls /sys/class/drm/*/edid') + if display_paths: + display_paths = display_paths.split('\n') + else: + return edid for dp in display_paths: if dp == '': continue edid_hex = open(dp, 'rb').read().hex() @@ -156,12 +161,35 @@ def get_lshw(): result = json.loads(lshw_raw) return result +def prepare_location(parent, rack, bay, slot): + location = {} + if parent: + location['parent'] = parent + if rack: + location['rack'] = rack + if bay: + location['bay'] = bay + if slot: + location['slot'] = slot + return location + +def send_post(url, payload): + headers = { 'Content-type': 'application/json', 'Accept': 'text/plain' } + # req = requests.post(url, json=payload, headers=headers) + req = requests.post(url, json=payload) + print(req.text) + def main(): global __debug # Create and parse arguments 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='store', help='If given, a post request is sent to the given URL') + parser.add_argument('-r', '--rack', action='store', help='') + parser.add_argument('-s', '--slot', action='store', help='') + parser.add_argument('-b', '--bay', action='store', help='') + parser.add_argument('-l', '--location', action='store', help=': Roomname where the client is located') args = parser.parse_args() if args.debug: @@ -176,9 +204,14 @@ def main(): _collecthw['edid'] = get_edid() _collecthw['lshw'] = get_lshw() _collecthw['net'] = get_net_fallback() + _collecthw['location'] = prepare_location(args.location, args.rack, args.bay, args.slot) + + collecthw_json = json.dumps(_collecthw) + if (args.url): + send_post(args.url, _collecthw) # Print out the final json - print(json.dumps(_collecthw)) + # print(json.dumps(_collecthw)) if __name__ == "__main__": main() -- cgit v1.2.3-55-g7522