Can Nagios pull logs from MSMQ queue?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
steph280
Posts: 6
Joined: Fri Jun 06, 2014 5:15 pm

Can Nagios pull logs from MSMQ queue?

Post 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
chris.fixter
Posts: 22
Joined: Wed Jun 18, 2014 4:15 am

Re: Can Nagios pull logs from MSMQ queue?

Post 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
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Can Nagios pull logs from MSMQ queue?

Post by lmiltchev »

@steph280
Did you try the chris.fixter's solution? Let us know if you get stuck with NSClient++.
Be sure to check out our Knowledgebase for helpful articles and solutions!
steph280
Posts: 6
Joined: Fri Jun 06, 2014 5:15 pm

Re: Can Nagios pull logs from MSMQ queue?

Post 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!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Can Nagios pull logs from MSMQ queue?

Post by tmcdonald »

We'll keep this thread open for a bit in case you have any questions about the script or nsclient.
Former Nagios employee
Locked