Intro
This is a topic that has been discussed many times but most of the scripts in the foglight community use an older version of the forge API which makes it pretty hard to access ASP information and looks complicated.
In this Document I'd like to share some snipets and Script that could be used in all groovy functions and allow you to automate agent setups in foglight.
ASPs (?)
Before we strat with the scripts I need to explain what ASPs are in Foglight. ASPs are Agent properties used to configure the Agents behaviour. You can see them in different Screens but mostely you'd like to go to them from the Agent Status Screen.
ASPs are seperated into primary ASPs and secondary ASPs. Primary ASPs is basically a private key-value list of simple settings which is only be used by an Agent at a time. Those settings are private to the Agents. An Agent may not have any specific configuration (like when you first create an agent) in this case the Agent will use a default set of primary ASPs.
Secondary ASPs are shared lists (Tables with multiple Columns and Rows) and shared between multiple Agent. Those are used to configure a behaviour that is similar in multiple Agents like collection intervals, Log File Filters, .... . Secondary ASPs are stored as references and there is a primary ASP setting (key-value) that holds this reference.
Working with primary ASPs
There are many starting point to work with primary ASPs but the most common use is to start with an Agent. You need the Agent ID which could be retrieved by the agent commands, the Agent Status Page or teh Data Model. I found it handy in most cases to use the Data Modell like this.
// find the agentID from the Topology Modell
def agentID = scope.monitoringAgent.agentID
Alternatively you could get the Agent ID from the commandline using
/foglight/bin/fglcmd.sh -cmd agent:list
Result:
Host: fgl563Env
ID: 1
Name: Monitor@localhost
Type: UnixAgent
Version: 5.6.5 (Build: 565-20120924-0906-b115)
Adapter ID: FglAM
Status: Active/Collecting data
Health State: OK
------------------------------------
Host: fgl563Env
ID: 2
Name: ag2
Type: UnixAgent
Version: 5.6.5 (Build: 565-20120924-0906-b115)
Adapter ID: FglAM
Status: Not active
Health State: OK
------------------------------------
Or using the following groovy Script
server.AgentService.findByName("YourAgentName")[0].id //assuming the Agent Name is unique
However you'll got your Agent Id. The next step is to get the Agent ASPs
def agentID = scope.monitoringAgent.agentID
def agent = server.AgentService.findById(agentID as String)
String namespace = agent.agentNamespace
String type = agent.typeId
def cfgS = server.ConfigService
def config = cfgS.getAgentInstancePrimaryAsp(namespace,type,agentID as String)
return config
This will access the ASP Configuration Object.
you might wondering what is actually stored in this Object so here's my "private" debug and dump snippet. I don't use this in real script but it's handy to quickly list all the fieldnames and current Values in the config.
if (field.type.toString() == "REF_OPTION") {
def secondary = config.getRef(field.name)
field.name + " : " + secondary.knownName + "(" + secondary.sharingName +")"
} else {
field.name + " : " + config.getString(field.name)
}
}.join("\n")
The following output is taken from a Host agent (UnixHost)
host : localhost
hostNameOverride : foglight-564
port : 22
topCpuCount : 5
topMemoryCount : 5
topIOCount : 5
useNativeCollector : 1
aggregateProcesses : 1
collectProcessDetails : 1
collectProcesses : 1
collectCPU : 1
collectDisk : 1
collectRAMDisks : 0
collectMemory : 0
collectNetwork : 1
collectMetrics : 1
collectSystemId : 1
useSudo : 0
sudoPath : /usr/bin/sudo
fglamCollectorConfig : new1(fglamCollectorConfig)
This is a key-value list of the primary ASP setting for this particular Host Agent. the last line show a secondary ASP which will be discussed in a following Document.
So let's change something ....
The good news is that you allready survived the most difficult part. Changing a primary ASP is easy once you got a hold on the config object.
Let's say I'd like to switch off CPU and memory monitoring on this Agents.
config.setValueByString("collectMemory","0")
config.setValueByString("collectCPU","0")
Changing ASP is an Transaction so it's important to call the ConfigService.save() methode once you're ready. This will tell Foglight that your changes are done and will update the ASP in the Foglight Repository. It will also tell the agent that his ASP have been changed and he needs to reload the new setings.