hostnamectl output now includes icons
Open
Nobody has claimed this yet.
Status: Untriaged
Type: Bug
- Dominant language
- Ruby
- Stars
- 690
- Forks
- 446
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 4
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect lib/ohai/plugins/linux/hostnamectl.rb, especially the parsing around lines 28-31. Reproduce the hostnamectl output containing a UTF-8 chassis icon on RHEL 10 and verify that the resulting Ohai data can be passed to JSON.generate without the encoding warning. Confirm that ordinary hostnamectl fields remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, ruby
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100