zbx-smartctl icon indicating copy to clipboard operation
zbx-smartctl copied to clipboard

On linux, name disks by ID

Open rkarlsba opened this issue 5 years ago • 8 comments

On linux, name disks by /dev/disk/by-id/xxx instead of /dev/xxx, since the latter may change after a reboot.

rkarlsba avatar Jun 30 '19 13:06 rkarlsba

Thank you for this! Exactly what I needed, constant change of the name is a very annoying issue.

fliker09 avatar Sep 14 '19 12:09 fliker09

If my understanding of regex is correct, ^ata- only searches for ata attached drives (SATA/IDE), as far as I know, SCSI attached drives should use ^scsi-. That is consistent with SCSI and SAS drives. I don't know much about perl, if I would know, I would fix that my self. But maybe @rkarlsba can fix that and send another push request to @v-zhuravlev?

Cheers

  • tschaerni

EDIT: I don't have NVMe drives to test it, but I would think they also have something other than ATA or SCSI, because they use a different protocol as far as I know.

tschaerni avatar Jan 24 '20 02:01 tschaerni

I've tested it with a different regex, to also incorporate SCSI devices, a friend of mine made the regex, just replace it with: /^(?:ata|scsi)\-/ or /^(?:ata-|scsi-)/ both work, but I find the second one a bit more clear ;)

Cheers

  • tschaerni

tschaerni avatar Jan 25 '20 23:01 tschaerni

The code is/was

if ($devlink =~ /^ata-/) {

This can easily be replaced with

if ($devlink =~ /^(ata|scsi)-/) {

Don't know why you'd want ?: in front of that, or escaping -, it's a perfectly valid character in regex unless it's in []

rkarlsba avatar Jan 25 '20 23:01 rkarlsba

I don't know that much about regex, I asked a friend of mine (perl dev with a lot of knowledge about regex) who gave me that regex, and it works after testing it.

btw. there are USB Harddrives with functional S.M.A.R.T, like the WD My Passport series. They identify as for example: usb-WD_My_Passport_25E1_XXXXXXXXXXXXXXXXXXXXXXXX-0:0 so, for USB Attached disks, the regex should also include USB: /^(?:ata-|scsi-|usb-)/

Cheers

  • tschaerni

tschaerni avatar Jan 29 '20 18:01 tschaerni

Sure - all we're waiting for is a pull…

rkarlsba avatar Jan 29 '20 18:01 rkarlsba

@rkarlsba Can you implement the proposed change (/^(?:ata-|scsi-|usb-)/) in this pull request with another commit?

Phlogi avatar Feb 27 '20 13:02 Phlogi

I beleive that should do

rkarlsba avatar Feb 27 '20 19:02 rkarlsba