This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Groovy to import hosts for "MultiHostProcessMonitorAgent" agent

Hi

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,

Eneko

Parents
  • Hello,

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

    www.quest.com/.../using-the-configservice-api-to-setup-agent-properties-asps

    /*
    * 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.
    */
    ds=server.DataService
    // 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", "")
    }
    cs.saveConfig(SecondaryAgentConfig)

    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)
    SecondaryAgentConfig.appendRow(newrow)
    }
    }
    }
    cs.saveConfig(SecondaryAgentConfig)
Reply
  • Hello,

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

    www.quest.com/.../using-the-configservice-api-to-setup-agent-properties-asps

    /*
    * 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.
    */
    ds=server.DataService
    // 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", "")
    }
    cs.saveConfig(SecondaryAgentConfig)

    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)
    SecondaryAgentConfig.appendRow(newrow)
    }
    }
    }
    cs.saveConfig(SecondaryAgentConfig)
Children
No Data