Hi All,
I am trying to create custom event and when this events occurs i want to put the host in maintenance mode. I am trying to do something like this:
private static MethodAction createAction() {
MethodAction action = new MethodAction();
action.setName("EnterMaintenanceMode_Task");
MethodActionArgument argument = new MethodActionArgument();
argument.setValue(0);
action.getArgument().addAll(
Arrays.asList(new MethodActionArgument[] { argument }));
return action;
}
private static AlarmTriggeringAction createAlarmTriggerAction(
MethodAction methodAction) throws Exception {
AlarmTriggeringAction alarmAction = new AlarmTriggeringAction();
alarmAction.setYellow2Red(true);
alarmAction.setRed2Yellow(true);
alarmAction.setGreen2Yellow(true);
alarmAction.setYellow2Green(true);
alarmAction.setAction(methodAction);
return alarmAction;
}
private static EventAlarmExpression createEventAlarmExpression()
throws Exception {
EventAlarmExpression expression = new EventAlarmExpression();
expression.setEventTypeId("xyz1");
expression.setObjectType("HostSystem");
expression.setEventType("EventEx");
return expression;
}
private static AlarmSpec createAlarmSpec(AlarmAction action,
AlarmExpression expression) throws Exception {
AlarmSpec spec = new AlarmSpec();
spec.setAction(action);
spec.setExpression(expression);
spec.setName(alarm);
spec.setDescription("temp description");
spec.setEnabled(true);
return spec;
}
public void createEventAlarm(ManagedObjectReference host) {
try{
alarmMgr = serviceContent.getAlarmManager();
rootFolder = serviceContent.getRootFolder();
EventAlarmExpression expression = createEventAlarmExpression();
MethodAction methodAction = createAction();
AlarmAction alarmAction = createAlarmTriggerAction(methodAction);
AlarmSpec alarmSpec = createAlarmSpec(alarmAction, expression);
ManagedObjectReference alarm = _vimPort.createAlarm(alarmMgr, host, alarmSpec);
} catch (Exception e) {
System.out.println(e.fillInStackTrace());
}
}
Can someone point the issue here.
Regards,
Vaibhav