summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2020-12-08 17:58:17 +0100
committerJannik Schönartz2020-12-08 17:58:17 +0100
commit1bf662a5aa821699fc4c8fe0e570207bc5d5c044 (patch)
tree8bb231a3e82e0933c2c9504369825bcf955a6ad0
parentChange capture_output to stdout and stderr to add compatebility to python < p... (diff)
downloadsystemd-init-1bf662a5aa821699fc4c8fe0e570207bc5d5c044.tar.gz
systemd-init-1bf662a5aa821699fc4c8fe0e570207bc5d5c044.tar.xz
systemd-init-1bf662a5aa821699fc4c8fe0e570207bc5d5c044.zip
Add fallback for ip and mac addresses
-rwxr-xr-xmodules.d/bas-python/scripts/00collect_hw_info_json.py33
1 files changed, 31 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 8176bdc5..0c14a019 100755
--- a/modules.d/bas-python/scripts/00collect_hw_info_json.py
+++ b/modules.d/bas-python/scripts/00collect_hw_info_json.py
@@ -102,6 +102,34 @@ def get_ip():
result = json.loads(ip_raw)
return result
+def get_net_fallback():
+ result = {}
+
+ # Get MAC address
+ interfaces = run_subprocess('ls /sys/class/net').split('\n')
+ for interface in interfaces:
+ # Skip local stuff
+ if interface == 'lo' or interface == '':
+ continue
+ net = {}
+ net['mac'] = run_subprocess('cat /sys/class/net/' + interface + '/address')
+ result[interface] = net
+
+ # Get IP address
+ interfaces = run_subprocess('ip -o addr show | awk \'/inet/ {print $2, $3, $4}\'').split('\n')
+ for interface in interfaces:
+ if interface == '':
+ continue
+ interf = interface.split(' ')
+ if interf[0] == 'lo':
+ continue
+ else:
+ if interf[1] == 'inet':
+ result[interf[0]]['ipv4'] = interf[2]
+ elif interf[1] == 'inet6':
+ result[interf[0]]['ipv6'] = interf[2]
+ return result
+
# Get and convert EDID data to hex
def get_edid():
edid = []
@@ -122,7 +150,7 @@ def get_lshw():
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)')
@@ -139,7 +167,8 @@ def main():
_collecthw['ip'] = get_ip()
_collecthw['edid'] = get_edid()
_collecthw['lshw'] = get_lshw()
-
+ _collecthw['net'] = get_net_fallback()
+
# Print out the final json
print(json.dumps(_collecthw))