Six Million Ways To…
  • About
Orchestrator

vRO : Workflow to Get Restarted VMs by HA

by Zakaria March 2, 2019 No Comments

Hello,

Today, i wanted to share with you a vRO workflow helping me to get the list of restarted virtual machine by HA on a vCenter. This Workflow can be called by any monitoring tool when an snmp trap is sent by vCenter :

Inputs & Outputs

Workflow Schema

Source Code for Used on Scriptable Task

//init variables
 //iterator
 var i=0;
 //the list of restarted Virtual machines
 var VMList = [];
 //The Time when VM HA Happened
 var Time = [];
 //Get All vCenter VMs
 var allvms = vCenter_Name.allVirtualMachines;
 //filter Events
 for each (var vm in allvms){
 var beginTime = new Date();
 //Set Start Date here we chose to parse the last 24hours events
 beginTime.setHours(beginTime.getHours()-24);
 //Create Event
 var vcEventFilterSpec = new VcEventFilterSpec();
 var spec = new VcEventFilterSpec();
 var vcEventFilterSpecByTime = new VcEventFilterSpecByTime();
 vcEventFilterSpec.time = vcEventFilterSpecByTime;
 vcEventFilterSpecByTime.beginTime = beginTime;
 //the Type ID of HA Event
 spec.eventTypeId = ["com.vmware.vc.ha.VmRestartedByHAEvent"];
 spec.entity = new VcEventFilterSpecByEntity();
 spec.entity.entity = vm;
 spec.entity.recursion = VcEventFilterSpecRecursionOption.self;
 spec.time = vcEventFilterSpecByTime;
 var events = vm.sdkConnection.eventManager.queryEvents(spec);
 //For each VM we query VM restart Event on the 24 hours last hours
 for each (var ev in events) {
 System.log(ev);
 VMList[i]= String(ev.fullFormattedMessage).split(' ')[5];
 Time[i]= String (ev.createdTime);
 i=i+1;
 }
 }

HAVRO

  • Previous vRO : Reminder : How to call or initialize objects, actions.4 years ago
  • Next vRO: Using vRA REST API to get all vCAC VMs4 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Menu

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Recent Posts

  • vRA : API : Submit a request
  • vRO: Setting constants for workflows
  • VM : Quickly delete one or more VM
  • vRO: Using vRA REST API to get all vCAC VMs
  • vRO : Workflow to Get Restarted VMs by HA

Archives

  • October 2019
  • March 2019
  • March 2018
  • September 2017

Categories

  • CLI (2)
  • ESXi (1)
  • Orchestrator (4)
  • Scripts (3)
    • Powercli (3)
  • vRA (2)
  • vSphere (1)

Tags

API (1) CLI (1) HA (1) Nutanix (1) PowerCLI (1) Reminder (1) REST (1) REST API (1) vCenter (3) VRA (2) VRO (3) vSphere (4)
2023 Six Million Ways To…. Donna Theme powered by WordPress