Rank: Contributing Member Groups: Member
Joined: 9/12/2009 Posts: 17 Location: N/A
|
I am looking for a way to update or create scoped registry variable values from the command line. I figure that a groovy script is the answer. In looking at the RegistryServiceInterface package, I see that the setRegistryValues(java.util.List<RegistryValueInterface> rv) method holds the key in accomplishing this. The parameter looks like an array object of variable=value pairs, which works for me. So, here is what I would like the groovy script to do:
1. It uses the script parameters hostname and variable name and searches for the scoped variable. 2. The third script parameter, variable value, is then used to update the scoped registry variable. I am thinking that the setRegistryValues method can be employed here. 3. But if no registry value parameter is provided, it will simply delete the scoped registry variable (leaving the global registry intact).
Is setRegistryValues the appropriate method for this? Has anyone created a script that achieves this and wouldn't mind posting it here?
I am using both 5.2.5 and 5.5.4 versions.
Thanks.
|
Rank: Member Groups: Member
Joined: 4/30/2008 Posts: 7 Location: UK
|
Hello
I can help with part of your request.
This script reads from an input of host,value and updates a registry variable called "SupportedBy" scoped to the host value.
regSvc = server["RegistryService"] querySvc = server["QueryService"] //read from the input file given as an argument
inputFile = args[1]
//parse the input file, should be in the style of <host>,<target>
testOut = new StringBuilder();
new File(inputFile).eachLine {line -> lineArray = line.toString().split(",")
host = lineArray[0] target = lineArray[1] queryString = "Host where name = '%" + host + "%'" output = querySvc.queryTopologyObjects(queryString) hostId = output.toArray()[0].getUniqueId()
regVariable = regSvc.getRegistryVariable('SupportedBy') values = regVariable.getRegistryValues() topologyValue = regVariable.createTopologyObjectRegistryValue(hostId) values.add(topologyValue) topologyValue.setDefaultValue(target)
regSvc.saveRegistryVariable(regVariable)
}
|
Rank: Contributing Member Groups: Member
Joined: 9/12/2009 Posts: 17 Location: N/A
|
Wow, thanks Chris. Haven't check back in a while but am pleased to see your response. I will give this a try.
One question: How then would you delete the scoped registry variable (leaving the global registry intact)?
Thanks for sharing!
|