Ad Widget

Collapse

Windows 2012 Disk Monitoring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JDNight
    Junior Member
    • Nov 2006
    • 15

    #1

    Windows 2012 Disk Monitoring

    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 wrote a powershell script to handle the volume discovery and disk free space monitoring:

    Code:
    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
    
    }
    More on setting up the script:
    A blog about IT tech tips. Covering Microsoft Windows, Hyper V, Firewalls, SANs, Networks, Exchnage, and Zabbix
  • pzabortsev
    Senior Member
    • Dec 2012
    • 338

    #2
    Good work!

    Many thanks!

    Comment

    • elvar
      Senior Member
      • Feb 2008
      • 226

      #3
      not valid json

      Hello, zabbix 2.4 reports that the output is not in valid JSON format. I noticed it is leaving a trailing comma at the end which should not be there. If you remove the last comma the json passes validation. Any chance you would modify the script to remove that comma?

      Comment

      • elvar
        Senior Member
        • Feb 2008
        • 226

        #4
        I modified JDNight's script to resolve the JSON validation problems I was seeing in Zabbix 2.4. I also made it so it only discovers filesystems of type CSVFS. You can certainly add in others.

        Code:
        param(
            [Parameter(Mandatory=$False)]
            [string]$QueryName,
            [string]$FSName
        )
        
        if ($QueryName -eq '') {
           
        $result = @{}
        $result.data = @()
        
        foreach ($fs in gwmi win32_volume | where {$_.FileSystem -eq "CSVFS"} | select Name,FileSystem) {
            $result.data += @{
                "{#FSNAME}" = $fs.Name -replace "\\","/";
                "{#FSTYPE}" = $fs.FileSystem;
            }
        }
        
        $result | ConvertTo-Json
        
        }
        
        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
        
        }

        Comment

        Working...