Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common_diagnostics cleaned hostname string #405

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def main(args=None):

# Create the node
hostname = socket.gethostname()
node = Node(f'cpu_monitor_{hostname.replace("-", "_")}')
# Every invalid symbol is replaced by underscore.
# isalnum() alone also allows invalid symbols depending on the locale
cleaned_hostname = ''.join(
c if (c.isascii() and c.isalnum()) else '_' for c in hostname)
node = Node(f'cpu_monitor_{cleaned_hostname}')

# Declare and get parameters
node.declare_parameter('warning_percentage', 90)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ class HDMonitor(Node):
"""

def __init__(self):
hostname = gethostname().replace('.', '_').replace('-', '_')
super().__init__(f'hd_monitor_{hostname}')
hostname = gethostname()
# Every invalid symbol is replaced by underscore.
# isalnum() alone also allows invalid symbols depending on the locale
cleaned_hostname = ''.join(
c if (c.isascii() and c.isalnum()) else '_' for c in hostname)
super().__init__(f'hd_monitor_{cleaned_hostname}')

self._path = '~'
self._free_percent_low = 0.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ def run(self, stat):

def main():
hostname = socket.gethostname()
# Every invalid symbol is replaced by underscore.
# isalnum() alone also allows invalid symbols depending on the locale
cleaned_hostname = ''.join(
c if (c.isascii() and c.isalnum()) else '_' for c in hostname)
rclpy.init()
node = rclpy.create_node(f'ram_monitor_{hostname.replace("-", "_")}')
node = rclpy.create_node(f'ram_monitor_{cleaned_hostname}')

updater = Updater(node)
updater.setHardwareID(hostname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ def monitor(self, stat):
if __name__ == '__main__':
rclpy.init()
hostname = socket.gethostname()
hostname_clean = hostname.translate(hostname.maketrans('-', '_'))
node = rclpy.create_node('sensors_monitor_%s' % hostname_clean)
# Every invalid symbol is replaced by underscore.
# isalnum() alone also allows invalid symbols depending on the locale
cleaned_hostname = ''.join(
c if (c.isascii() and c.isalnum()) else '_' for c in hostname)
node = rclpy.create_node('sensors_monitor_%s' % cleaned_hostname)

monitor = SensorsMonitor(node, hostname)
try:
Expand Down
Loading