Groovy to import hosts for "MultiHostProcessMonitorAgent" agent


I would like to be able to import a list of hosts to an agent of type "MultiHostProcessMonitorAgent", by a groovy script.

Could anyone give me a hint/snipet?

Thank you,


  • Hello,

    I was able to create a script based on the reference code published in the next very helpful article:

    * The script below is used to dynamically update the list of hosts that are configured in an agent of type "MultiHostProcessMonitorAgent",
    * so we can monitor automatically the Processes running on all the he Virtual Machines in our Virtual Environment.
    * The script can be triggered via a Schedule Driven rule.
    * The "MultiHostProcessMonitorAgent" agent has to be created before hand.
    // Replace with your "MultiHostProcessMonitorAgent" agent name
    def agentId = server.AgentService.findByName("Monitor@Windows_GENERIC_Processes")[0].id
    def agent = server.AgentService.findById(agentId as String)
    String namespace = agent.agentNamespace
    String type = agent.typeId
    def cs = server.ConfigService
    def AgentConfig = cs.getAgentInstancePrimaryAsp(namespace,type,agentId as String)
    def SecondaryAgentConfig = AgentConfig.getRef("multiHostConfig")
    def rows = SecondaryAgentConfig.getRows()

    // Delete all Rows by emptying the values
    rows.each() {row ->
    row.setValueByString("type", "")
    row.setValueByString("host", "")
    row.setValueByString("hostNameOverride", "")
    row.setValueByString("port", "")

    objs = #!VMWVirtualMachine where (osDisplayName like '%Windows%')#.getTopologyObjects()
    objs.each() {obj ->
    type = "Windows"
    host = obj.get("name").toLowerCase()
    hostNameOverride = host
    port = "-1"
    vmState = ds.retrieveLatestValue(obj, 'vmState')?.value
    if (vmState == "poweredOn") {
    // Blacklist VMs that we don't want to monitor
    if (host != "" && host != "") {
    newrow = SecondaryAgentConfig.prepareEmptyRow()
    newrow.setValueByString("type", type)
    newrow.setValueByString("host", host)
    newrow.setValueByString("hostNameOverride", hostNameOverride)
    newrow.setValueByString("port", port)