原文详见 https://blog.51cto.com/magic3/7555836
优化两部分
- 脚本部分
- 补充zabbix UserParameter部分
脚本部分
- 物理磁盘发现:
Storcli_PDisk_Discovery.ps1
#author:shizhenning
#----20250928V2----#
$Path_tool = "C:\Program Files\StorCli\"
cd $Path_tool
$Count_Physical_Disk = (.\storcli64.exe /c0 show |where {$_ -match "^Physical Drives"}).Split('=')[-1] #获取物理磁盘总数量
$PDisk_Discovery = .\storcli64.exe /c0 show J nolog
$Data_Source = $PDisk_Discovery | ConvertFrom-Json #json转换成自定义对象
$Raid_Info = $Data_Source.Controllers[0]
$Location_Physical_Disk = $Raid_Info.'Response Data'.'PD LIST'.'EID:Slt' #获取物理磁盘位置,形如32:0,32:1,32:2
### 构造json格式
$discoveryData = $Location_Physical_Disk | ForEach-Object {
[PSCustomObject]@{
"{#PDISK}" = $_
}
}
$jsondata = $discoveryData | ConvertTo-Json
Write-Output $jsondata
- 物理磁盘信息
Storcli_PDisk_Info.ps1
#author:shizhenning
#----20250928---#
<#
EID=Enclosure Device ID|Slt=Slot No|DID=Device ID|DG=DriveGroup
DHS=Dedicated Hot Spare|UGood=Unconfigured Good|GHS=Global Hotspare
UBad=Unconfigured Bad|Sntze=Sanitize|Onln=Online|Offln=Offline|Intf=Interface
Med=Media Type|SED=Self Encryptive Drive|PI=PI Eligible
SeSz=Sector Size|Sp=Spun|U=Up|D=Down|T=Transition|F=Foreign
UGUnsp=UGood Unsupported|UGShld=UGood shielded|HSPShld=Hotspare shielded
CFShld=Configured shielded|Cpybck=CopyBack|CBShld=Copyback Shielded
UBUnsp=UBad Unsupported|Rbld=Rebuild
#>
$Path_tool = "C:\Program Files\StorCli\"
cd $Path_tool
$Location_Physical_Disk = $args[0] #参数格式[32:6],即磁盘盘位
$Attr_PDisk = $args[1] #参数选项 State, Size ,Interface(SAS\SATA),Model,
$Number_Enclousure = $Location_Physical_Disk.trim("[","]").split(":")[0] #获取Enclousure ID,比如32
$DID_Physical_Disk = $Location_Physical_Disk.trim("[","]").split(":")[1] #从形如[32:2]格式的盘位获取磁盘ID 2,供storcli /s调用
$PDAttr_info = .\storcli64.exe /c0 /e $Number_Enclousure /s $DID_Physical_Disk show NOLOG J
$Attr_Source = $PDAttr_info | ConvertFrom-Json #获取磁盘属性列表,比如State, Size ,Intf(SAS\SATA),Model,Med\DID(Device ID)等
Write-Output $Attr_Source.Controllers[0].'Response Data'.'Drive Information'.$Attr_PDisk
- 虚拟磁盘发现
#author:shizhenning
#----20250928V2----#
$Path_tool = "C:\Program Files\StorCli\"
cd $Path_tool
$Count_Physical_Disk = (.\storcli64.exe /c0 show |where {$_ -Match "^Virtual"}).Split("=")[-1] #获取虚拟磁盘总数量
$VDisk_Discovery = .\storcli64.exe /c0 show J nolog
$Data_Source = $VDisk_Discovery | ConvertFrom-Json #json转换成复的自定义对象
$Raid_Info = $Data_Source.Controllers[0]
$List_VDisk = $Raid_Info.'Response Data'.'VD LIST'.'DG/VD' #获取虚拟磁盘名称,形如0/0,1/1
$discoveryData = $List_VDisk | ForEach-Object {
[PSCustomObject]@{
"{#VDISK}" = $_
}
}
$jsondata = $discoveryData | ConvertTo-Json
Write-Output $jsondata
- 虚拟磁盘信息
#author:shizhenning
#----20250928---#
$Path_tool = "C:\Program Files\StorCli\"
cd $Path_tool
<#
VD=Virtual Drive| DG=Drive Group|Rec=Recovery
Cac=CacheCade|Rec=Recovery|OfLn=OffLine|Pdgd=Partially Degraded|Dgrd=Degraded
Optl=Optimal|dflt=Default|RO=Read Only|RW=Read Write|HD=Hidden|TRANS=TransportReady
B=Blocked|Consist=Consistent|R=Read Ahead Always|NR=No Read Ahead|WB=WriteBack
FWB=Force WriteBack|WT=WriteThrough|C=Cached IO|D=Direct IO|sCC=Scheduled
Check Consistency
#>
$No_VDisk = $args[0] #参数为获取虚拟磁盘名称,形如0/0,1/1
$No_VDisk = $No_VDisk.split("/")[-1]
$Attr_VDisk_Query = $args[1] #参数选项name,size,type,state,cache,scc等
$Attr_VDisk = .\storcli64.exe /c0 /v$No_VDisk show J NOLOG
$Attr_Source = $Attr_VDisk | ConvertFrom-Json #获取虚拟磁盘属性列表,比如name,size,type,state,cache,scc等
Write-Output $Attr_Source.Controllers[0].'Response Data'.'Virtual Drives'.$Attr_VDisk_Query
zabbix 部分
- UserParameter部分: userparameter.conf
UserParameter=PDisk.discovery,c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy bypass -File "C:\zabbix\scripts\Storcli_PDisk_Discovery.ps1"
UserParameter=PDisk.Info[*],c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy bypass -File C:\zabbix\scripts\Storcli_PDisk_Info.ps1 $1 "$2"
UserParameter=VDisk.discovery,c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy bypass -File C:\zabbix\scripts\Storcli_VDisk_Discovery.ps1
UserParameter=VDisk.Info[*],c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy bypass -File C:\zabbix\scripts\Storcli_VDisk_Info.ps1 $1 "$2"
- zabbix 模板
物理磁盘:

虚拟磁盘:

















