Using the SDK, I would like to reset an alarm that has been triggered on a VM - equivalent to a VIC user right-clicking on the alarm and choosing "reset to green". Acknowledging it is easy, but I'd like it to be removed completely and can't see any way to do so via the API. I don't want to affect other triggered instances of the same alarm on different VMs, so disabling/enabling or recreating the alarm isn't an option.
Any way to do this that I'm just missing?
Thanks,
Brian
This blog post should answer all your questions including a sample script - http://www.virtuallyghetto.com/2010/10/how-to-ack-reset-vcenter-alarm.html
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware VCP3,4
VMware VCAP-DCA4
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Are you asking about AcknowledgeAlarm ? That is how you reset or ack and alarm using the vSphere Client and this is the method to do so.
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
No, AcknowledgeAlarm does not achieve what I'm looking for.
Using the VIC client, a user may do two things:
A) Acknowledge alarm - this greys out the alarm, but leaves it displayed. The VM still has the alarm icon in the tree.
B) Reset alarm to green - this completely removes the alarm from the list of triggered alarms for the VM. The VM no longer has the alarm icon in the tree.
I'd like to do the equivalent of "reset alarm to green" - I want the alarm to no longer display in the list of alarms, and I want no warning icon beside the VM in the tree.
Yes, I just tried this on the vSphere Client and since I was not able to search for the method in the vSphere API documents, I thought I fire up Onyx to see exactly what method is being called, it looks like the method that is used is SetAlarmStatus which is actually not exposed in the public API.
You'll see the following message when reset the alarm to green:
WARNING: Method 'SetAlarmStatus' is not available in the public API.
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
That confirms what I've seen - I suspect there's no way to do it, though I'm waiting for a response from VmWare support. Thanks for checking.
Speaking of AcknowledgeAlarm.... do you see anything wrong with my code? Alerts are not behaving.
I'm trying to use AcknowledgeAlarm and the sdk tells me that the method does not exist for Alarm Manager (well I think that is what it is telling me)
array(3) {
=>
string(15) "ServerFaultCode"
=>
string(0) ""
=>
array(1) {
=>
array(2) {
=>
string(12) "AlarmManager"
=>
string(16) "AcknowledgeAlarm"
}
}
}
Here is my function. $this->ns is "urn:vim25" and $this->vmware is a nuSOAP client object.
function AcknowledgeAlarm($entity, $alarm)
{
$soapmsg[] = new soapval('_this',false,$this->vimsession,false,false,array('type'=>'AlarmManager'));
$soapmsg[] = $alarm;
$soapmsg[] = $entity;
$result = $this->vmware->call('AcknowledgeAlarm',$soapmsg,$this->ns);
if(is_array($result) && isset($result))
{
$this->fault = $result;
CLog::Error("Fault during AcknowledgeAlarm: ",var_export($result,true));
return false;
}
$this->fault = false;
return true;
}
This blog post should answer all your questions including a sample script - http://www.virtuallyghetto.com/2010/10/how-to-ack-reset-vcenter-alarm.html
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware VCP3,4
VMware VCAP-DCA4
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
This is essentially what I did after using Onyx to check out the VI client behaviour - extended the WSDL to include the SetAlarmStatus functionality.
There turned out to be a solution that worked out better than using (undocumented APIs) - the custom alarm that I defined used an event based trigger to set the alarm. A second trigger, based on a different event, sets the alarm status back to "Normal". Reseting the alarm is done by posting the event.
Here is some code (in Java) that will create a user defined alarm on datastores that will trigger and reset itself based on events:
try {
OrAlarmExpression orExp = new OrAlarmExpression();
AlarmExpression[] expressions = new AlarmExpression[2];
orExp.setExpression( expressions );
EventAlarmExpression alarmExp = new EventAlarmExpression();
alarmExp.setEventType( "EventEx" );
alarmExp.setEventTypeId( "unique.userdefined.FailureKey" );
alarmExp.setObjectType( "Datastore" );
alarmExp.setStatus( ManagedEntityStatus.red );
expressions[0] = alarmExp;
EventAlarmExpression alarmClearExp = new EventAlarmExpression();
alarmClearExp.setEventType( "EventEx" );
alarmClearExp.setEventTypeId( "unique.userdefined.FailureKeyClear" );
alarmClearExp.setObjectType( "Datastore" );
alarmClearExp.setStatus( ManagedEntityStatus.green );
expressions[1] = alarmClearExp;
AlarmSpec spec = new AlarmSpec();
spec.setDescription( "A user defined failure has occurred" );
spec.setEnabled( true );
spec.setExpression( orExp );
// this is the string that the user will see in the alarm tables
spec.setName( "User Defined Failure" );
// To ensure that all items of that type see it, you'll want to set it on the root folder
vmwareService.createAlarm( serviceContent.getAlarmManager(), serviceContent.getRootFolder(), spec );
} catch( Throwable t ) { t.printStackTrace(); }
Now, to trigger the alarm, do something like:
ManagedObjectReference eventMgrRef = serviceContent.getEventManager();
EventEx event = new EventEx();
event.setUserName( "vcUsername" );
// This must be set or the event will not be posted against the datastore...
DatastoreEventArgument dsArg = new DatastoreEventArgument();
dsArg.setDatastore( datastoreManagedObjectReference );
// This name -must- be there or the event will fail...
dsArg.setName( "Datastore" );
event.setDs( dsArg );
//Set the chainId to 0 if the TaskInfo is not being passed,
//otherwise set it to the eventChainId property of the TaskInfo
event.setChainId( 0 );
event.setKey( 0 );
event.setCreatedTime( Calendar.getInstance() );
event.setFullFormattedMessage( "User Defined Failure Occurred" );
event.setMessage( "User Defined Failure Occurred");
event.setEventTypeId( "unique.userdefined.FailureKey");
event.setSeverity( EventEventSeverity._error );
try {
vmwareService.postEvent( eventMgrRef, event, null );
} catch( Throwable t ) { t.printStackTrace(); }
To Clear the alarm, just change a few items from above, and call postEvent again:
event.setEventTypeId( "unique.userdefined.FailureKeyClear" );
event.setSeverity( EventEventSeverity._info );
Note that the alarm creation should only be called once, and then the events handle all the triggering / clearing after that.