ossiejhmoore

OSCript : List All Agents

Jul 26th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. function void ListAllAgentIds()
  2.  
  3.     Object  osAgents
  4.     Object  osNext
  5.     String  path
  6.     List    children
  7.     List    descendants
  8.     Integer i
  9.     List    usedIds = {}
  10.    
  11.     //get root "Agents" node by looping through the children
  12.     //of AgentController's parent and finding the "Agents" ospace
  13.     //(probably a better way do do this)
  14.     children = OS.Children( $llagent.AgentController.OSParent )
  15.     for i = 1 to Length(children)
  16.         osNext = children[ i ]
  17.         if (osNext.OSName == "Agents")
  18.             osAgents = osNext
  19.             children = Undefined
  20.             break
  21.         end
  22.     end
  23.    
  24.     //build list of all agents with valid agent id.
  25.     //might as well echo the id and full path to the agent
  26.     //while i am at it.
  27.     descendants = $kernel.OSpaceUtils.GetDescendants(osAgents)
  28.     for i = 1 to Length(descendants)
  29.         osNext = descendants[ i ]
  30.         if ((IsDefined(osNext.fAgentId)) && (osNext.fAgentId != 0))
  31.             usedIds = {@usedIds, osNext.fAgentId}
  32.             echo(osNext.fAgentId, " ", GetAgentPath(osNext))
  33.         end
  34.     end
  35.     descendants = Undefined
  36.    
  37.     //sort used agent ids
  38.     usedIds = List.Sort(usedIds)
  39.    
  40.     //print out used ids
  41.     for i = 1 to Length(usedIds)
  42.         echo(usedIds[ i ])
  43.     end
  44.  
  45. end
  46.  
  47. function String GetAgentPath(Object osAgent)
  48.  
  49.     Object osNext
  50.     String path
  51.     Boolean done
  52.    
  53.     osNext = osAgent
  54.     done = false
  55.     while(!done)
  56.         done = (osNext.OSName == "Agents")
  57.         if (Length(path) > 0)
  58.             path = Str.Format("%1:%2", osNext.OSName, path)
  59.         else
  60.             path = osNext.OSName
  61.         end
  62.         osNext = osNext.OSParent
  63.     end
  64.     return path
  65. end
Advertisement
Add Comment
Please, Sign In to add comment