My main storage machine at home has 36 disks. So that I can find which is which, I’ve used my trusty Dymo labeller to print out the serial numbers and have put these labels on the drive bays.
I’m monitoring the temperatures of these with hddtemp, reading this data into Zabbix, and the alerting into Slack/Google Chat, but given that the “/dev/sdX” device names may change between reboots, keeping track of which disk is which can be a bit of a pain, to say the least.

But there is a solution!
After about an hour of trying to get a shell glob to exclude the list of partitions in /dev/disk/by-id, then looking for a way to do that with a systemd service file (which for hddtemp doesn’t exist in Ubuntu) I had a bit of a light-bulb moment.

The config file for hddtemp on Ubuntu lives in /etc/default/hddtemp and the important bit here is at the top of that file:

# Defaults for hddtemp initscript (/etc/init.d/hddtemp)
# This is a POSIX shell fragment

Which means, you can use a shell escape to list your disks!

So for me, this gives us
DISKS=”$(ls /dev/disk/by-id/ata-* | grep -v ‘part’)”

and then the output of the hddtemp daemon would look something like this

sean@storey:/etc/default$ nc localhost 7634
|/dev/disk/by-id/ata-Crucial_CT1050MX300SSD1_16321392ED21|Crucial_CT1050MX300SSD1|38|C||/dev/disk/by-id/ata-Crucial_CT1050MX300SSD1_164514982DDC|Crucial_CT1050MX300SSD1|38|C||/dev/disk/by-id/ata-Crucial_CT1050MX300SSD1_164614AF2D97|Crucial_CT1050MX300SSD1|38|C||/dev/disk/by-id/ata-Crucial_CT1050MX300SSD1_17011543714A|Crucial_CT1050MX300SSD1|38|C||/dev/disk/by-id/ata-SanDisk_SD6SB1M064G1022I_144106402063|SanDisk SD6SB1M064G1022I �|35|C||/dev/disk/by-id/ata-SanDisk_SD6SB1M064G1022I_144106402893|SanDisk SD6SB1M064G1022I �|35|C||/dev/disk/by-id/ata-SanDisk_SDSSDA120G_171334447114|SanDisk SDSSDA120G|43|C||/dev/disk/by-id/ata-SanDisk_SDSSDA120G_171334464203|SanDisk SDSSDA120G|43|C||/dev/disk/by-id/ata-SanDisk_SDSSDA120G_171522463801|SanDisk SDSSDA120G|43|C||/dev/disk/by-id/ata-SanDisk_SDSSDA120G_171548455709|SanDisk SDSSDA120G|45|C||/dev/disk/by-id/ata-SanDisk_SDSSDP064G_144227401653|SanDisk SDSSDP064G|39|C||/dev/disk/by-id/ata-SanDisk_SDSSDP064G_144227402736|SanDisk SDSSDP064G|41|C||/dev/disk/by-id/ata-ST4000DM000-2AE166_WDH0Q5T5|ST4000DM000-2AE166|43|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_S300XV2G|ST4000VN000-1H4168|35|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_W301C0EV|ST4000VN000-1H4168|41|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z301SY2A|ST4000VN000-1H4168|35|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z301SZPK|ST4000VN000-1H4168|34|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z3028038|ST4000VN000-1H4168|34|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z30281M6|ST4000VN000-1H4168|47|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z302G8L8|ST4000VN000-1H4168|48|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z302G8SA|ST4000VN000-1H4168|46|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z302G8SE|ST4000VN000-1H4168|44|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z302SN4E|ST4000VN000-1H4168|46|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z306B1QH|ST4000VN000-1H4168|41|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z306C75E|ST4000VN000-1H4168|39|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z306CCSJ|ST4000VN000-1H4168|37|C||/dev/disk/by-id/ata-ST4000VN000-1H4168_Z306E1CM|ST4000VN000-1H4168|40|C||/dev/disk/by-id/ata-ST4000VN000-2AH166_WDH05LW6|ST4000VN000-2AH166|33|C||/dev/disk/by-id/ata-ST4000VN000-2AH166_ZDH02XCL|ST4000VN000-2AH166|38|C||/dev/disk/by-id/ata-ST4000VN000-2AH166_ZDH02YXJ|ST4000VN000-2AH166|42|C||/dev/disk/by-id/ata-ST4000VN008-2DR166_ZDH4KPRN|ST4000VN008-2DR166|35|C||/dev/disk/by-id/ata-ST4000VN008-2DR166_ZDH4KQ1L|ST4000VN008-2DR166|37|C||/dev/disk/by-id/ata-ST4000VN008-2DR166_ZGY5F6TE|ST4000VN008-2DR166|36|C||/dev/disk/by-id/ata-ST4000VN008-2DR166_ZGY5R71H|ST4000VN008-2DR166|34|C||/dev/disk/by-id/ata-ST4000VN008-2DR166_ZGY5R9VR|ST4000VN008-2DR166|43|C||/dev/disk/by-id/ata-ST4000VN008-2DR166_ZGY64LZ0|ST4000VN008-2DR166|43|C|

Hangouts Chat alert from Zabbix with useful disk identifier

But then to get this into Zabbix with “Template HDD Temperature” you need to change what the disk discovery looks for…

For me this is then:
sean@storey:/etc/zabbix/zabbix_agentd.conf.d$ cat hddtemp.conf
# Make sure to execute “sudo chmod u+s /usr/sbin/hddtemp” so that any user can run hddtemp, including Zabbix
UserParameter=hddtemp.diskdiscovery,for disk in $(ls /dev/disk/by-id/ata-* | grep -v ‘part’ | cut -d/ -f5); do list=”$list,”‘{“{#DISK}”:”‘$disk'”}’; done; echo ‘{“data”:[‘${list#,}’]}’
UserParameter=hddtemp[*],hddtemp -n /dev/disk/by-id/$1

Actually, to be honest, the second part isn’t dependent upon the first, but it’s good to be consistent!