File tree Expand file tree Collapse file tree 4 files changed +21
-6
lines changed
diagnostic_common_diagnostics/diagnostic_common_diagnostics Expand file tree Collapse file tree 4 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,11 @@ def main(args=None):
9292
9393 # Create the node
9494 hostname = socket .gethostname ()
95- node = Node (f'cpu_monitor_{ hostname .replace ("-" , "_" )} ' )
95+ # Every invalid symbol is replaced by underscore.
96+ # isalnum() alone also allows invalid symbols depending on the locale
97+ cleaned_hostname = '' .join (
98+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
99+ node = Node (f'cpu_monitor_{ cleaned_hostname } ' )
96100
97101 # Declare and get parameters
98102 node .declare_parameter ('warning_percentage' , 90 )
Original file line number Diff line number Diff line change @@ -74,8 +74,12 @@ class HDMonitor(Node):
7474 """
7575
7676 def __init__ (self ):
77- hostname = gethostname ().replace ('.' , '_' ).replace ('-' , '_' )
78- super ().__init__ (f'hd_monitor_{ hostname } ' )
77+ hostname = gethostname ()
78+ # Every invalid symbol is replaced by underscore.
79+ # isalnum() alone also allows invalid symbols depending on the locale
80+ cleaned_hostname = '' .join (
81+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
82+ super ().__init__ (f'hd_monitor_{ cleaned_hostname } ' )
7983
8084 self ._path = '~'
8185 self ._free_percent_low = 0.05
Original file line number Diff line number Diff line change @@ -72,8 +72,12 @@ def run(self, stat):
7272
7373def main ():
7474 hostname = socket .gethostname ()
75+ # Every invalid symbol is replaced by underscore.
76+ # isalnum() alone also allows invalid symbols depending on the locale
77+ cleaned_hostname = '' .join (
78+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
7579 rclpy .init ()
76- node = rclpy .create_node (f'ram_monitor_{ hostname . replace ( "-" , "_" ) } ' )
80+ node = rclpy .create_node (f'ram_monitor_{ cleaned_hostname } ' )
7781
7882 updater = Updater (node )
7983 updater .setHardwareID (hostname )
Original file line number Diff line number Diff line change @@ -245,8 +245,11 @@ def monitor(self, stat):
245245if __name__ == '__main__' :
246246 rclpy .init ()
247247 hostname = socket .gethostname ()
248- hostname_clean = hostname .translate (hostname .maketrans ('-' , '_' ))
249- node = rclpy .create_node ('sensors_monitor_%s' % hostname_clean )
248+ # Every invalid symbol is replaced by underscore.
249+ # isalnum() alone also allows invalid symbols depending on the locale
250+ cleaned_hostname = '' .join (
251+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
252+ node = rclpy .create_node ('sensors_monitor_%s' % cleaned_hostname )
250253
251254 monitor = SensorsMonitor (node , hostname )
252255 try :
You can’t perform that action at this time.
0 commit comments