Based on scripts from https://github.com/Art3mK/Zabbix-LSI-RAID-Monitoringmaster
parent
dbdc6ca9a6
commit
0b7465a997
7 changed files with 288 additions and 4 deletions
Binary file not shown.
Binary file not shown.
@ -0,0 +1,117 @@ |
||||
Param( |
||||
[parameter(Position=0,Mandatory=$true)] |
||||
[ValidateSet("pdisk", "vdisk", "bbu", "adapter")] |
||||
[alias("m")] |
||||
[String] |
||||
$mode |
||||
, |
||||
[parameter()] |
||||
[ValidateNotNullOrEmpty()] |
||||
[alias("p","item")] |
||||
[string] |
||||
$mode_item |
||||
, |
||||
[parameter(Mandatory=$true)] |
||||
[ValidateRange(0,5)] |
||||
[alias("a","adp")] |
||||
[int] |
||||
$adapter |
||||
, |
||||
[parameter()] |
||||
[ValidateRange(0,4096)] |
||||
[alias("e","enc")] |
||||
[int] |
||||
$enclosure_id |
||||
, |
||||
[parameter()] |
||||
[ValidateRange(0,256)] |
||||
[alias("pdisk")] |
||||
[int] |
||||
$disk_id |
||||
, |
||||
[parameter()] |
||||
[ValidateRange(0,256)] |
||||
[alias("vdisk")] |
||||
[int] |
||||
$vdisk_id |
||||
) |
||||
|
||||
$CLI = "C:\Program Files\Zabbix Agent\bin\perccli64.exe" |
||||
|
||||
function pdisk_item($item,$adapter,$enclosure_id,$disk_id) { |
||||
$regex = '' |
||||
switch ($item) { |
||||
'firmware_state' { $regex = "Firmware state:\s(.*)" } |
||||
'raw_size' { $regex = "Raw Size:\s+(\d+\.\d+\s..)" } |
||||
'predictive_errors' { $regex = "Predictive Failure Count:\s(.*)" } |
||||
'inquiry_data' { $regex = "Inquiry Data:\s+(.*)" } |
||||
'media_errors' { $regex = "Media Error Count:\s(.*)" } |
||||
} |
||||
|
||||
if ($enclosure_id -eq 2989) { $enclosure_id = '' } |
||||
$output = (& $CLI -pdinfo -PhysDrv["$enclosure_id":"$disk_id"] -a $adapter -NoLog | Select-String $regex -AllMatches | % { $_.Matches } | % { $_.groups[1].value }) |
||||
if ($item -eq 'firmware_state') { |
||||
if ($output -Match '^(Unconfigured\(good\).*|Online,\sSpun.*|Hotspare,\sSpun.*)$') { |
||||
$output = 0 |
||||
} |
||||
elseif ($output -Match '^Rebuild') { |
||||
$output = 2 |
||||
} |
||||
else { |
||||
$output = 1 |
||||
} |
||||
} |
||||
write-host $output |
||||
} |
||||
|
||||
function vdisk_item($item,$adapter,$vd) { |
||||
$regex = '' |
||||
switch ($item) { |
||||
'vd_state' { $regex = "^State\s+:\s(.*)$" } |
||||
'vd_size' { $regex = "^Size\s+:\s(\d+\.\d+\s..)" } |
||||
} |
||||
|
||||
$output = (& $CLI -LDinfo -L $vd -a $adapter -NoLog | Select-String $regex -AllMatches | % { $_.Matches } | % { $_.groups[1].value }) |
||||
if ($item -eq 'vd_state') { |
||||
if ($output -Match '^Optimal$') { $output = 0 } else { $output = 1 } |
||||
} |
||||
write-host $output |
||||
} |
||||
|
||||
function bbu_item($item,$adapter){ |
||||
$regex = '' |
||||
$command = '' |
||||
switch ($item) { |
||||
'bbu_state' { $command = '-GetBbuStatus'; $regex = "Battery State\s*:\s(.*)$"; $wanted_group = 1 } |
||||
'design_capacity' { $command = '-GetBBUDesignInfo'; $regex = "Design\sCapacity:\s(\d+)\s(mAh|J)"; $wanted_group = 1 } |
||||
'full_capacity' { $command = '-GetBBUCapacityInfo'; $regex = "(Full\sCharge\sCapacity|.*Pack\senergy\s*):\s(\d+)\s(mAh|J)"; $wanted_group = 2 } |
||||
'state_of_charge' { $command = '-GetBBUCapacityInfo'; $regex = "Absolute\sState\sof\scharge\s*:\s(\d+).*%"; $wanted_group = 1 } |
||||
'date_manufactured' { $command = '-GetBBUDesignInfo'; $regex = "Date\sof\sManufacture\s*:\s(.*)$"; $wanted_group = 1 } |
||||
} |
||||
if ($bbu_state -Match '^(Optimal|Operational)$') { $bbu_state = 0 } else { $bbu_state = 1 } |
||||
$output = (& $CLI -AdpBbuCmd $command -a $adapter -NoLog | Select-String $regex | % {$_.Matches} | % { $_.groups[$wanted_group].value }) |
||||
if ($item -eq 'bbu_state') { |
||||
if ($output -Match '^(Optimal|Operational)$') { $output = 0 } else { $output = 1 } |
||||
} |
||||
write-host $output |
||||
} |
||||
|
||||
function adapter_item($item,$adapter){ |
||||
$regex = '' |
||||
switch ($item) { |
||||
'fw_version' { $regex = "^\s*FW\sPackage\sBuild:\s(.*)$" } |
||||
'product_name' { $regex = "^\s*Product\sName\s*:\s(.*)$" } |
||||
} |
||||
|
||||
$output = (& $CLI -AdpAllInfo -a $adapter -NoLog | Select-String $regex | % {$_.Matches} | % { $_.groups[1].value }) |
||||
write-host $output |
||||
} |
||||
|
||||
### Start doing our job |
||||
|
||||
switch ($mode) { |
||||
"pdisk" { pdisk_item $mode_item $adapter $enclosure_id $disk_id } |
||||
"vdisk" { vdisk_item $mode_item $adapter $vdisk_id } |
||||
"bbu" { bbu_item $mode_item $adapter } |
||||
"adapter" { adapter_item $mode_item $adapter } |
||||
} |
@ -0,0 +1,152 @@ |
||||
Param( |
||||
[parameter(Position=0,Mandatory=$true)] |
||||
[ValidateSet("pdisk", "vdisk", "bbu", "adapter")] |
||||
[alias("m")] |
||||
[String] |
||||
$mode |
||||
, |
||||
[parameter()] |
||||
[ValidateRange(0,5)] |
||||
[alias("a","adp")] |
||||
[int] |
||||
$adapter |
||||
) |
||||
|
||||
$CLI = "C:\Program Files\Zabbix Agent\bin\perccli64.exe" |
||||
|
||||
|
||||
function disco_adp() { |
||||
$number_of_adapters = [int](& $CLI -adpCount -NoLog | Select-String "Controller Count: (\d+)" -AllMatches | % {$_.Matches} | % {$_.groups[1].value}) |
||||
$out = '[' |
||||
$i = 1 |
||||
for ($adapter_id = 0; $adapter_id -lt $number_of_adapters; $adapter_id++) { |
||||
$out = $out + "{`"{#MEGARAID_ADP}`": `"$adapter_id`"}" |
||||
if ($i -lt $number_of_adapters){ |
||||
$out = $out + ',' |
||||
} |
||||
$i++ |
||||
} |
||||
$out = $out + ']' |
||||
Write-Host $out |
||||
} |
||||
|
||||
function disco_bbu() { |
||||
$battery_units = @{} |
||||
$number_of_adapters = [int](& $CLI -adpCount -NoLog | Select-String "Controller Count: (\d+)" -AllMatches | % {$_.Matches} | % {$_.groups[1].value}) |
||||
for ($adapter_id = 0; $adapter_id -lt $number_of_adapters; $adapter_id++) { |
||||
$bbu_is_missing = (& $CLI -AdpBbuCmd -GetBbuStatus -a $adapter -NoLog | Select-String ".*Get BBU Status Failed.*" | % {$_.Matches}) |
||||
if (!$bbu_is_missing) { |
||||
$battery_units.Add($adapter,"{ `"{#ADAPTER_ID}`":`"$adapter`" }") |
||||
} |
||||
} |
||||
$out = '[' |
||||
$i = 1 |
||||
foreach ($battery_unit in $battery_units.Keys){ |
||||
$out = $out + "$($battery_units.item($battery_unit))" |
||||
if ($i -lt $battery_units.Count){ |
||||
$out = $out + "," |
||||
} |
||||
} |
||||
$out = $out + ']' |
||||
Write-Host $out |
||||
} |
||||
|
||||
function disco_vdisk() { |
||||
$virtual_drives = @{} |
||||
# check IDs for configured RAID volumes (IDs could be sequential, or not) |
||||
$tmp_file = Join-Path ${env:temp} "raid_vdrives-$(Get-Date -Format yyyy-MM-dd-HH-mm-ss).tmp" |
||||
& $CLI -LDinfo -Lall -a $adapter -NoLog | Out-File $tmp_file |
||||
[regex]$regex_vd_id = "^\s*Virtual\sDrive:\s(\d+)\s.*$" |
||||
$reader = [System.IO.File]::OpenText($tmp_file) |
||||
$vdrive_id = -1; |
||||
try { |
||||
for(;;) { |
||||
$line = $reader.ReadLine() |
||||
if ($line -eq $null) { break } |
||||
if (($regex_vd_id.isMatch($line)) -eq $True) { |
||||
$vdrive_id = $regex_vd_id.Matches($line) | % {$_.groups[1].value} |
||||
$virtual_drives.Add("$adapter-$vdrive_id","{ `"{#VDRIVE_ID}`":`"$vdrive_id`", `"{#ADAPTER_ID}`":`"$adapter`" }") |
||||
} else { |
||||
Continue |
||||
} |
||||
} |
||||
} |
||||
finally { |
||||
$reader.Close() |
||||
} |
||||
remove-item $tmp_file |
||||
$out = '[' |
||||
$i = 1 |
||||
foreach ($virtual_drive in $virtual_drives.Keys) { |
||||
$out = $out + "$($virtual_drives.Item($virtual_drive))" |
||||
if ($i -lt $virtual_drives.Count) { |
||||
$out = $out + "," |
||||
} |
||||
$i++ |
||||
} |
||||
$out = $out + ']' |
||||
Write-Host $out |
||||
} |
||||
|
||||
function disco_pdisk() { |
||||
$physical_drives = @{} |
||||
# ======== |
||||
# List all physical drives |
||||
# ======== |
||||
$check_next_line = 0 |
||||
[regex]$regex_enc = "^\s*Enclosure\sDevice\sID:\s(\d+)$" |
||||
[regex]$regex_enc_na = "^\s*Enclosure\sDevice\sID:\sN\/A$" |
||||
[regex]$regex_slot = "^\s*Slot\sNumber:\s(\d+)$" |
||||
|
||||
$tmp_file = Join-Path ${env:temp} "raid_enclosures-$(Get-Date -Format yyyy-MM-dd-HH-mm-ss).tmp" |
||||
& $CLI -pdlist -a $adapter -NoLog | Out-File $tmp_file |
||||
$reader = [System.IO.File]::OpenText($tmp_file) |
||||
|
||||
# Determine Slot Number for each drive on enclosure |
||||
$enclosure_id = -1; |
||||
try { |
||||
for(;;) { |
||||
$line = $reader.ReadLine() |
||||
if ($line -eq $null) { break } |
||||
# Line contains enc id, next line is slot id |
||||
if (($regex_enc.isMatch($line)) -eq $True) { |
||||
$enclosure_id = $regex_enc.Matches($line) | % {$_.groups[1].value} |
||||
$check_next_line = 1 |
||||
} elseif (($regex_enc_na.isMatch($line)) -eq $True) { |
||||
# This can happen, if embedded raid controller is in use, there are drives and logical disks, but no enclosures |
||||
$enclosure_id = 2989 # 0xBAD, :( magic hack |
||||
$check_next_line = 1 |
||||
} elseif ((($regex_slot.isMatch($line)) -eq $True) -and ($check_next_line -eq 1) -and ($enclosure_id -ne -1)) { |
||||
$drive_id = $regex_slot.Matches($line) | % {$_.groups[1].value} |
||||
$physical_drives.Add("$adapter-$enclosure_id-$drive_id","{ `"{#ENCLOSURE_ID}`":`"$enclosure_id`", `"{#PDRIVE_ID}`":`"$drive_id`", `"{#ADAPTER_ID}`":`"$adapter`" }") |
||||
$check_next_line = 0 |
||||
$enclosure_id = -1 |
||||
} else { |
||||
Continue |
||||
} |
||||
} |
||||
} |
||||
finally { |
||||
$reader.Close() |
||||
} |
||||
remove-item $tmp_file |
||||
|
||||
$out = '[' |
||||
$i = 1 |
||||
foreach ($physical_drive in $physical_drives.Keys) { |
||||
$out = $out + "$($physical_drives.Item($physical_drive))" |
||||
if ($i -lt $physical_drives.Count) { |
||||
$out = $out + "," |
||||
} |
||||
$i++ |
||||
} |
||||
$out = $out + ']' |
||||
Write-Host $out |
||||
} |
||||
|
||||
switch ($mode) { |
||||
"adapter" { disco_adp } |
||||
"bbu" { disco_bbu } |
||||
"vdisk" { disco_vdisk } |
||||
"pdisk" { disco_pdisk } |
||||
} |
@ -0,0 +1,5 @@ |
||||
UserParameter=raid.megaraid.discovery[*],C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\Zabbix Agent\scripts\disco_raid_megaraid.ps1" -mode $1 |
||||
UserParameter=raid.megaraid.adapter[*],C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\Zabbix Agent\scripts\check_raid_megaraid.ps1" -mode adapter -item $2 -adapter $1 |
||||
UserParameter=raid.megaraid.bbu[*],C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\Zabbix Agent\scripts\check_raid_megaraid.ps1" -mode bbu -item $2 -adapter $1 |
||||
UserParameter=raid.megaraid.vdisk[*],C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\Zabbix Agent\scripts\check_raid_megaraid.ps1" -mode vdisk -item $3 -adapter $1 -vdisk $2 |
||||
UserParameter=raid.megaraid.pdisk[*],C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\Zabbix Agent\scripts\check_raid_megaraid.ps1" -mode pdisk -item $4 -adapter $1 -enc $2 -pdisk $3 |
Loading…
Reference in new issue