How to change Alarm Template assignment of an agent via groovy script?

I am automating our deployment of agents via the CLI but the Foglight-generated "mssql_cli_installer.groovy" script which creates the agents does not have a parameter to specify what Alarm Template a new agent should be assigned.  It creates the agents under whatever template is set as default.

So my next option is to run another script AFTER "mssql_cli_installer.groovy" which would change that assignment from the default template to something else.  Probably just passing in the agent name and Alarm Template name, I would think.

Can anyone assist?  Is there a function somewhere that does this?

Thanks!

Jeff

EDIT: 

In case this is useful for anyone, I created the 2 scripts below to handle moving an agent to a different template.

 

//Move DB Agent to new template.  Replace [TemplateNameHere] and [DBAgentNameHere]:

def topologyService = server["TopologyService"];
def queryService = server["QueryService"];
def alarmTemplateService = server["AlarmTemplateService"];

// get template
def almTemplate = alarmTemplateService.getByName("[TemplateNameHere]");

// add db agent to template
def query = "!TopologyObject where name = '[DBAgentNameHere]' and topologyTypeName = 'DBSS_Instance'";
def targetDBAgent = queryService.queryTopologyObjects(query);
alarmTemplateService.assignTargets(almTemplate,targetDBAgent);

//Move Host Agent to new template.  Replace [TemplateNameHere] and [HostNameHere]:

def topologyService = server["TopologyService"];
def queryService = server["QueryService"];
def alarmTemplateService = server["AlarmTemplateService"];

// get template
def almTemplate = alarmTemplateService.getByName("TemplateNameHere");

// add host agent to template
def query = "!TopologyObject where name = 'HostNameHere' and topologyTypeName = 'Host'";
def targetHostAgent = queryService.queryTopologyObjects(query);
alarmTemplateService.assignTargets(almTemplate,targetHostAgent);

Parents Reply Children
No Data