summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2021-01-12 10:18:59 +0100
committerJannik Schönartz2021-01-12 10:18:59 +0100
commita7cc1461a94f909224129b018814d1836a91cf25 (patch)
tree2f6636331553d35172a83578d242d24c1f93a975
parentRemove endl from mac and catch error if scmartctl version < 7 (diff)
downloadsystemd-init-a7cc1461a94f909224129b018814d1836a91cf25.tar.gz
systemd-init-a7cc1461a94f909224129b018814d1836a91cf25.tar.xz
systemd-init-a7cc1461a94f909224129b018814d1836a91cf25.zip
Add sending post request and arguments for the location of the client
-rwxr-xr-xmodules.d/bas-python/scripts/00collect_hw_info_json.py37
1 files 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='<rack>')
+ parser.add_argument('-s', '--slot', action='store', help='<slot>')
+ parser.add_argument('-b', '--bay', action='store', help='<bay>')
+ parser.add_argument('-l', '--location', action='store', help='<location>: 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()