Page 1 of 1

Can Nagios pull logs from MSMQ queue?

Posted: Thu Jun 19, 2014 4:35 pm
by steph280
Greetings, my first post here. I'm looking at the possibility of using Nagios to monitor an application platform. One criteria is the ability for Nagios to read the MSMQ queue, and generate alarms if it recognizes any key words such as "XXXX Application down."

I did some search and only came up with check_msmq.vbs module, but it seems that's only used for counting how many messages are in queue.

Any suggestion is greatly appreciated.

Stephen

Re: Can Nagios pull logs from MSMQ queue?

Posted: Fri Jun 20, 2014 12:54 am
by chris.fixter
Assume you already know how to use check_msmq.vbs, you can use the following vbs with nsclient

Code: Select all

Option Explicit
Const MQ_RECEIVE_ACCESS = 1 
Const MQ_SEND_ACCESS = 2 
Const MQ_DENY_NONE = 0 
Const MQ_PEEK_ACCESS = 32

if WScript.Arguments.Count <> 2 then
	call help()
	wscript.quit(2)
end if


Dim SearchStr 
SearchStr = WScript.Arguments(1)
Dim FormatName
FormatName = "DIRECT=OS:localhost\private$\" & WScript.Arguments(0)
Dim MSMQQueueInfo 
Set MSMQQueueInfo = CreateObject("MSMQ.MSMQQueueInfo")
MSMQQueueInfo.FormatName = FormatName
Dim MSMQQueue
Set MSMQQueue = CreateObject("MSMQ.MSMQQueue")
Dim MSMQMessage
Set MSMQMessage = CreateObject("MSMQ.MSMQMessage")


Set MSMQQueue = MSMQQueueInfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
Dim message
If getMSMQCount(FormatName)>0 then
	Set message = MSMQQueue.PeekCurrent()
	if instr(message.body, SearchStr)>0 then 
		wscript.echo "CRITICAL - String (" & SearchStr & ") found in MSMQ"
		wscript.quit(2)
	end if
	Do While (Not message Is Nothing) and (getMSMQCount(FormatName)>0)
		if instr(message.body, SearchStr)>0 then 
			wscript.echo "CRITICAL - String (" & SearchStr & ") found in MSMQ"
			wscript.quit(2)
		end if
		Set message = MSMQQueue.PeekNext(False, true, 0)
	Loop
	wscript.echo "OK - String (" & SearchStr & ") NOT found in MSMQ"
	wscript.quit(0)
end If

function getMSMQCount(qformat)
	dim MSMQApp, Mgmt
	Set MSMQApp = CreateObject("MSMQ.MSMQApplication")
	Set Mgmt = CreateObject("MSMQ.MSMQManagement")
	Mgmt.Init ,,qFormat
	getMSMQCount = CLng(Mgmt.MessageCount)
end function

Function Help()
  Wscript.Echo "Usage: search_msmq.vbs [queuename] [search string]"
End Function

Re: Can Nagios pull logs from MSMQ queue?

Posted: Fri Jun 20, 2014 12:56 pm
by lmiltchev
@steph280
Did you try the chris.fixter's solution? Let us know if you get stuck with NSClient++.

Re: Can Nagios pull logs from MSMQ queue?

Posted: Tue Jun 24, 2014 12:18 pm
by steph280
I have not had a chance to set that up yet since we don't have a test box in the live environment yet. I have no experience with visual basic so there will be some learning curve. I'm sure I will have a bunch more questions during the setup process.

Thanks again for the help!

Re: Can Nagios pull logs from MSMQ queue?

Posted: Tue Jun 24, 2014 12:47 pm
by tmcdonald
We'll keep this thread open for a bit in case you have any questions about the script or nsclient.