Home > Blogs > VMware PowerCLI Blog > Tag Archives: vSphere

Tag Archives: vSphere

What’s New for vSphere Alarm Management

One of the hot topics at VMworld EU was around alarm management and the new cmdlets which were recently made available. There has been a solid set of alarm-based cmdlets that already exist and have been part of PowerCLI for many years. However, as evidenced by a PowerCLI session at VMworld in 2017 where we dug into some examples only available by the API, those cmdlets didn’t give quite give us everything we needed. Therefore, PowerCLI 11.5 added 6 new cmdlets and 3 updated cmdlets to help manage alarm definitions, create alarm triggers, and pull information about available event types and metrics.

These new cmdlets are as follows:

  • New-AlarmDefinition
  • Remove-AlarmDefinition
  • New-AlarmTrigger
  • Get-AlarmTrigger
  • Get-EventType
  • Get-Metric

The updated cmdlets are as follows:

  • New-AlarmAction
  • New-AlarmActionTrigger
  • Set-AlarmDefinition

Let’s run through creating a new alarm with these cmdlets.

VM Reconfiguration Alarm Creation

There’s been a migration over the years to treat VM workloads in a more disposable fashion. This means that instead of making changes or updates directly to the deployed VM, we would destroy and re-deploy a new VM with the new configuration. Therefore, we’re looking to create an alarm when any VM has been reconfigured.

To create this alarm, we will need to make use of a couple of the new cmdlets that were introduced with PowerCLI 11.5. Namely: Get-EventType, New-AlarmTrigger, and New-AlarmDefintion

First, we need to find the particular event type related to a VM reconfiguration event. There are over 400 different event types, so we’ll want to get a little more specific by using a filter.

Filter Example:

Example: Viewing a filtered list of Event types

Looking through the response, we can see the last event type is the one we happen to be looking to use.

Next, we need to create an alarm trigger which will be based off of the event type we found in the prior step. For this we will use New-AlarmTrigger. This new cmdlet will have two other parameters we will need to populate as well, EntityStatus and EntityType. The EntityStatus parameter controls what the alarm severity will be. The available statuses are listed here: EntityStatus values Example: an EntityStatus of “yellow” is a warning. The EntityType parameter controls what object types the alarm can be referenced against. Example: VirtualMachine, HostSystem

For our use case, we’re going to use the following code to create a warning when a VM reconfigure task has been performed:

Lastly, we will be defining our alarm with the New-AlarmDefinition cmdlet. There are a few parameters which we’ll use to define this new alarm, including: Name, Description, AlarmTrigger, and Entity. The first two are describing our new alarm. The AlarmTrigger parameter is referencing the trigger we built in the prior step. The Entity parameter is not quite as straightforward. This parameter is actually describing at what level the alarm should be applied. Example: to apply this alarm to only a specific cluster, the entity would be for that cluster object. For this use case, we want the alarm to apply across the entire vSphere environment so we will apply it to the top-level folder named “Datacenters”.

The code to create this new alarm will look like the following:

Example: Creating a new alarm based on VM reconfiguration events

If we switch over to the vSphere Client, we can also see our newly created alarm there:

Example: Newly created alarm as viewed in the vSphere Client

That’s it! Our new alarm is created and enabled by default for usage in our environment.

Listing Active Alarms

The next question is normally “how do we list the alarms with PowerCLI?” Unfortunately, there is not a function to list these alarms easily. However, almost every top-level, managed object (technically, ManagedEntity) has a property available at the vSphere API level that we can reference to easily discover any active alarms. This property is known as the TriggeredAlarmState. When it comes to PowerCLI, this property is available through an object’s ExtensionData.

Going back to our vSphere environment, we can modify a VM in PowerCLI and see that our newly created alarm does work as planned by referencing that TriggeredAlarmState property:
Example: Modifying a VM and viewing the TriggeredAlarmState property

Then, in the vSphere Client, we will also see the following:
Example: Alarm as viewed in the vSphere Client

The output from the TriggeredAlarmState property feels like it’s being pulled directly from the vSphere API and doesn’t easily give us some important information which we can easily turn into a report. I created a new advanced function and shared it on the VMware Code Sample Exchange and on the PowerCLI Community repo, it’s called Get-TriggeredAlarm.

Get-TriggeredAlarm in action:
Example: Get-TriggeredAlarm usage

The code for Get-TriggeredAlarm:

Summary

The latest version of PowerCLI 11.5 gave us a number of updates, including a handful of new and updated cmdlets which allows us to streamline the process of automating vSphere alarm management. These 6 new cmdlets and 3 updated cmdlets help manage alarm definitions, create alarm triggers, and pull information about available event types and metrics. This blog took a look at how to easily create a new alarm, including identifying a particular event and creating an alarm trigger, as well as how to report back alarms that are already active for particular vSphere objects.

Install PowerCLI 11.5 today and let us know in the comments what you’d like to see added next when it comes to vSphere alarm management!

Managing the Virtual Machine Lifecycle with PowerCLI

 

Following the last videos showing an introduction to PowerCLI and Reporting in PowerCLI there is now a new video that takes you through managing the virtual machine lifecycle with PowerCLI, these videos are a fantastic, quick way to learn PowerCLI tips and tricks.

Administrators are no longer responsible for managing single digit servers, they now have hundreds or even thousands to maintain. The automation capabilities of PowerCLI allow you to manage the lifecycle of a single virtual machine, or a large number of virtual machines, by using custom scripts.

Every stage of the virtual machine lifecycle, from creation and modification to migration and deletion, can be automated with just a few lines of PowerCLI code. What’s more, the number of virtual machines that you are managing, has no significant impact on the complexity of the PowerCLI scripts that you need to use.

This latest video shows how to perform the following tasks easily:

  • Create a single VM
  • Deploy a VM from a Template
  • Deploy a VM using a customization specification
  • Deploying VMs from a CSV file into multiple folders
  • Change resources assigned to a VM (CPU/Mem)
  • Move a large number of VMs from one network to another
  • Move VMs to a new folder
  • vMotion VMs between hosts
  • Storage vMotion VMs to a new datastore
  • Remove Virtual Machines

All this in under 5 minutes!

Watch the video

 

VDS Export/Import with PowerCLI

One of the great new features introduced in vSphere 5.1 was the ability to export and import the configuration of your vSphere Distributed Switch (VDS) and port groups to a file.

This gives you a quick restore method in case of issues or misconfigurations and also allows you to copy the entire VDS or port group configuration to a new VDS.  This feature is detailed by this VMware KB and is available via the vSphere Web Client, below you can see how we would do this via the web client:

image

Exporting the configuration with PowerCLI

With the introduction of the VDS cmdlets in PowerCLI 5.1 R2 we can also automate this process using the Export-VDSwitch and

Continue reading

PowerCLI at VMworld 2011 (Las Vegas) UPDATE

VSP2296 What everybody ought to know about reporting vSphere and vCloud environment with PowerCLI session has a repetition!

If you haven’t managed to subscribe for it in the first time slot due to the high interest level from the audience, now you have the opportunity to attend the second one on Tuesday 4:30 PM.

All PowerCLI Presentations