Ad Widget

Collapse

Detecting broken RAIDS in Windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frater
    Senior Member
    • Oct 2010
    • 340

    #1

    Detecting broken RAIDS in Windows

    I want to detect broken RAIDS in Windows and I think I'm close with a very simple recipe, but somehow I just can't see it working reliably on ALL windows machines.

    Userparameters
    Code:
    UserParameter=vfs.softraid.count,   findstr /i   "Mirror RAID" %TEMP%\diskpart | find /c /i "volume"
    UserParameter=vfs.softraid.healthy, findstr /i   "Mirror RAID" %TEMP%\diskpart | findstr /i "healthy orde" | find /c /i "volume"
    UserParameter=vfs.volumes.count,   findstr /i /v "Mirror RAID" %TEMP%\diskpart | find /c /i "volume"
    UserParameter=vfs.volumes.healthy, findstr /i /v "Mirror RAID" %TEMP%\diskpart | findstr /i "healthy orde" | find /c /i "volume"
    UserParameter=vfs.volumes, echo.list volume | diskpart | findstr /i "FAT NTFS" >%TEMP%\diskpart && TYPE %TEMP%\diskpart
    Output of vfs.volumes
    Code:
    Volume 0     C   Windows      NTFS   Partition     27 GB  Healthy    Boot    
      Volume 1         SYSTEM       FAT32  Partition    100 MB  Healthy    System  
      Volume 2         Recovery     NTFS   Partition   1024 MB  Healthy    Hidden
    In this case the output of the 4 userparameters are
    Code:
    vfs.softraid.count    0
    vfs.softraid.healthy    0
    vfs.volumes.count     3
    vfs.volumes.healthy 3
    But somehow the 2 userparameters are greyed out in "latest data" with the information "0"
    Why?
    I don't know....

    I created 2 triggers
    This one for the RAID volumes
    Code:
    {Template_Windows_Volumes:vfs.softraid.healthy.last()}
     < {Template_Windows_Volumes:vfs.softraid.count.last()}
    This one for the regular volumes
    Code:
    {Template_Windows_Volumes:vfs.volumes.healthy.last()}
     < {Template_Windows_Volumes:vfs.volumes.count.last()}

    I thought I could let the Zabbix server process the output of diskpart itself, but I found out I have no means of counting the strings.

    regexp() can only return 0 or 1 (for instance)
    I also can't think of some regular expression to use as preprocessing a dependent item that would count the occurences of the RAID.


    Another solution would be the creation of a script that gives an output like this. Then I could use the available regular expressions to create dependent items.

    Code:
    All SoftRaid Volumes 0
    Healthy Softraid Volumes 0
    Regular Volumes 3
    Healthy Regular Volumes 3
    I'm just not that good with powershell (quite good in bash, though).
    Anyone willing to help me???
    Attached Files
    Last edited by frater; 04-12-2017, 18:47.
    Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP
  • frater
    Senior Member
    • Oct 2010
    • 340

    #2
    I decided to do it totally different and am now exploring powershell.
    I rarely use that, but by trial and error I came to some commands that I could use with regular expressions.

    Code:
    $Disks=Get-Disk
    Write-Host All Disks $Disks.Count
    Write-Host Healthy Disks ($Disks | Where-Object -FilterScript { $_.HealthStatus -eq "Healthy" }).Count
    Code:
    All Disks 11
    Healthy Disks 11
    I tested this on my own Windows 10 machine.
    Because I don't have any softraid I continued the trial and error on a Windows 2008R2 machine.
    I then found out that Get-Disk didn't work as it is running Powershell 2.0

    I don't know that much about powershell and how it influences the computer.
    Can I just install a newer powershell on it and trust that everything is alright? I've seen some posts that I shouldn't.

    It seems to be related to .NET4
    Well, .NET4.7 is installed on these machines.
    The powershell is however 2.0
    I don't even know if 4.0 is enough...

    How can I run powershell 4.0 from the Zabbix agent???
    Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

    Comment

    • frater
      Senior Member
      • Oct 2010
      • 340

      #3
      After finding out that the other objects (wmi or internal powershell) aren't telling me properly I have a broken mirror or not I went back to diskpart, but this time I've learned some extra powershell.
      It seems I shouldn't use "echo" in powershell.

      This project made me return to diskpart.exe (and borrowed one line of that code.... which I modified)



      Code:
      $diskpart = "list volume" | diskpart | ? { $_ -match "^  [^-]" } | Select-String -SimpleMatch -Pattern "FAT","NTFS"
      $mirrored = $diskpart | Select-String -SimpleMatch -Pattern "Mirror","RAID"
      $regular = $diskpart | Select-String -SimpleMatch -NotMatch -Pattern "Mirror","RAID"
      
      Write-Host All Healthy RAID Volumes ($mirrored | Select-String -SimpleMatch -Pattern "Healthy","orde").count
      Write-Host All RAID Volumes ($mirrored).count
      Write-Host All Healthy Regular Volumes ($regular | Select-String -SimpleMatch -Pattern "Healthy","orde").count
      Write-Host All Regular Volumes ($regular).count
      Write-Host All Healthy Volumes ($diskpart | Select-String -SimpleMatch -Pattern "Healthy","orde").count
      Write-Host All Volumes ($diskpart).count
      Code:
      All Healthy RAID Volumes 0
      All RAID Volumes 0
      All Healthy Regular Volumes 13
      All Regular Volumes 13
      All Healthy Volumes 13
      All Volumes 13
      Well.... This works fine on my Windows 10 machine, but somehow the count is not reliable on Windows 2008R2 (or Powershell 2.0)
      So, back to the drawing board.....

      Well, that's for tomorrow
      If anyone knows some tips....???

      [EDIT]
      Mmmm, this is so addicting....

      I found this link, but that didn't work either.
      https://stackoverflow.com/questions/...ng-as-expected
      But using some imagination I came up with this and that DID work.

      diskpart.ps1
      Code:
      $diskpart = "list volume" | diskpart | ? { $_ -Match "FAT|NTFS"} | foreach { $_.trim() }
      $mirrored = @($diskpart | Select-String -SimpleMatch -Pattern "Mirror","RAID")
      $regular = @($diskpart | Select-String -SimpleMatch -NotMatch -Pattern "Mirror","RAID")
      
      Write-Output $diskpart
      Write-Host All Healthy RAID Volumes @($mirrored | Select-String -SimpleMatch -Pattern "Healthy","orde").count
      Write-Host All RAID Volumes @($mirrored).count
      Write-Host All Healthy Regular Volumes @($regular | Select-String -SimpleMatch -Pattern "Healthy","orde").count
      Write-Host All Regular Volumes @($regular).count
      Write-Host All Healthy Volumes @($diskpart | Select-String -SimpleMatch -Pattern "Healthy","orde").count
      Write-Host All Volumes @($diskpart).count
      Code:
      UserParameter=vfs.volumes, powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files (x86)\Zabbix Agent\diskpart.ps1"
      It's very satisfying to reach this on my own.
      I would still like to know where to get some help as I still have no idea why the code in the first post is unreliable.
      On the other hand.. It's obvious for me that my last code is more efficient.

      Would like to know if others will start using this.
      I've seen other attempts at detecting a broken RAID in Windows, but they seem to me overly complicated.

      I may give this another approach using LLD.
      Give everything back in JSON or XML data and create the dependent items based on that info.

      For now I'm very satisfied.
      I also have the raw data output of diskpart and maybe something will come out after I start implementing this on all my agents.
      I did bring the interval to 15 minutes. That should be enough.
      Attached Files
      Last edited by frater; 05-12-2017, 16:02.
      Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

      Comment

      Working...