# This script checks that a cluster's File Share Witness is online. # check_file_share_witness v0.01 # Copyright (C) 2016 Minh Van Le # License GPLv3+: GNU GPL version 3 or later # This is free software: you are free to change and redistribute it. # There is NO WARRANTY, to the extent permitted by law. # # Written by Minh Van Le [CmdletBinding()] param ( [string] $cluster, [string] $node, [string] $fsw, [switch] $c ) #/******************************************************************************** # * Functions # ********************************************************************************/ function usage() { "Usage: check_file_share_witness [-cluster:cluster_name] [-node:node_name] [-fsw:share_path] [-c]" } function isNodeUp() { $cmd = "-split (cluster $clusterOption node $node | select-string 'Up')" $output = invoke-expression $cmd $output[-1] -eq "up" } function isFileShareWitnessOnline() { $cmd = "-split (cluster $clusterOption res 'File Share Witness' | select-string 'Online')" $output = invoke-expression $cmd $output[-1] -eq "online" } function getFileShareWitness() { $cmd = "-split (cluster $clusterOption res 'File Share Witness' /priv | select-string 'SharePath')" $output = invoke-expression $cmd $output[-1] } function doCheck() { if ($node) { if (! (isNodeUp)) { write-host "$node is not up" return $false } } if ($fsw) { if (! ($fsw -eq (getFileShareWitness))) { write-host "Path is not a witness $fsw" return $false } } if (! (isFileShareWitnessOnline)) { write-host "File Share Witness is not online" return $false } #/* All passed */ return $true } function returnNagiosResult() { if ($error) { exit 3 #// Unknown } elseif ($result -eq $false) { if ($c) { exit 2 #// Critical } else { exit 1 #// Warning } } elseif ($result -eq $true) { "OK: " + (getFileShareWitness) exit 0 } else { "Huh ?" exit 3 #// Unknown } } #/******************************************************************************** # * Main # ********************************************************************************/ if (! $psboundparameters.count) { usage exit 3 } $error.clear() if ($cluster) { $clusterOption = " /cluster:$cluster " } $result = doCheck returnNagiosResult