Analysis to return Chassis type as string

I manage a bunch of Linux systems, servers, laptops, VMs. I need to determine the Chassis type of each system. I’m trying to write an analysis to take the value in /sys/class/dmi/id/chassis_type and then return with a string that tells us the Type. For instance, 1 is Other, 9 is Laptop, 23 is Rack Mount Chassis. I seem to be having problems on reading the value. I’m trying something like

(if it contains "23" then "Chassis" else if it contains "1" then "Other" else "") of file "/sys/class/dmi/id/chassis_type"

but get told The operator "contains" is not defined. Any help?

Would using the SMBIOS inspector yield the same results?

Q: (tuple string item ( (it as string as integer) of values "type" of structures "system_enclosure_or_chassis" of smbios ) of "Unknown, Other, Unknown, Desktop, Low Profile Desktop, Pizza Box, Mini Tower, Tower, Portable, Laptop, Notebook, Hand Held, Docking Station, All in One, Sub Notebook, Space-Saving, Lunch Box, Main System Chassis, Expansion Chassis, SubChassis, Bus Expansion Chassis, Peripheral Chassis, Storage Chassis, Rack Mount Chassis, Sealed-Case PC, Multi-system chassis, CompactPCI, AdvancedTCA, Blade, Blade Enclosure, Tablet, Convertible, Detachable") | ERROR "Unknown"
A: Desktop
T: 296

Almost. It works on a Dell Latitude 5550 and a VM, but a PowerEdge 660 returns User-defined error: Unknown. It seems like Bigfix’s DMI/SMBios is returning the wrong value.

Q: values "type" of structures "system_enclosure_or_chassis" of smbios

A: 151

I would expect it to be a value orf23, which is what the file says

# more /sys/class/dmi/id/chassis_type

23

That intrigued me, and when I spell it out in binary there's a solid relationship between the decimal numbers '151' and '23'.

q: 151 as bits
A: 10010111

q: 23 as bits
A:    10111

These are...the same value, but '151' also has the highest bit (value 128) as 'set' rather than 'cleared'. Otherwise, these are the same.

Sure enough, checking the DMI specification...'chassis_type' is a single byte, but it actually holds two different values. At https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf , see page 1025, at offset 05h:

Offset 05h
Specification Verion: 2.0+
Name: Type
Length: BYTE
Value: Varies
Description:
Bit 7 Chassis lock is present if 1. Otherwise, either a lock is not present, or it is unknown if theenclosure has a lock.

Bits 6:0 Enumeration value; see
below.

So, what does that all mean?
It means that for value 151, this is chassis_type 23 decimal, i.e. 0x17, or 'Rack Mount Chassis'; AND bit 7 is set, so it is 'Locked'.

Give me a few minutes to work on a more generalized form of the relevance to split up that value.

Try this form and see whether it gives the result you expect (you can remove the first item of the tuple if you don't care to check whether it's locked)

q: (if bit 7 of it then "Locked" else "Unlocked|Unknown") of (hexadecimal integer (it as hexadecimal) as bits) of values "type" of structures "system_enclosure_or_chassis" of smbios
A: Unlocked|Unknown
I: plural string

q: (tuple string item ((((it - (128 as bit set)) as integer) of  (hexadecimal integer (it as hexadecimal) as bits)) of values "type" of structures "system_enclosure_or_chassis" of smbios) of "Unknown, Other, Unknown, Desktop, Low Profile Desktop, Pizza Box, Mini Tower, Tower, Portable, Laptop, Notebook, Hand Held, Docking Station, All in One, Sub Notebook, Space-Saving, Lunch Box, Main System Chassis, Expansion Chassis, SubChassis, Bus Expansion Chassis, Peripheral Chassis, Storage Chassis, Rack Mount Chassis, Sealed-Case PC, Multi-system chassis, CompactPCI, AdvancedTCA, Blade, Blade Enclosure, Tablet, Convertible, Detachable") | ERROR "Unknown"
A: Notebook
I: singular string

q: ((if bit 7 of it then "Locked" else "Unlocked|Unknown") of (hexadecimal integer (it as hexadecimal) as bits) of values "type" of structures "system_enclosure_or_chassis" of smbios, (tuple string item ((((it - (128 as bit set)) as integer) of  (hexadecimal integer (it as hexadecimal) as bits)) of values "type" of structures "system_enclosure_or_chassis" of smbios) of "Unknown, Other, Unknown, Desktop, Low Profile Desktop, Pizza Box, Mini Tower, Tower, Portable, Laptop, Notebook, Hand Held, Docking Station, All in One, Sub Notebook, Space-Saving, Lunch Box, Main System Chassis, Expansion Chassis, SubChassis, Bus Expansion Chassis, Peripheral Chassis, Storage Chassis, Rack Mount Chassis, Sealed-Case PC, Multi-system chassis, CompactPCI, AdvancedTCA, Blade, Blade Enclosure, Tablet, Convertible, Detachable") | ERROR "Unknown")
A: Unlocked|Unknown, Notebook
I: plural ( string, string )
2 Likes

Thanks Jason!

That’s giving me exactly what I need.

1 Like