Skip to content

hostnamectl output now includes icons #1908

@nvwls

Description

@nvwls

Description

According to gemini:

In RHEL 10 (and other modern systemd-based distributions), the hostnamectl command
has been updated to include visual icons using UTF-8 characters for the Chassis field.

This change is part of the upstream systemd project's effort to make the CLI output more
visually informative for users. Instead of just seeing the word "laptop" or "server," you now
see a corresponding symbol.

This leads to following:

warning: JSON.generate: UTF-8 string passed as BINARY, this will raise an encoding error in json 3.0

The problematic code is:

https://github.com/chef/ohai/blob/main/lib/ohai/plugins/linux/hostnamectl.rb#L28-L31

Proposed Fix

diff --git lib/ohai/plugins/linux/hostnamectl.rb lib/ohai/plugins/linux/hostnamectl.rb
index 8f16e246..b86d7f63 100644
--- lib/ohai/plugins/linux/hostnamectl.rb
+++ lib/ohai/plugins/linux/hostnamectl.rb
@@ -27,6 +27,10 @@ Ohai.plugin(:Hostnamectl) do
     if hostnamectl_path
       shell_out(hostnamectl_path).stdout.split("\n").each do |line|
         key, val = line.split(": ", 2)
+
+        # strip visual icons produced by newer versions of systemd
+        val.gsub!(/ [^[:ascii]]*$/, "")
+
         hostnamectl[key.chomp.lstrip.tr(" ", "_").downcase] = val
       end
     end

Ohai Version

18.2.5

Platform Version

RHEL-10

Ohai Output

[root@dokken /]# hostnamectl | od -c
0000000       S   t   a   t   i   c       h   o   s   t   n   a   m   e
0000020   :       d   o   k   k   e   n  \n
0000040   I   c   o   n       n   a   m   e   :       c   o   m   p   u
0000060   t   e   r   -   c   o   n   t   a   i   n   e   r  \n
0000100                               C   h   a   s   s   i   s   :
0000120   c   o   n   t   a   i   n   e   r     342 230 220  \n
0000140                   M   a   c   h   i   n   e       I   D   :
0000160   8   7   a   0   9   7   9   c   3   d   9   b   4   8   9   d
0000200   b   6   5   8   a   f   f   4   c   5   0   b   4   0   6   6
0000220  \n                                       B   o   o   t       I
0000240   D   :       5   a   1   e   c   b   b   4   c   4   f   6   4
0000260   1   c   2   a   9   e   b   5   5   d   c   b   e   0   b   8
0000300   0   f   b  \n           V   i   r   t   u   a   l   i   z   a
0000320   t   i   o   n   :       d   o   c   k   e   r  \n   O   p   e
0000340   r   a   t   i   n   g       S   y   s   t   e   m   :       C
0000360   e   n   t   O   S       S   t   r   e   a   m       1   0
0000400   (   C   o   u   g   h   l   a   n   )  \n
0000420   C   P   E       O   S       N   a   m   e   :       c   p   e
0000440   :   /   o   :   c   e   n   t   o   s   :   c   e   n   t   o
0000460   s   :   1   0  \n                                           K
0000500   e   r   n   e   l   :       L   i   n   u   x       5   .   1
0000520   4   .   0   -   5   8   5   .   e   l   9   .   x   8   6   _
0000540   6   4  \n                   A   r   c   h   i   t   e   c   t
0000560   u   r   e   :       x   8   6   -   6   4  \n
0000574

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UntriagedAn issue that has yet to be triaged.Type: BugDoes not work as expected.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions