VMware Cloud Community
jesse_cohen
Enthusiast
Enthusiast

Trying to pull alarm actions and getting too much

I need to report on all current alarms in vcenter that have a send snmp action attached.  I can get the info but cannot seem to pull simply the action value.

I simplified the code as much as i could, but no matter how I navigate I can only get down to pulling too much info

var alarmManager = sdk.alarmManager;

var alarms = alarmManager.getAlarm();

for each (var alarm in alarms)

{

var actionName = alarm.info.name;

var actionInfo = alarm.info.action

if (actionInfo != undefined){

System.log(actionName);

actionAction= actionInfo.action;

System.log(actionAction);

}

}

I tried another .action (3) but that is undefined.

0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee

Something like the following?

var alarmManager = sdk.alarmManager;

var alarms = alarmManager.getAlarm();

for each (var alarm in alarms) {

  if (alarm.info.action != null && alarm.info.action.action != null) {

    for each (var ac in alarm.info.action.action) {

       if (ac instanceof VcAlarmTriggeringAction && ac.action instanceof VcSendSNMPAction) {

          System.log("Found alarm with SNMP action");

          System.log("    Alarm name: " + alarm.info.name);

          System.log("    SNMP action: " + ac.action);

          break; // next alarm

       }

    }

  }

}

0 Kudos