DX Unified Infrastructure Management

  • 1.  LUA to automate the Pacakges installation

    Posted Nov 02, 2016 07:11 AM

    Hello,

     

    Is there way in LUA to detect the newly added robots on a Hub and install the packages automatically?

     

    I was using request.cfg file and installing the packages, wondering if it's can be done using LUA.

     

    Thanks



  • 2.  Re: LUA to automate the Pacakges installation

    Broadcom Employee
    Posted Nov 02, 2016 10:10 AM

    I can not think of a way to do this as there is no new robot flag that is stored anyplace.

    I would suggest you look at the new MCS in 8.47 as this is the only thing that I think comes close.

     

    With LUA you would have to store the previous runs robot list in a file and parse it each time you check and then add new ones to it I would think to manage the list of robots.



  • 3.  Re: LUA to automate the Pacakges installation

    Posted Nov 02, 2016 10:36 AM

    Thanks for the response.


    We are actually running in 8.31, no plans to get to 8.47 soon. that's why i was looking for a way to get this done via LUA.



  • 4.  Re: LUA to automate the Pacakges installation

    Broadcom Employee
    Posted Nov 02, 2016 11:00 AM

    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")



  • 5.  Re: LUA to automate the Pacakges installation

    Posted Nov 02, 2016 11:40 AM

    Thanks a lot. Will modify it as per my requirement and try,



  • 6.  Re: LUA to automate the Pacakges installation

    Posted Nov 02, 2016 01:58 PM

    What about looking the following objects to aid in locating recently deployed robots.

     

    Query via LUA or DB query

    • Robot creation time based on created by date criteria. If done through LUA would need to loop through each hub.
    • Leverage user tag to denote new object pending onboarding.
      • Include default user tag for pending onboarding via robot-vars during robot installation. Can ease this deployment via including said robot files off any nimsoft root directory\install and retrieve robot and installation file through installation script via wget.
    • Deploy packages via LUA or request.cfg.


  • 7.  Re: LUA to automate the Pacakges installation

    Posted Nov 05, 2016 03:17 PM

    Also consider that once you have this scripted you can use callbacks to dirscan to test if a file/directory exists (install sqlserver package if you find SQL server installed for instance), or the get_file callback to the controller - handy if you have a config file on the destination system that might have usernames or passwords you could put into the configs with the controller callback  probe_config_set. Or if you retrieve the list of installed packages, you can compare the versions and automate the update process.

     

    -Garin