<# Name: Check_psmsmq.ps1 Version: 1 Author: Tom Unsworth (mail@tomunsworth.net) Comment: This script was disgned to monitor MSMQs through powershell and intigrated .Net. Feel free to update and make suggestions. Usage Add the below line into the NSC.ini file under the ‘[NRPE Handlers]’ header check_psmsmq=cmd /c echo scripts\Check_psmsmq.ps1 $ARG1$ ; exit($lastexitcode) | powershell.exe -command - Nagios Command $USER1$/check_nrpe -p 5666 -t 30 -H $HOSTADDRESS$ -c check_psmsmq -a ".\\private$$\\$ARG1$ $ARG2$ $ARG3$" $ARG1$ = Queue Name $ARG2$ = Warning Level $ARG3$ = Critical Level The minimal permissions needed for the script to monitor a queue are ‘Receive Messages, Peek Messages, Receive Journal Message, Delete Message, Delete Journal Message” #> Param( [String] $QueueName = $(Throw "Must specify Queuename"), [long] $Warn = $(Throw "Must specify warning threshold"), [long] $Crit = $(Throw "Must Specify Critical Threshold")) add-type -assemblyName "System.Messaging" $QueuesFromDotNet = new-object System.Messaging.MessageQueue $QueueName $Queuelength = $QueuesFromDotNet.GetAllMessages().Length if ($Queuelength -ge $Crit) { write-output "Current Messages in $($QueueName) queue : $($Queuelength) Critcal" write-output "|MessagesinQueue=$($Queuelength);$($Warn);$($Crit);0;100" ; exit(2) } elseif ($Queuelength -ge $Warn) { write-output "Current Messages in $($QueueName) queue : $($Queuelength) Warning" write-output "|MessagesinQueue=$($Queuelength);$($Warn);$($Crit);0;100" ; exit(1) } elseif ($Queuelength -lt $Warn + $Crit) { write-output "Current Queue Length $($Queuelength)" write-output "|MessagesinQueue=$($Queuelength);$($Warn);$($Crit);0;100" ; exit(0) } else {write-output An Unkown Error occured, please check the script and try again; exit(3)}