# MemUsed by a Process # # This script will look at all mailbox databases # and determine the status of each. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # Originally created by Jeff Roberson (jeffrey.roberson@gmail.com) # at Bethel College, North Newton, KS # # Revision History # 18/07/2012 Matthieu Paturot Creation # # To execute from within NSClient++ # #[NRPE Handlers] #memory_used_process=scripts\powershellexec.bat "D:\Scripts\memused_process.ps1" "$ARG1$ $ARG2$ $ARG3$" # $StatusText = @{"0"="OK"; "1"="WARNING"; "2"="CRITICAL"; "3"="UNKNOW"} $Process = $args[0] $Warn = $args[1] $Crit = $args[2] $string # Path performance counter $counter = "\Process($Process)\Private Bytes" # Command to get performance counter $data = get-counter $counter # Query $string = $data.countersamples | format-list -property * | out-string -stream | select-string "CookedValue" # Get a numeric value without text "CookedValue :" $resraw = $string -replace '[a-z, ,:]','' # Get a round numeric value in Mega Bytes $rescooked = [math]::truncate($resraw / 1MB) # Control if($rescooked -gt $Crit) { $Status = 2 } elseif($rescooked -gt $Warn) { $status = 1 } else { $Status = 0 } #Perfdata $PerfData = "MemoryUsed=" + $rescooked + ";" + $Warn + ";" + $Crit # Print result write-host $StatusText["$Status"] "-" "$rescooked MB | $PerfData"