diff --git a/clever/src/selfcheck.py b/clever/src/selfcheck.py index 36f2ad27..9fb766ca 100755 --- a/clever/src/selfcheck.py +++ b/clever/src/selfcheck.py @@ -9,6 +9,7 @@ # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. +import os import math import subprocess import re @@ -692,9 +693,32 @@ def check_preflight_status(): failure(' '.join([match.groups()[1], 'check:', check_status])) +@check('Network') +def check_network(): + ros_hostname = os.environ.get('ROS_HOSTNAME').strip() + + if not ros_hostname: + failure('No ROS_HOSTNAME is set') + + elif ros_hostname.endswith('.local'): + # using mdns hostname + hosts = open('/etc/hosts', 'r') + for line in hosts: + parts = line.split() + if len(parts) < 2: + continue + ip = parts.pop(0).split('.') + if ip[0] == '127': # loopback ip + if ros_hostname in parts: + break + else: + failure('Not found %s in /etc/hosts, ROS will malfunction if network interfaces are down, https://clever.coex.tech/hostname', ros_hostname) + + def selfcheck(): check_image() check_clever_service() + check_network() check_fcu() check_imu() check_local_position()