Contents
If the queue count exceeds the threshold the script will log “ALERT:” followed by a description of the problem. That makes it very easy to detect this condition using a standard notification rule.
There are two examples given of calling this function. If no arguments are given then the script defaults to the current channel name and will raise an alert if the channel count exceeds 100.
These defaults can be overridden which is what the second example shows:
Here is the code to copy:
require 'queuemon' function main() -- Using default parameters queuemon.checkQueue() -- Setting the channel name and count explicitly queuemon.checkQueue{channel = '<your channel name>', count = 10000} end
The queuemon module makes use of this module called iguanaconfig:
-- This module does a lazy load of the Iguana Configuration file - it only loads the file once iguanaconfig={} -- We open the configuration file once at compile time local F = io.open('IguanaConfiguration.xml', 'r') local C = F:read('*a') F:close() -- best practice to close (open filehandle can prevent Iguana updating config file on Win machines) function iguanaconfig.config(A) return xml.parse{data=C} end
The iguanaconfig module just loads the IguanaConfiguration.xml file and returns it as a XML document. It’s extremely useful for all sorts of things.
In this case we use it to pull back the port number that the Iguana instance is listening on. The source to the queuemon module is here:
require("node") require("iguanaconfig") queuemon = {} local function trace(a,b,c,d) return end local function CheckChannel(Chan, Count, Name) if Chan.Name:nodeValue() == Name then local QC = tonumber(Chan.MessagesQueued:nodeValue()) trace(QC) if QC > Count then print('ALERT:\n Channel '..Name..' has '..QC..' messages queued.') end end end function queuemon.checkQueue(Param) -- We default to a queue count of 100 if not Param then Param = {} end if not Param.count then Param.count = 100 end if not Param.channel then Param.channel= iguana.channelName() end local url = 'http://localhost:'.. iguanaconfig.config().iguana_config.web_config.port..'/status.html' trace(url) -- We need a user login here. Best to use a user with few -- permissions. local S = net.http.get{url=url, parameters={UserName='admin',Password='password', Format='xml'}, live=true} S = xml.parse{data=S} for i = 1, S.IguanaStatus:childCount('Channel') do local Chan = S.IguanaStatus:child("Channel", i) CheckChannel(Chan, Param.count, Param.channel) end return "Checking queue of "..Param.channel.. ' is less than '..Param.count end
This module uses the web monitoring URL to pull back the XML summary and parses it to find the queue counts for the channel. In this case we are only selecting one channel to check the queue count but there is no reason we could not check all the channels or even parse a group of channels and only check the queue counts on that channel group.
If you would like to see this script extended in that manner please contact support at support@interfaceware.com.
Pingback: Auto-Generating Code for Easy Reporting and Alerts