vRO Logging Day-2 Operations with Event Log EBS topic
vRA 7.x EBS is awesome !
While writing code, one should aspire to be as generic as possible, with simplicity being a key value – since it is not always possible to provide both simultaneously. this principal will meet us coders over-and-over. remember – Keep It Simple, Stupid! (or otherwise, KISS)
Sticking to this principle, I was trying to think about a generic way to log Day-2 operations in vRA, without being too specific to a type of request or setting up many EBS subscriptions for this customer request.
Here ‘EventLog Default Event’ EBS topic in vRA, Came to the rescue.
The description is not great, but on the Event Log Tab (Administration -> Events -> Event Logs) we can find clues that can help understand what event log entries exists and what filter to set-up.
Based on that data we can setup a notification policy. My focus was to find all successful day-2 operations to log all details,
So I have set-up the following subscription policy :
- Target Type – Equals – ResourceActionRequest
- Description – Contains – completed successfully
since the payload in this case is empty, we can use the request number, sent by vRA in __asd_targetResourceId to full request details, and even the target vm :
var client = cafeHost.createRestClient(vCACCAFEServicesEnum.CATALOG_SERVICE);
var result = client.get("consumer/requests?$filter=requestNumber eq '"+__asd_targetResourceId+"'");
var request = result.getBodyAsJson().content[0];
System.log(JSON.stringify(request));
Now, Dumping vm properties and request data was a breeze!
Putting it all together –
The workflow – Day-2 Logger
BONUS – The workflow includes the code to flatten a JSON structure, to contain only one level keys, so it may be conveniently dumped into a Properties or a flat CSV easily code found with the help of StackOverflow Here
Yaniv