Disclaimer on this, its early and I'm a LUA hacker at best.
I used variables and functions incase you wanted to add other checks or features. It can pull the information from the triggered alarm. Also, you may need a pause of some sort between the starting and stopping of the service.
----Get information from alarm---
a = alarm.get()
----Variables--------------------
service = "CertPropSvc"
probe = "ntservices"
addr = "/"..a.domain.."/"..a.hub.."/"..a.robot.."/"..probe
function CheckServiceState(addr,service)
list_services = nimbus.request(addr, "list_services")
for k,v in pairs(list_services) do
if k == service then
for key,value in pairs(v) do
if key == "state" then
if value == "running" then
StopService(addr,service)
StartService(addr,service)
else
StartService(addr,service)
end
end
end
end
end
end
function StopService(addr,service)
args = pds.create()
pds.putString(args, "name", service)
req = nimbus.request(addr,"stop_service", args)
if req ~= nil then
print (service .. " successfully stopped")
else
print (service .. " failed to stop")
end
end
function StartService(addr,service)
args = pds.create()
pds.putString(args, "name", service)
req = nimbus.request(addr,"start_service", args)
if req ~= nil then
print (service .. " successfully started")
else
print (service .. " failed to start")
end
end
CheckServiceState(addr,service)