summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2021-01-12 11:07:20 +0100
committerJannik Schönartz2021-01-12 11:07:20 +0100
commit5116dc46d51702389c9dd36c6b04de5ce8a2f01c (patch)
treed17eb227f31a39173ef972506882f91d5d7711b5
parentAdd sending post request and arguments for the location of the client (diff)
downloadsystemd-init-5116dc46d51702389c9dd36c6b04de5ce8a2f01c.tar.gz
systemd-init-5116dc46d51702389c9dd36c6b04de5ce8a2f01c.tar.xz
systemd-init-5116dc46d51702389c9dd36c6b04de5ce8a2f01c.zip
Handle stderr with valid returncode 0 and add paramter for printing the json
-rwxr-xr-xmodules.d/bas-python/scripts/00collect_hw_info_json.py19
1 files changed, 13 insertions, 6 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 8c1d14e8..fc10eb42 100755
--- a/modules.d/bas-python/scripts/00collect_hw_info_json.py
+++ b/modules.d/bas-python/scripts/00collect_hw_info_json.py
@@ -25,10 +25,14 @@ def run_subprocess(_cmd):
print()
# stderr len instead of proc.returncode > 0 is used because some have returncode 2 but are still valid
if len(stderr.decode()) > 0:
- print('Critical Error: ' + str(proc.returncode))
- print('Failed with error: ' + stderr.decode())
- print()
- return False
+ print(_cmd + ' Errors:')
+ print(stderr.decode())
+ if proc.returncode != 0:
+ print('Error Return Code: ' + str(proc.returncode))
+ print()
+ return False
+ else:
+ return stdout.decode()
else:
return stdout.decode()
@@ -177,6 +181,7 @@ 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("POST-Request Response: \n")
print(req.text)
def main():
@@ -185,7 +190,8 @@ def main():
# 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('-u', '--url', action='store', help='If given, a post request with the generated JSON is sent to the given URL')
+ parser.add_argument('-p', '--print', action='store_true', help='Prints the generated JSON')
parser.add_argument('-r', '--rack', action='store', help='<rack>')
parser.add_argument('-s', '--slot', action='store', help='<slot>')
parser.add_argument('-b', '--bay', action='store', help='<bay>')
@@ -211,7 +217,8 @@ def main():
send_post(args.url, _collecthw)
# Print out the final json
- # print(json.dumps(_collecthw))
+ if (args.print):
+ print(json.dumps(_collecthw))
if __name__ == "__main__":
main()