I need to create a workflow where it gives us details of user details who put the host in mm mode when we select a ESXi host. I got the event details when a host is selected but unable to filter out the mm mode details alone.
Try replacing the line
while ((taskPage = collector.readPreviousTasks(100)) != null)
with
while ((taskPage = collector.readNextTasks(100)) != null)
Could you show the code you have so far that fetches the event? I'm not quite sure what you mean by "filter out the mm mode details". Doesn't userName property of the event object contain the info you are looking for?
Hi Llian,
Yes it does, but we have lot of hosts and activites going on in different datacenters, we are trying to create a XaaS blueprint to just enter a host name to get the details of the person who kept the host in mm mode. I have the below function to get the details, but it doesn't work as expected.
function getEventLogs(hostIn){
try{
var sdk = hostIn.sdkConnection;
// Create TaskFilterSpecByEntity using moRef of vc:hostsystem
var spec = new VcTaskFilterSpecByEntity();
spec.entity = hostIn.reference;
spec.recursion = VcTaskFilterSpecRecursionOption.self; // Set recursion to self as only interested in this host object
// Create FilterSpec containing vm reference to filter
var filter = new VcTaskFilterSpec();
filter.entity = spec;
// Create collector and set it to the latest entry
var collector = sdk.taskManager.createCollectorForTasks(filter);
collector.resetCollector();
// Browse pages returned by collector in reverse until none are returned
var taskPage;
while ((taskPage = collector.readPreviousTasks(100)) != null)
{
for each (var task in taskPage)
{
// Pull only Enter maint mode messages
if(task.name == "enterMaintenanceMode"){
System.log("Task: " + task.name);
System.log(" startTime: " + task.startTime );
System.log(" User: " + task.reason.userName );
System.log(" dynamicProperty: " + task.dynamicProperty );
task.dynamicProperty == "HostSystem.enterMaintenanceMode"
}
}
}
} catch(ex){
System.log("ERROR : " + ex);
}@
Try replacing the line
while ((taskPage = collector.readPreviousTasks(100)) != null)
with
while ((taskPage = collector.readNextTasks(100)) != null)