Empty volume name on Windows results in an empty by_device key
Description
#1419 set the device name for filesystem/filesystem2 to the drive volume name, which is optional. If you don't have a volume name set you can end up with:
node["filesystem"]["by_device"][""]["volume_name"] == ""
The value for volume_name being empty is fine, but the key being empty causes indexing errors with Elasticsearch. Probably world-ending things would happen as well if you had two drives without volume names.
Could not index event to Elasticsearch. {:status=>400, :action=>["index
", {:_id=>nil, :_index=>"chef-automate2-18.05.2020", :routing=>nil, :_type=>"_doc"}, #<LogStash::Event:0x218c2509>], :response=>{"index"=>{"_i
ndex"=>"chef-automate2-18.05.2020", "_type"=>"_doc", "_id"=>"gm9-J3IB1wrHbrNo-k9j", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception
", "reason"=>"failed to parse", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"field name cannot be an empty string"}}}}}

Fix?
We don't collect any actual device data for disks on Windows, maybe this is where we should. We can get disk information from Win32_DiskDrive and use Win32_LogicalDiskToPartition to map that to some drive letters.
Win32_DiskDrive
[#<WmiLite::Wmi::Instance:0x0000000005506a68
@property_map=
{"availability"=>nil,
"bytespersector"=>512,
"capabilities"=>[3, 4],
"capabilitydescriptions"=>["Random Access", "Supports Writing"],
"caption"=>"Microsoft Virtual Disk",
"compressionmethod"=>nil,
"configmanagererrorcode"=>0,
"configmanageruserconfig"=>false,
"creationclassname"=>"Win32_DiskDrive",
"defaultblocksize"=>nil,
"description"=>"Disk drive",
"deviceid"=>"\\\\.\\PHYSICALDRIVE1",
"errorcleared"=>nil,
"errordescription"=>nil,
"errormethodology"=>nil,
"firmwarerevision"=>"1.0 ",
"index"=>1,
"installdate"=>nil,
"interfacetype"=>"SCSI",
"lasterrorcode"=>nil,
"manufacturer"=>"(Standard disk drives)",
"maxblocksize"=>nil,
"maxmediasize"=>nil,
"medialoaded"=>true,
"mediatype"=>"Fixed hard disk media",
"minblocksize"=>nil,
"model"=>"Microsoft Virtual Disk",
"name"=>"\\\\.\\PHYSICALDRIVE1",
"needscleaning"=>nil,
"numberofmediasupported"=>nil,
"partitions"=>1,
"pnpdeviceid"=>"SCSI\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\000001",
"powermanagementcapabilities"=>nil,
"powermanagementsupported"=>nil,
"scsibus"=>0,
"scsilogicalunit"=>1,
"scsiport"=>0,
"scsitargetid"=>0,
"sectorspertrack"=>63,
"serialnumber"=>nil,
"signature"=>772835539,
"size"=>"15027586560",
"status"=>"OK",
"statusinfo"=>nil,
"systemcreationclassname"=>"Win32_ComputerSystem",
"systemname"=>"btm-win10",
"totalcylinders"=>"1827",
"totalheads"=>255,
"totalsectors"=>"29350755",
"totaltracks"=>"465885",
"trackspercylinder"=>255},
@wmi_ole_object=#<WIN32OLE:0x0000000005506a90>>,
#<WmiLite::Wmi::Instance:0x0000000005517570
@property_map=
{"availability"=>nil,
"bytespersector"=>512,
"capabilities"=>[3, 4],
"capabilitydescriptions"=>["Random Access", "Supports Writing"],
"caption"=>"Microsoft Virtual Disk",
"compressionmethod"=>nil,
"configmanagererrorcode"=>0,
"configmanageruserconfig"=>false,
"creationclassname"=>"Win32_DiskDrive",
"defaultblocksize"=>nil,
"description"=>"Disk drive",
"deviceid"=>"\\\\.\\PHYSICALDRIVE0",
"errorcleared"=>nil,
"errordescription"=>nil,
"errormethodology"=>nil,
"firmwarerevision"=>"1.0 ",
"index"=>0,
"installdate"=>nil,
"interfacetype"=>"SCSI",
"lasterrorcode"=>nil,
"manufacturer"=>"(Standard disk drives)",
"maxblocksize"=>nil,
"maxmediasize"=>nil,
"medialoaded"=>true,
"mediatype"=>"Fixed hard disk media",
"minblocksize"=>nil,
"model"=>"Microsoft Virtual Disk",
"name"=>"\\\\.\\PHYSICALDRIVE0",
"needscleaning"=>nil,
"numberofmediasupported"=>nil,
"partitions"=>3,
"pnpdeviceid"=>"SCSI\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\000000",
"powermanagementcapabilities"=>nil,
"powermanagementsupported"=>nil,
"scsibus"=>0,
"scsilogicalunit"=>0,
"scsiport"=>0,
"scsitargetid"=>0,
"sectorspertrack"=>63,
"serialnumber"=>nil,
"signature"=>nil,
"size"=>"136366917120",
"status"=>"OK",
"statusinfo"=>nil,
"systemcreationclassname"=>"Win32_ComputerSystem",
"systemname"=>"btm-win10",
"totalcylinders"=>"16579",
"totalheads"=>255,
"totalsectors"=>"266341635",
"totaltracks"=>"4227645",
"trackspercylinder"=>255},
@wmi_ole_object=#<WIN32OLE:0x0000000005517598>>]
Win32_LogicalDiskToPartition
[#<WmiLite::Wmi::Instance:0x00000000050a51b8
@property_map=
{"antecedent"=>
"\\\\btm-win10\\root\\cimv2:Win32_DiskPartition.DeviceID=\"Disk #0, Partition #2\"",
"dependent"=>
"\\\\btm-win10\\root\\cimv2:Win32_LogicalDisk.DeviceID=\"C:\"",
"endingaddress"=>"136365194751",
"startingaddress"=>"593494016"},
@wmi_ole_object=#<WIN32OLE:0x00000000050a51e0>>,
#<WmiLite::Wmi::Instance:0x000000000509fe70
@property_map=
{"antecedent"=>
"\\\\btm-win10\\root\\cimv2:Win32_DiskPartition.DeviceID=\"Disk #1, Partition #0\"",
"dependent"=>
"\\\\btm-win10\\root\\cimv2:Win32_LogicalDisk.DeviceID=\"D:\"",
"endingaddress"=>"15031336959",
"startingaddress"=>"65536"},
@wmi_ole_object=#<WIN32OLE:0x000000000509fe98>>]
Win32_LogicalDisk
[#<WmiLite::Wmi::Instance:0x000000000551dc68
@property_map=
{"access"=>0,
"availability"=>nil,
"blocksize"=>nil,
"caption"=>"C:",
"compressed"=>false,
"configmanagererrorcode"=>nil,
"configmanageruserconfig"=>nil,
"creationclassname"=>"Win32_LogicalDisk",
"description"=>"Local Fixed Disk",
"deviceid"=>"C:",
"drivetype"=>3,
"errorcleared"=>nil,
"errordescription"=>nil,
"errormethodology"=>nil,
"filesystem"=>"NTFS",
"freespace"=>"110169063424",
"installdate"=>nil,
"lasterrorcode"=>nil,
"maximumcomponentlength"=>255,
"mediatype"=>12,
"name"=>"C:",
"numberofblocks"=>nil,
"pnpdeviceid"=>nil,
"powermanagementcapabilities"=>nil,
"powermanagementsupported"=>nil,
"providername"=>nil,
"purpose"=>nil,
"quotasdisabled"=>true,
"quotasincomplete"=>false,
"quotasrebuilding"=>false,
"size"=>"135771697152",
"status"=>nil,
"statusinfo"=>nil,
"supportsdiskquotas"=>true,
"supportsfilebasedcompression"=>true,
"systemcreationclassname"=>"Win32_ComputerSystem",
"systemname"=>"btm-win10",
"volumedirty"=>false,
"volumename"=>"Windows",
"volumeserialnumber"=>"52CD78C2"},
@wmi_ole_object=#<WIN32OLE:0x000000000551dc90>>,
#<WmiLite::Wmi::Instance:0x000000000553b858
@property_map=
{"access"=>0,
"availability"=>nil,
"blocksize"=>nil,
"caption"=>"D:",
"compressed"=>false,
"configmanagererrorcode"=>nil,
"configmanageruserconfig"=>nil,
"creationclassname"=>"Win32_LogicalDisk",
"description"=>"Local Fixed Disk",
"deviceid"=>"D:",
"drivetype"=>3,
"errorcleared"=>nil,
"errordescription"=>nil,
"errormethodology"=>nil,
"filesystem"=>"NTFS",
"freespace"=>"13774643200",
"installdate"=>nil,
"lasterrorcode"=>nil,
"maximumcomponentlength"=>255,
"mediatype"=>12,
"name"=>"D:",
"numberofblocks"=>nil,
"pnpdeviceid"=>nil,
"powermanagementcapabilities"=>nil,
"powermanagementsupported"=>nil,
"providername"=>nil,
"purpose"=>nil,
"quotasdisabled"=>true,
"quotasincomplete"=>false,
"quotasrebuilding"=>false,
"size"=>"15031267328",
"status"=>nil,
"statusinfo"=>nil,
"supportsdiskquotas"=>true,
"supportsfilebasedcompression"=>true,
"systemcreationclassname"=>"Win32_ComputerSystem",
"systemname"=>"btm-win10",
"volumedirty"=>false,
"volumename"=>"Temporary Storage",
"volumeserialnumber"=>"400E135B"},
@wmi_ole_object=#<WIN32OLE:0x000000000553b880>>,
#<WmiLite::Wmi::Instance:0x0000000005554dd0
@property_map=
{"access"=>nil,
"availability"=>nil,
"blocksize"=>nil,
"caption"=>"E:",
"compressed"=>nil,
"configmanagererrorcode"=>nil,
"configmanageruserconfig"=>nil,
"creationclassname"=>"Win32_LogicalDisk",
"description"=>"CD-ROM Disc",
"deviceid"=>"E:",
"drivetype"=>5,
"errorcleared"=>nil,
"errordescription"=>nil,
"errormethodology"=>nil,
"filesystem"=>nil,
"freespace"=>nil,
"installdate"=>nil,
"lasterrorcode"=>nil,
"maximumcomponentlength"=>nil,
"mediatype"=>11,
"name"=>"E:",
"numberofblocks"=>nil,
"pnpdeviceid"=>nil,
"powermanagementcapabilities"=>nil,
"powermanagementsupported"=>nil,
"providername"=>nil,
"purpose"=>nil,
"quotasdisabled"=>nil,
"quotasincomplete"=>nil,
"quotasrebuilding"=>nil,
"size"=>nil,
"status"=>nil,
"statusinfo"=>nil,
"supportsdiskquotas"=>nil,
"supportsfilebasedcompression"=>nil,
"systemcreationclassname"=>"Win32_ComputerSystem",
"systemname"=>"btm-win10",
"volumedirty"=>nil,
"volumename"=>nil,
"volumeserialnumber"=>nil},
@wmi_ole_object=#<WIN32OLE:0x0000000005554df8>>]
a note, you can't ohai.bat filesystem2 even though it is in the results. Maybe because there isn't a provides "filesystem2". But you get this error:
[2020-05-18T14:20:30+00:00] ERROR: Encountered error while running plugins: #<Ohai::Exceptions::AttributeNotFound: No such attribute: 'filesystem2'>
Ohai Version
Chef 16.0.275, Ohai 16.0.20
Platform Version
Windows 2016 server, default AWS AMI Windows 10, Azure
Paging @jaymzh for some knowledge on this plugin
Well, the Volume name - which is the equivalent of device in windows - is "" so in the by_device hash, the key is "". This... feels like exactly the right behavior to me. You can instead use by_mountpoint and then use your drive-letter. But that hash (by_device) point in life is to give you an index by Volume Name. What other behavior could we possibly give?