Hi,
I am using VIJAVA API to develop application. Using following program I tried to post vCenter event. On execution, I can see the event does get posted and is visible in vSphere Tasks and Events/Events panel. The issue is with labels. I am putting the snap regarding how it looks.
This is not what expected. I need properly formatted text.
Following is code. Can anyone help me what's wrong with it.
-----------------------------------------------------------------------------------------
public class CreateCustomTask
{
final static String EXTENSION_KEY = "DoubleCloud";
public static void main(String[] args) throws RemoteException, MalformedURLException, InterruptedException
{
ServiceInstance si = new ServiceInstance(new URL("https://vCenter IP address/sdk/vim"), "Administrator", "password", true);
ManagedObjectReference vm = new ManagedObjectReference();
vm.type = "VirtualMachine";
vm.val = "vm-827";
ExtensionManager em = si.getExtensionManager();
if(em.findExtension(EXTENSION_KEY)==null)
{
em.registerExtension(createExtension());
}
EventManager eventManager = si.getEventManager();
ExtendedEvent myEvent = new ExtendedEvent();
myEvent.setChainId(0);
myEvent.setKey(0);
myEvent.setCreatedTime(new GregorianCalendar());
myEvent.setFullFormattedMessage("This is my first event message");
myEvent.setUserName("Admin_2");
myEvent.setMessage("This is my first event message");
myEvent.setEventTypeId("AcmeBackupEvent");
myEvent.setManagedObject(vm);
eventManager.postEvent(myEvent, null);
System.out.println("posting my event done");
si.getServerConnection().logout();
}
private static Extension createExtension()
{
Extension extension = new Extension();
Description desc = new Description();
desc.setLabel("DoubleCloud");
desc.setSummary("A sample extension with a new type of task.");
ExtensionEventTypeInfo eeti = new ExtensionEventTypeInfo();
eeti.setEventID("AcmeBackupEvent");
KeyValue kv1 = new KeyValue();
kv1.setKey("event.AcmeBackupEvent.category");
kv1.setValue("warning");
KeyValue kv2 = new KeyValue();
kv2.setKey("event.AcmeBackupEvent.label");
kv2.setValue("Acme backup event");
KeyValue kv3 = new KeyValue();
kv3.setKey("event.AcmeBackupEvent.fullFormat");
kv3.setValue("Acme backup virtual machines on host.");
KeyValue kv4 = new KeyValue();
kv3.setKey("event.AcmeBackupEvent.summary");
kv3.setValue("Acme backup virtual machines summary.");
ExtensionResourceInfo eri = new ExtensionResourceInfo();
eri.setLocale("en");
eri.setModule("event");
eri.setData(new KeyValue[] {kv1, kv2, kv3, kv4});
extension.setDescription(desc);
extension.setKey(EXTENSION_KEY);
extension.setVersion("1.0.0");
extension.setLastHeartbeatTime(Calendar.getInstance());
extension.setCompany("Acme Inc.");
extension.setEventList(new ExtensionEventTypeInfo[] { eeti });
extension.setResourceList(new ExtensionResourceInfo[] { eri});
return extension;
}
Thanks,
Prithvee.