![]() ![]() |
Oct 29 2009, 07:33 PM
Post
#1
|
|
|
Power user ![]() ![]() ![]() Group: Power users Posts: 192 Joined: 17-May 07 Member No.: 958 |
Some people have asked for this on the wishlist, so I thought I would take a stab at it.
CODE -- Version: 4.0 -- Date: 2009-10-29 -- Description: Counts the number of instances of a process that are running -- Arguments: process name, minimum count, maximum count ---------------------------------------------------------------------------------------------------------- -- This function is called by INM to retrieve a script configuration function OnConfigure() -- The variable returned must be called "Config" so INM can find it. Config = LuaScriptConfigurator() -- Author. Config:SetAuthor("Kevin Prestage") -- Description. Config:SetDescription("Counts the number of instances of a process that are running") -- Minimum build version of INM, set to zero for if no specific build version is required. Config:SetMinBuildVersion(4.0) -- Script version (major/minor) Config:SetScriptVersion(1,0) -- A parameter configuration, add them in the order the script is extracting them. Config:AddArgument("Process Name","Enter the process name as it appears in task manager",LuaScriptConfigurator.CHECK_NOT_EMPTY) Config:AddArgument("Minimum Instance(s)","Monitor will go into alarm if the number of instance running falls below this number.",LuaScriptConfigurator.CHECK_NOT_EMPTY) Config:AddArgument("Minimum Instance(s)","Monitor will go into alarm if the number of instance running rises above this number.",LuaScriptConfigurator.CHECK_NOT_EMPTY) -- Set the entry point, this is the function called by INM Config:SetEntryPoint("main") -- Done with configuration, return the object return Config end -- This is the entry point function main() processname = GetArgument(0) min = tonumber(GetArgument(1)) max = tonumber(GetArgument(2)) ok = true result = "" count = 0 SetExitStatus("OK",true) --Query WMI for a list of all processes running on the machine. Query = TLuaWMIQuery(); b = Query:Execute("Select * from Win32_Process where Name = \"" .. processname .. "\""); --if the query failed, set the result. if (b == false) then result = "An error occurred querying WMI. " .. Query:GetErrorDescription(); else while (Query:NextInstance()) do count = count + 1 end if (count < min) then result = "The number of running instances is " .. count .. " which is less than " .. min ok = false elseif (count > max) then result = "The number of running instances is " .. count .. " which is more than " .. max ok = false else result = "The number of running instances is " .. count .. " which is between " .. min .. " and " .. max ok = true end end SetExitStatus(result,ok); end |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 31st July 2010 - 05:42 PM |