VMware {code} Community
SergioBonilla
Contributor
Contributor

Custom events not formatting correctly with WSSDK 5.1

Hello,

I'm registering an extension using the VMware vSphere Web Services SDK. The custom tasks and faults I've defined are displayed correctly on the VMware vSphere Client, as well as the vSphere Web Client. The events I defined used to be displayed correctly in both, but when I converted my code from the 5.0 release to 5.1, they are no longer being shown correctly.

Instead of seeing something like, "Type: info" and "Description: This is the full format message", the event now looks something like, "Type: XXX Company.Product.CustomEvent.category not found XXX" and "Description: event.Company.Product.CustomEvent.fullFormat (Company.Product.CustomEvent)".

The code to register the extension is similar to the following, with some parts omitted, since the tasks and faults are working OK:

import com.vmware.vim25.*;

public static final String EXTENSION_KEY = "Company.Product";
public static final String CUSTOM_EVENT = EXTENSION_KEY + ".CustomEvent";

Extension extension = new Extension();

ExtensionEventTypeInfo customEventInfo = new ExtensionEventTypeInfo();
customEventInfo.setEventID(CUSTOM_EVENT);
extension.getEventList().add(customEventInfo);

ExtensionResourceInfo customEventResourceInfo = new ExtensionResourceInfo();
customEventResourceInfo.setLocale("en");
customEventResourceInfo.setModule("event");

KeyValue customEventCategory = new KeyValue();
customEventCategory.setKey(CUSTOM_EVENT + ".category");
customEventCategory.setValue("info");
customEventResourceInfo.getData().add(customEventCategory);

KeyValue customEventLabel = new KeyValue();
customEventLabel.setKey(CUSTOM_EVENT + ".label");
customEventLabel.setValue("This is the label");
customEventResourceInfo.getData().add(customEventLabel);

KeyValue customEventSummary = new KeyValue();
customEventSummary.setKey(CUSTOM_EVENT + ".summary");
customEventSummary.setValue("This is the summary");
customEventResourceInfo.getData().add(customEventSummary);

KeyValue customEventFormat = new KeyValue();
customEventFormat.setKey(CUSTOM_EVENT + ".fullFormat");
customEventFormat.setValue("This is the full format message");
customEventResourceInfo.getData().add(customEventFormat);


The main difference between this and my previous version of the extension is the change to Lists that I need to retrieve before adding objects, instead of adding array of objects.

The code I use to create the events looks similar to:

ExtendedEvent event = new ExtendedEvent();
event.setEventTypeId(CUSTOM_EVENT);
event.setManagedObject(moRef);
event.setUserName(user);
event.setChainId(taskInfo.getEventChainId());
event.setKey(0);
event.setMessage("This is a non-localized message");
event.setCreatedTime(xmlGregCal);

vimPort.postEvent(eventManagerMOR, event, taskInfo);


This part of the code has also changed a little from the 5.0 version of the SDK to the 5.1 version, such as the use of XMLGregorianCalendar for the created time.

I've tried prefixing the keys for the resource information with "event." but this didn't fix the problem. I didn't have to change much to get the custom tasks and faults to work with 5.1, but that doesn't seem to be the case with events. Does anyone know what other changes need to be made for events to be displayed correctly?

Thanks,

Reply
0 Kudos
8 Replies
CathyBr
Enthusiast
Enthusiast

Hi,

I'm very happy to have found this diskussion!  We've been pulling out our hair trying to find the way to define custom events for a few months now. (We're almost bald!).

There seems to be no docu on how to do this, so by trial an error, we've now reached the point where

you where when you asked the question.

Unfortunately ... there was never a reply to this discussion.

Can someone tell what needs to be done, so that we see a real text in the Description area (instead of only the EventID String?  And how we can define texts for "Event Type Description" and "Possible Causes"?

I assume these definitions must be made when the Extension is registered - like adding them to the

ExtensionResourceInfo like stated above, it doesn't seem to work as expected.

Does anyone have any info?

Thanks

Cathy

Reply
0 Kudos
rdey
Enthusiast
Enthusiast

Here is the code snippet for creating custom events in 5.1 and up ..

GregorianCalendar gregorianCalendar = new GregorianCalendar(); 

XMLGregorianCalendar xmlValue = null;

try {

        xmlValue = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);  

} catch (DatatypeConfigurationException e) {

    System.out.printf("newXMLGregorianCalendar Failed\n");

}

KeyAnyValue kav1 = new KeyAnyValue();

kav1.setKey("com.vmware.plugin.event.1235.category");

kav1.setValue("info");

           

KeyAnyValue kav2 = new KeyAnyValue();

kav2.setKey("com.vmware.plugin.event.1235.fullFormat");

kav2.setValue("VMware- Performing: Task HEALTH of NAS controller ctrl is unavailable");

KeyAnyValue kav3 = new KeyAnyValue();

kav3.setKey("com.vmware.plugin.event.1235.description");

kav3.setValue("VMware - Performing: Task HEALTH of NAS controller ctrl is unavailable");

EventEx vcEvent = new EventEx();

vcEvent.setEventTypeId("com.vmware.plugin.event.1235");

vcEvent.setChainId(0);

vcEvent.setKey(0);

vcEvent.setUserName(userName);

vcEvent.setCreatedTime(xmlValue);

vcEvent.getArguments().add(kav1);

vcEvent.getArguments().add(kav2);

vcEvent.getArguments().add(kav3);

Reply
0 Kudos
CathyBr
Enthusiast
Enthusiast

Many thanks rdey,

this got me a little closer..

My code still was not working correctly, so I copied and pasted your snipplet to mine and sent your event.

No I see (both for yours and mine) a text  in the "Description" part of the EventManager View (webClient),

but not what I expected.

So I modified the snipplet -  so that the kav3(.description) value is "VMware - Performing:description".

In the EventManagerView I see your event, but the

Description Column shows the text you defined for "fullFormat" (instead of description)

Type Column shows "error" (instead of "information")

I am working with vSphere Client V5.5ga.  Could it be that I am using an old version of the vim25?

Something just does not seem to match here.

And if I can bother you with some more questions.  The arguments you added to your event seem like

attributes which are defined in the class "EventDescriptionEventDetail" - am I correct?

I was thinking of defining my event details by creating an instance of that class, filling out the values and somehow add it to the EventManager.eventInfo list - is that possible? Or am I completely on the wrong track??

I don't understand the relationship between my custom event (EventEx) as you described above, and the ExtensionEventTypeInfo which I define when registering the extension. It has an eventId and an eventScheme.  So I thought that if I did the following:

1) Register my extension with

