You could get the package list (packages deployed to the robot) and if there is no other packages installed other than the robot (ie a new host) then you could deploy the baseline probe packages.
This script does something similar and might be useful....
Just run it once a day or something
cheers
Rowan
-- script : auto package deploy
-- author : Nimsoft, Rowan Collis
-- desc : this script gets all the hubs and then for each hub, gets the robots and for each one
-- gets the list of installs and checks if there is no cdm (for example).
-- If so then deploy the package derived from the robotname
fname = "./AutoDeploy.log"
-- Creates/overwrites the file - only do once
--file.create (fname)
function check_package(package_name)
pds.putString(args,"name", package_name)
pds.putInt(args,"detail_level",1)
check,rc = nimbus.request(hubrobot.."/distsrv","archive_list",args)
max_ver = 0;package_found = false
if rc == NIME_OK then
if check.entry ~= nil then
for _, chk in pairs( check.entry) do
ver = tonumber (chk.version)
if ver > max_ver then
max_ver = ver
end
package_found = true
end
else
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." ERROR on Package Check on "..hubrobot.."/distsrv Package "..strPackage.." missing ".."\n")
print(" auto deployment script: Package "..strPackage.." not present in archive so no deployment possible")
end
else
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." ERROR on request archive_list to "..hubrobot.."/distsrv (error "..rc..")".."\n")
print ( " auto deployment script: ERROR on Package Check on "..hubrobot.."/distsrv Package "..strPackage.." (error "..rc..")")
end
end
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." ************************* Starting Auto Deploy Script *************************".."\n")
args = pds.create()
tblHub = nimbus.request("hub","gethubs")
for _,hub in pairs(tblHub.hublist) do
ctrUp = 0; ctrDown = 0; ctrRebuild = 0; ctrComError = 0; ctrPkgError = 0
printf("hub = %s",hub.addr)
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." hub is "..hub.addr.."\n")
hubrobot = "/"..hub.domain.."/"..hub.name.."/"..hub.robotname
if hub.status == 0
--and hub.domain == "rc-win7-dom"
then
tblRobots = nimbus.request(hub.addr,"getrobots",args,2)
if tblRobots ~= nil then
strDomain = tblRobots.domain
for _,robot in pairs(tblRobots.robotlist) do
printf(" %s",robot.name)
if robot.status == 0 then
newbuild = "yes"
addr = robot.addr.."/controller"
command = "inst_list_summary"
list,rc = nimbus.request(addr,command)
if rc ~= NIME_OK then
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." ERROR on request "..command.." to "..addr.." (error "..rc..")".."\n")
print("auto deployment script: ERROR on request "..command.." to "..addr.." (error "..rc..")")
newbuild = "error"; ctrComError = ctrComError + 1
else
for _,probe in pairs(list.pkg) do
if probe.name == "cdm" then
newbuild = "no"
end
end
if newbuild == "no" then
printf (" this is good"); ctrUp = ctrUp + 1
else
printf (" this is a rebuild")
strFP = mid(robot.name,7,5)
strPackage = "baseline_"..strFP
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Trying to deploy Package "..strPackage.." to "..robot.addr.."\n")
print ("package is ",strPackage)
--check package exists
check_package (strPackage)
--if package in archive then deploy
if package_found then
-- pds.putString(args,"package", strPackage)
-- pds.putString(args,"robot", robot.addr)
-- deploy,rc = nimbus.request(hubrobot.."/distsrv","job_add",args)
if rc == NIME_OK then
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Deployed Package "..strPackage.." Version "..max_ver.." to "..robot.addr.."\n")
printf ("deployed package %s to %s",strPackage,robot.addr)
ctrRebuild = ctrRebuild + 1
else
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." ERROR on request jobadd to "..hubrobot.."/distsrv (error "..rc..")".."\n")
print("auto deployment script: ERROR on request jobadd to "..hubrobot.."/distsrv (error "..rc..")")
end
else
ctrPkgError = ctrPkgError + 1
end
end
end
else
printf (" this robot is down")
ctrDown = ctrDown + 1
end
end
end
else
if hub.status == 0 then
printf (" this hub is possibly in a different domain")
else
printf (" this hub isn't running")
end
end
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Stats: Robots up:"..ctrUp.."\n")
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Stats: Robots down:"..ctrDown.."\n")
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Stats: Robots rebuilt:"..ctrRebuild.."\n")
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Stats: Robots Comm Error:"..ctrComError.."\n")
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Stats: Robots Packge Error:"..ctrPkgError.."\n")
end
file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." ************************* Finished Auto Deploy Script *************************".."\n")