Useful for Blackberry Queues, etc, where an individual User may have many messages Queued (as they are out of service range or device is turned off). In this case an individual data will not set off the alarm. The monitor will alarm when the majority of individuals are seeing an increase in Queued messages.
Arguments:
-OID to be walked
-SNMP Community < will not poll form Object/ monitor properties
-Threshold - Maximum Accepted value for OID's
Comments Welcome.
CODE
--name= "SNMPWalkMajority"
--date= "April 19, 2008"
Author = "Jazz Alyxzander Turner-Baggs"
VersionMaj = 1
VersionMin = 3
Description = "Returns False When The Majority of OID Instances are above a given Threshold"
----------------------------------------------------------------------------------------------------------
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor(Author)
Config:SetDescription(Description)
Config:SetMinBuildVersion(0)
Config:SetScriptVersion(VersionMaj, VersionMin )
Config:AddArgument("OID","OID to be walked. <do not include the instance identifier>",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Community String","",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Threshold","Minimum Accepted Value",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
function main()
--// ===========================================================================
--// Functions
--// ===========================================================================
--// ===========================================================================
--// Variables
--// ===========================================================================
--// Script Vars
debugOn = 0
iArgumentsRequired = 3
ERROR_STRING = "Possible Errors Detected"
SUCCESS_STRING = "OK"
--// Compare Vars
iProblemCount = 0
iTotalCount = 0
--// SNMP vars
SNMP = TLuaSNMP()
sOID = ".iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifIndex"
sCommunity = "public"
--// ===========================================================================
--// Initialize Script
--// ===========================================================================
--// Ensure Arguments are entered Correctly
if GetArgumentCount() ~= iArgumentsRequired then
SetExitStatus("Incorrect Number of Paramaters", false);
return
else
print("Load Var")
sOID = GetArgument(0)
sCommunity = GetArgument(1)
iMinVal = tonumber(GetArgument(2))
end
--// ===========================================================================
--// SNMP Query
--// ===========================================================================
SNMP:Open(sCommunity);
snmpResult = TLuaSNMPResult();
-- Loop Through OIDS and record the number that are above iMinVal
SNMP:BeginWalk(sOID);
repeat
snmpResult = SNMP:Walk(sOID);
sOID = snmpResult.m_sOID;
if debugOn == 1 then
print("Total: " .. iTotalCount .. " Problems: " .. iProblemCount )
print("OID: " ..snmpResult.m_sOID)
print("Data: " ..snmpResult.m_sData)
end
if snmpResult.m_sData ~= "" then
if tonumber(snmpResult.m_sData) > iMinVal then
iProblemCount = iProblemCount + 1
end
iTotalCount = iTotalCount + 1
end
until snmpResult.m_sOID == "";
--// ===========================================================================
--// Compare
--// ===========================================================================
-- If there are more than 50% errors Alarm.
if iTotalCount == 0 then
SetExitStatus("Error", false)
elseif iProblemCount > (iTotalCount / 2) then
SetExitStatus(ERROR_STRING, false)
else
SetExitStatus(SUCCESS_STRING, true)
end
--// ===========================================================================
--// ~~
--// ===========================================================================
end
--date= "April 19, 2008"
Author = "Jazz Alyxzander Turner-Baggs"
VersionMaj = 1
VersionMin = 3
Description = "Returns False When The Majority of OID Instances are above a given Threshold"
----------------------------------------------------------------------------------------------------------
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor(Author)
Config:SetDescription(Description)
Config:SetMinBuildVersion(0)
Config:SetScriptVersion(VersionMaj, VersionMin )
Config:AddArgument("OID","OID to be walked. <do not include the instance identifier>",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Community String","",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Threshold","Minimum Accepted Value",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
function main()
--// ===========================================================================
--// Functions
--// ===========================================================================
--// ===========================================================================
--// Variables
--// ===========================================================================
--// Script Vars
debugOn = 0
iArgumentsRequired = 3
ERROR_STRING = "Possible Errors Detected"
SUCCESS_STRING = "OK"
--// Compare Vars
iProblemCount = 0
iTotalCount = 0
--// SNMP vars
SNMP = TLuaSNMP()
sOID = ".iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifIndex"
sCommunity = "public"
--// ===========================================================================
--// Initialize Script
--// ===========================================================================
--// Ensure Arguments are entered Correctly
if GetArgumentCount() ~= iArgumentsRequired then
SetExitStatus("Incorrect Number of Paramaters", false);
return
else
print("Load Var")
sOID = GetArgument(0)
sCommunity = GetArgument(1)
iMinVal = tonumber(GetArgument(2))
end
--// ===========================================================================
--// SNMP Query
--// ===========================================================================
SNMP:Open(sCommunity);
snmpResult = TLuaSNMPResult();
-- Loop Through OIDS and record the number that are above iMinVal
SNMP:BeginWalk(sOID);
repeat
snmpResult = SNMP:Walk(sOID);
sOID = snmpResult.m_sOID;
if debugOn == 1 then
print("Total: " .. iTotalCount .. " Problems: " .. iProblemCount )
print("OID: " ..snmpResult.m_sOID)
print("Data: " ..snmpResult.m_sData)
end
if snmpResult.m_sData ~= "" then
if tonumber(snmpResult.m_sData) > iMinVal then
iProblemCount = iProblemCount + 1
end
iTotalCount = iTotalCount + 1
end
until snmpResult.m_sOID == "";
--// ===========================================================================
--// Compare
--// ===========================================================================
-- If there are more than 50% errors Alarm.
if iTotalCount == 0 then
SetExitStatus("Error", false)
elseif iProblemCount > (iTotalCount / 2) then
SetExitStatus(ERROR_STRING, false)
else
SetExitStatus(SUCCESS_STRING, true)
end
--// ===========================================================================
--// ~~
--// ===========================================================================
end
/jAzz