Windows Disk Monitor for Zabbix


With a Windows 2012 Cluster Microsoft introduced a new file system - CSVFS. I found that currently the zabbix agent does not return this file system when using the vfs.fs.discovery low level discovery for the file system. Additionally the low level discovery will not work on volumes that have been mapped to a directory instead of a driver letter.

So I've written a powershell script that handles finding file system and monitoring for drive capacity and free space:

param(
    [Parameter(Mandatory=$False)]
    [string]$QueryName,
    [string]$FSName
)

if ($QueryName -eq '') {
   
    $colItems = gwmi win32_volume | select Name,FileSystem

    write-host "{"
    write-host " `"data`":["
    write-host

    foreach ($objItem in $colItems) {
        $objItem.Name = $objItem.Name -replace "\\\\\?\\Volume{","Volume-"
        $objItem.Name = $objItem.Name -replace "}\\","`+"
        $objItem.Name = $objItem.Name -replace "\\","/"
        $line =  " { `"{#FSNAME}`":`"" + $objItem.Name + "`" , `"{#FSTYPE}`":`"" + $objItem.FileSystem + "`" },"
        write-host $line
    }

    write-host
    write-host " ]"
    write-host "}"
    write-host
}

else {
    #$FSName = [regex]::escape($FSName)
    $FSName = $FSName -replace "Volume-","\\\\?\\Volume{"
    $FSName = $FSName -replace "\+","}\\"
    $FSName = $FSName -replace "/","\\"
    switch ($QueryName)
        {
        ('Capacity') {$Results = gwmi win32_volume -Filter "name = '$FSName'" | select Capacity | Format-Table -HideTableHeaders -AutoSize}
        ('FreeSpace') {$Results = gwmi win32_volume -Filter "name = '$FSName'" | select FreeSpace | Format-Table -HideTableHeaders -AutoSize}
        default {$Results = "Incorrect Command Given"}
        }
    $Results = $Results | Out-String
    $Results = $Results.trim()
    Write-Host $Results

}
https://github.com/jdnow/ZabbixFiles/blob/master/Scripts/WinDrives_Status.ps1

I have also tested it running on Windows 2008 servers.

Settings for zabbix agent config:
UserParameter=windisk.discover,powershell.exe -NoProfile -ExecutionPolicy Bypass -file "C:\Program Files\Zabbix\WinDrives_Status.ps1"
UserParameter=windisk.check[*],powershell.exe -NoProfile -ExecutionPolicy Bypass -file "C:\Program Files\Zabbix\WinDrives_Status.ps1" $1 "$2"

Zabbix Discovery Rule:

Zabbix Item Prototypes:


Auto Discovery of Window 2012 Volumes:

Comments

Post a Comment