Browse Source

Add support for megaraid monitoring (with perccli)

Based on scripts from https://github.com/Art3mK/Zabbix-LSI-RAID-Monitoring
master
Daniel Berteaud 1 month ago
parent
commit
0b7465a997
7 changed files with 288 additions and 4 deletions
  1. +4
    -4
      WAPT/control
  2. BIN
     
  3. BIN
     
  4. +117
    -0
      scripts/check_raid_megaraid.ps1
  5. +152
    -0
      scripts/disco_raid_megaraid.ps1
  6. +10
    -0
      setup.py
  7. +5
    -0
      zabbix_agentd.conf.d/raid_megaraid.conf

+ 4
- 4
WAPT/control View File

@@ -1,5 +1,5 @@
package : fws-zabbix-agent
version : 5.0.3-2
version : 5.0.3-5
architecture : all
section : base
priority : optional
@@ -31,13 +31,13 @@ editor : Zabbix SIA
keywords : monitoring, zabbix, agent
licence :
homepage : https://zabbix.com
package_uuid : d9d05c05-bd84-4eac-8b64-05a3c518a6b4
package_uuid : 19f8e32b-3b75-4547-95e6-ba31e9395770
valid_from :
valid_until :
forced_install_on :
changelog :
signer : Daniel Berteaud
signer_fingerprint: 3c9415559e2dedbc4390e3faa2c28d3b67265baa5b35902d2764d9e41c3b3f0a
signature : Poipzhnpm383+yinYYjJVi1tIT7tNR2oH0B8RGC+BsdQVxsAyAAnGxOsSH2LnX1nlbrmQGI/U+4DTtKtH6WuyRk7A8XDa2tVlXd0Y2mrpitqr1zv9PiglrnxXkDk+f2hal20Bsm0cOZ0CET9iSs0UsZA2wIY4yNY0KIvtV8T+u8muPbUleSQu4ukdHE3RjOtcyBcKje2OcJWK7ABjkHXs9BuA8LUlHBdkxmzNAFFwcOk/fSXOltHfVgEdh3ZldviFYJxNI+7QL/QVtAi9aUgr2CjZcAc+SHh6P5XxPUXHeUFB+bHGAbg7gkmALQqym2TFsSIbvnhpimZ4qGr3YejiQ==
signature_date : 2020-08-27T09:24:58.935000
signature : ghFVHSOf8p7IBqeAqcawIl6IVA8See2s670wDvs+QHTQqKE/NRGjJjyuM+QROS6xk3UDcILY0pIHZkw5jE/Z3XkivpU3aP1bWGY4mQ3Wqt8qxymPmKRNLEYwE+DwW8iSsuivVBvY+gkyfv18ewBa+So19AmlfBalOxlzFLyihVs1TtNkJql7vNfbpV18pBpmwImeijLGnSpdS/0EY6DSQRK4s1YINegjxNuWDeNx9WV0OQRowVFSarfK0oUrEo+m9Tyaqnl+7UNJWFq3fiuI1lRUIXs2tjJHVtGOt/8ceIxM0UXzRCKwCZIwWEOc5fRdmHv7FFmrq+dWpRwkThXwQg==
signature_date : 2020-09-01T11:29:17.881000
signed_attributes : package,version,architecture,section,priority,name,categories,maintainer,description,depends,conflicts,maturity,locale,target_os,min_os_version,max_os_version,min_wapt_version,sources,installed_size,impacted_process,description_fr,description_pl,description_de,description_es,description_pt,description_it,description_nl,description_ru,audit_schedule,editor,keywords,licence,homepage,package_uuid,valid_from,valid_until,forced_install_on,changelog,signer,signer_fingerprint,signature_date,signed_attributes

BIN
View File


BIN
View File


+ 117
- 0
scripts/check_raid_megaraid.ps1 View File

@@ -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 }
}

+ 152
- 0
scripts/disco_raid_megaraid.ps1 View File

@@ -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 }
}

+ 10
- 0
setup.py View File

@@ -49,6 +49,16 @@ def install():
# And add a new one
run('netsh advfirewall firewall add rule name="Zabbix Agent" dir=in action=allow protocol=TCP localport=10050 enable=yes remoteip=%s' % (','.join(variables['zabbix_servers'])))
# Copy conf, scripts and binaries
print('Copying additional configuration, scripts and binaries')
for dir in ['zabbix_agentd.conf.d','scripts','bin']:
mkdirs(makepath(programfiles,'Zabbix Agent',dir))
copytree2(dir,makepath(programfiles,'Zabbix Agent',dir))
# Restart the service
print('Restarting the service')
service_restart('Zabbix Agent')
def uninstall():
print('Removing firewall rule')
run_notfatal('netsh advfirewall firewall del rule name="Zabbix Agent"')


+ 5
- 0
zabbix_agentd.conf.d/raid_megaraid.conf View File

@@ -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…
Cancel
Save