ExtensionEventTypeInfo.eventID="myplugin.event.1234"

ExtensionEventTypeInfo.eventTypeSchema = <EventType><eventTypeID>myplugin.event.1234</eventTypeID><description>my description</description><arguments><argument><name>var1</name><type>string</type></argument></arguments></EventType>

send a custom event as you did above

vcEvent.setEventTypeId("myplugin.event.1234");

my event has 1 argument,

KeyAnyValue key4 = new KeyAnyValue();

key4.setKey("var1");

key4.setVaue("abcd");

vcEvent.getArguments().add(key4);

and then I set my fullFormat string to "This is a custom {var1} event".

I expected to see an event with the Type of "info", the Description Column to show "my Event", and

the long description (in the detail area) to show

This is a custom abcd event.

But either I'm completely confused, or am just missing one or two things I haven't found yet.

Also after registering the event as show above (I can see it in the mob), I would have thought that when the user defines an Event Trigger alarm, he would see it in the list of defined events. But that doesn't seem to work either.

Lots of questions, I know, but thanks for any directions you could give me.

Cathy

Reply
0 Kudos
CathyBr
Enthusiast
Enthusiast

Hi,

I'm still trying to add definitions for our custom event.  I choose a predefined Event from the mob, and modeled my

Event Definition to match it.  For Example I choose the Login Succeeded Event from com.vmware.vim.eam.

Here's how its defined (as seen in the mob)

eventID = "com.vmware.vim.eam.login.succeded"

eventTypeSchema = "<EventType>

                                        <eventTypeID>com.vmware.vim.eam.login.succeeded</eventTypeID>

                                        <description>A user logged successfully into vSphere ESX Agent Manager</description>

                                        <arguments>

                                             <argument>

                                                  <name>user</name>

                                                  <type>string</type>

                                             </argument>

                                        </arguments>

                              </EventType>"

So I registered my plugin defining the following Event

eventID = "com.acme.model.events.MyEvent"

eventTypeSchema = "<EventType>

                                        <eventTypeID>com.acme.model.events.MyEvent</eventTypeID>

                                        <description> MyEvent </description>

                                        <arguments>

                                             <argument>

                                                  <name>user</name>

                                                  <type>string</type>

                                             </argument>

                                        <arguments>

                                   <EventType>

Then using the vim25, I found the EventDescriptionEventDetail definitions in the EventManager for the two events seen above.

1) The predefined Login Succeeded Event looks like this:

EventDescriptionEventDetail.category = "info"

EventDescriptionEventDetail.description = "Successful login to vSphere ESX Agent Manager"

EventDescriptionEventDetail.fullFormat = "com.vmware.vim.eam.login.succeeded|Successful login by  {user} into vSphere ESX Agent Manager"

EventDescriptionEventDetail.key = "EventEx"

2) My Event looks like this:

EventDescriptionEventDetail.category = event.com.acme.model.events.MyEvent.category

EventDescriptionEventDetail.description = com.acme.model.events.MyEvent

EventDescriptionEventDetail.fulFormat = com.acme.model.events.MyEvent|event.com.acme.model.events.MyEvent.fullFormat

EventDescriptionEventDetail.key = "ExtendedEvent"

It seems to me (just a speculation) that the EventManager was not able to resolve the information I defined.

I created an event class in my DataProvider

com.acme.model.events.MyEvent - and it extends the EventEx class - but it seems that the EventManager can't map

my class to the Extension information.

Using the MOB I viewed all the other things which were defined in the EAM Extension, but could not

find anything which would help me further..

Can someone please tell me how these things fit together?

thanks

Cathy

Reply
0 Kudos
VaibhavJain
Contributor
Contributor

Hi,

Were you able to solve this problem? I can see this issue as well with 5.1 WSSDK.

-Vaibhav

Reply
0 Kudos
CathyBr
Enthusiast
Enthusiast

No, unfortuately, my question was never answered

Reply
0 Kudos
HarshaG
Contributor
Contributor

Hi,


try - customEventResourceInfo.setLocale("en_US");

Regards,

Harsha

Reply
0 Kudos
yangot
Contributor
Contributor

hi, Cathy

Did you fix your problem?

- tigey

Reply
0 Kudos