How to extract Foglight Alarms from the command line or script editor using groovy script?
Run the following from the Foglight Management Server:
\bin\fglcmd -srv hostname -port 8080 -usr foguser -pwd fogpwd -cmd script:run -f exportAlarms.groovy > currentAlarms.csv
where exportAlarms.groovy looks like:import com.quest.nitro.service.alarm.*;
import com.quest.nitro.service.sl.interfaces.alarm.*;
topSvc = server.get("TopologyService");
almSvc = server.get("AlarmService");
rulSvc = server.get("RuleService");
def getAlarmProperties(alarm) {
def props = []
id = null
try {
id = alarm.getID();
}
catch (Exception e){
}
props.add(id == null ? "" : id);
ti = null
try {
ti = alarm.getTopologyObjectID()
}
catch (Exception e){
}
props.add(ti == null ? "" : ti);
props.add(alarm.getCreatedTime());
props.add(alarm.getIsCleared());
props.add(alarm.getSourceName());
props.add(alarm.getSeverity());
props.add("\""+alarm.getMessage()+"\"");
to = null
hostname = null;
agentname = null;
try {
to = topSvc.getObject(ti);
hostname = (to == null) ? null : to.get("monitoredHost/name");
agentname = (to == null) ? null : to.get("monitoringAgent/name");
}
catch (Exception e){
}
props.add(hostname == null ? "" : hostname);
props.add(agentname == null ? "" : agentname );
ri = null;
rule = null
try {
ri = alarm.getRuleID();
rule = (ri == null) ? null : rulSvc.getRule(ri);
props.add(rule == null ? "" : rule.getName());
}
catch (Exception e){
}
return props
}
////////////////////////
// get Data and Export
////////////////////////
alarms = almSvc.getCurrentAlarms();
//alarmCount=alarms.size();
def expAlarms = []
alarms.each{ _alarm ->
expAlarms.add(getAlarmProperties(_alarm))
}
// Build Result
StringBuffer buffer = new StringBuffer();
buffer.append("AlarmID,TopologyID,Created,Cleared?,Source,Severity,Message,Host,Agent,Rule\n");
expAlarms.each{m->
int i = 0;
m.each{k->
buffer.append((i>0?",":"")+k)
i++
}
buffer.append("\n")
}
return buffer
or it can run from the Foglight Script Editor.
AlarmID,TopologyID,Created,Cleared?,Source,Severity,Message,Host,Agent,Rule
ab3e41da-fe83-4d38-8e67-5a2611a3b7b2,e963e22c-74db-476a-967e-b46188f293bb,2022-07-22 12:13:14.148,false,DBSS - Process CPU Utilization,3,"Process CPU Utilization. The sqlservr.exe (101SQL2017) process is consuming 1.04% CPU.",101sql2017,101SQL2017,DBSS - Process CPU Utilization
NOTE: The information in the script(s) provided is known to work successfully; however, they have not been officially tested by our Quality Control. If any of these instructions are changed and/or incorrectly used, intentionally or unintentionally, this script becomes unsupported by our Support and Development. Support and Development recommend always making a backup of the current database prior to execution of any script(s) that may modify it. For customization of Foglight, please contact our Professional Services Organization.
The same content can be found on this Foglight community discussion.
© ALL RIGHTS RESERVED. Feedback Terms of Use Privacy Cookie Preference Center