How to use::
1. Create an 'Auto Login' account with access to all the counters you wish to use.
2. Create an object with an ip of your inm server, perhaps call it Applications.
3. Add a new monitor to that server, using this lua script.
It works for me, and I hope it will work for some of you too!
-- Update: Just modified caption on 'Object List' configuration as I noticed it said 'Monitor List' (from the screenshots I posted below).
-- Update 2: Just found a bug to do with agents. Seems I had been lucky all this time not running into it. It's fixed now.
-- Update 3: Posted V 1.1
Here's version 1.1:
CODE
-----------------------------------------------------------------
-- Name: Application.lua
-- Author: Geoff Bucar
-- Version: 1.1
-- Date: 2009-12-11
-----------------------------------------------------------------
function OnEnumerate(sFieldToEnum)
Enum = LuaScriptEnumResult()
if sFieldToEnum == "Secure Server" then
Enum:Add("Yes")
Enum:Add("No")
end
return Enum
end
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor("Geoff Bucar")
Config:SetDescription("This script checks a series of monitors for alarms, if there is one it raises the alarm.")
Config:SetMinBuildVersion(5391)
Config:SetScriptVersion(1,1)
Config:AddArgument("INM Port","INM Website Port",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Secure Server","Is INM running in Secure mode? (SSL)",LuaScriptConfigurator.ENUM_AVAIL + LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Auto Login User","INM Auto Login User with access to all Objects and Monitors you've listed.",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Object List","INM Object IDs seperated by a comma - Example: 10,11,12",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Monitor List","INM Monitor IDs seperated by a comma - Example: 15,20,25",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
-- Function to split strings, found online...
function split (s,t)
local l = {n=0}
local f = function (s)
l.n = l.n + 1
l[l.n] = s
end
local p = "%s*(.-)%s*"..t.."%s*"
s = string.gsub(s,"^%s+","")
s = string.gsub(s,"%s+$","")
s = string.gsub(s,p,f)
l.n = l.n + 1
l[l.n] = string.gsub(s,"(%s%s*)$","")
return l
end
-- This is the entry point
function main()
-- Gather Arguments
iINMPort = tonumber(GetArgument(0));
sINMSecure = GetArgument(1);
bINMSecure = false;
if sINMSecure == "Yes" then
bINMSecure = true;
end
sINMUser = GetArgument(2);
sObjects = GetArgument(3);
aObjects = split(sObjects,',');
iTotalObjects = table.getn(aObjects);
sAgents = GetArgument(4);
aAgents = split(sAgents,',');
iTotalAgents = table.getn(aAgents);
bNoErrors = true;
bAgentFound = false;
sStatusString = "Application components have the following status:\n";
-- Loop through each Object
for iObject=1,iTotalObjects do
iCurrentObject = aObjects[iObject]
iAgentCount = 0;
-- Connect to HTTP and get XML
http = TLuaHTTPClient()
iRet = http:Connect(iINMPort,bINMSecure,'','')
if iRet ~= 0 then
iRet = http:Get("/extract.xsi?cmd=object_xml&user=" .. sINMUser .. "&id=" .. iCurrentObject)
xmlContent = http:GetContent(iRet)
--print(xmlContent)
end
-- Load into XML Reader
Reader = TLuaXMLReader();
iRet = Reader:FromXML(xmlContent);
if iret == false then
SetExitStatus("Failed to parse XML",false)
return;
end
-- Select Object
Object = Reader:FindNode("INM_OBJECT",Reader:GetRootNode())
if Object:IsValid() == false then
SetExitStatus("Failed to find XML Object",false)
return;
end
-- Select First Agent
Agent = Object:FindChildNode("INM_AGENT",iAgentCount)
if Agent:IsValid() == false then
SetExitStatus("Failed to find XML Agent",false)
return;
end
ObjectName = Object:FindChildNode("NAME",0);
sObjectName = ObjectName:GetData();
-- Cycle through all Agents for this Object
while (Agent:IsValid() == true) do
-- Get Agent ID
AgentID = Agent:FindChildNode("ID",0)
iAgentID = AgentID:GetData()
-- Loop through Agent ID List
for iAgent=1,iTotalAgents do
-- If this agent is in the list then
if (iAgentID == aAgents[iAgent]) then
AgentName = Agent:FindChildNode("NAME",0);
sAgentName = AgentName:GetData();
LastOK = Agent:FindChildNode("LAST_OK_TEST",0);
sLastOK = LastOK:GetData();
AgentStatus = Agent:FindChildNode("STATUS",0);
sAgentStatus = AgentStatus:GetData();
AgentStatusString = Agent:FindChildNode("STATUS_STRING",0);
sAgentStatusString = AgentStatusString:GetData();
sOutputString = " [" .. sAgentStatus .. " - " .. sObjectName .. " - " .. sAgentName .. ": " .. sAgentStatusString .. " - Last OK at: " .. sLastOK .. "]\n";
sStatusString = sStatusString .. sOutputString;
-- Report if Agent is upset
if not (sAgentStatus == "OK") then
bNoErrors = false;
end
end
end
-- Move onto next Agent
iAgentCount = iAgentCount + 1;
Agent = Object:FindChildNode("INM_AGENT",iAgentCount)
end
end
-- Report status and exit
SetExitStatus(sStatusString,bNoErrors)
end
-- Name: Application.lua
-- Author: Geoff Bucar
-- Version: 1.1
-- Date: 2009-12-11
-----------------------------------------------------------------
function OnEnumerate(sFieldToEnum)
Enum = LuaScriptEnumResult()
if sFieldToEnum == "Secure Server" then
Enum:Add("Yes")
Enum:Add("No")
end
return Enum
end
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor("Geoff Bucar")
Config:SetDescription("This script checks a series of monitors for alarms, if there is one it raises the alarm.")
Config:SetMinBuildVersion(5391)
Config:SetScriptVersion(1,1)
Config:AddArgument("INM Port","INM Website Port",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Secure Server","Is INM running in Secure mode? (SSL)",LuaScriptConfigurator.ENUM_AVAIL + LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Auto Login User","INM Auto Login User with access to all Objects and Monitors you've listed.",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Object List","INM Object IDs seperated by a comma - Example: 10,11,12",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Monitor List","INM Monitor IDs seperated by a comma - Example: 15,20,25",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
-- Function to split strings, found online...
function split (s,t)
local l = {n=0}
local f = function (s)
l.n = l.n + 1
l[l.n] = s
end
local p = "%s*(.-)%s*"..t.."%s*"
s = string.gsub(s,"^%s+","")
s = string.gsub(s,"%s+$","")
s = string.gsub(s,p,f)
l.n = l.n + 1
l[l.n] = string.gsub(s,"(%s%s*)$","")
return l
end
-- This is the entry point
function main()
-- Gather Arguments
iINMPort = tonumber(GetArgument(0));
sINMSecure = GetArgument(1);
bINMSecure = false;
if sINMSecure == "Yes" then
bINMSecure = true;
end
sINMUser = GetArgument(2);
sObjects = GetArgument(3);
aObjects = split(sObjects,',');
iTotalObjects = table.getn(aObjects);
sAgents = GetArgument(4);
aAgents = split(sAgents,',');
iTotalAgents = table.getn(aAgents);
bNoErrors = true;
bAgentFound = false;
sStatusString = "Application components have the following status:\n";
-- Loop through each Object
for iObject=1,iTotalObjects do
iCurrentObject = aObjects[iObject]
iAgentCount = 0;
-- Connect to HTTP and get XML
http = TLuaHTTPClient()
iRet = http:Connect(iINMPort,bINMSecure,'','')
if iRet ~= 0 then
iRet = http:Get("/extract.xsi?cmd=object_xml&user=" .. sINMUser .. "&id=" .. iCurrentObject)
xmlContent = http:GetContent(iRet)
--print(xmlContent)
end
-- Load into XML Reader
Reader = TLuaXMLReader();
iRet = Reader:FromXML(xmlContent);
if iret == false then
SetExitStatus("Failed to parse XML",false)
return;
end
-- Select Object
Object = Reader:FindNode("INM_OBJECT",Reader:GetRootNode())
if Object:IsValid() == false then
SetExitStatus("Failed to find XML Object",false)
return;
end
-- Select First Agent
Agent = Object:FindChildNode("INM_AGENT",iAgentCount)
if Agent:IsValid() == false then
SetExitStatus("Failed to find XML Agent",false)
return;
end
ObjectName = Object:FindChildNode("NAME",0);
sObjectName = ObjectName:GetData();
-- Cycle through all Agents for this Object
while (Agent:IsValid() == true) do
-- Get Agent ID
AgentID = Agent:FindChildNode("ID",0)
iAgentID = AgentID:GetData()
-- Loop through Agent ID List
for iAgent=1,iTotalAgents do
-- If this agent is in the list then
if (iAgentID == aAgents[iAgent]) then
AgentName = Agent:FindChildNode("NAME",0);
sAgentName = AgentName:GetData();
LastOK = Agent:FindChildNode("LAST_OK_TEST",0);
sLastOK = LastOK:GetData();
AgentStatus = Agent:FindChildNode("STATUS",0);
sAgentStatus = AgentStatus:GetData();
AgentStatusString = Agent:FindChildNode("STATUS_STRING",0);
sAgentStatusString = AgentStatusString:GetData();
sOutputString = " [" .. sAgentStatus .. " - " .. sObjectName .. " - " .. sAgentName .. ": " .. sAgentStatusString .. " - Last OK at: " .. sLastOK .. "]\n";
sStatusString = sStatusString .. sOutputString;
-- Report if Agent is upset
if not (sAgentStatus == "OK") then
bNoErrors = false;
end
end
end
-- Move onto next Agent
iAgentCount = iAgentCount + 1;
Agent = Object:FindChildNode("INM_AGENT",iAgentCount)
end
end
-- Report status and exit
SetExitStatus(sStatusString,bNoErrors)
end