Home > Blogs > VMware PowerCLI Blog > Author Archives: Nedko Nedev

Author Archives: Nedko Nedev

Managing vSphere Alarms with PowerCLI

Greetings to all vSphere administrators out there! We are now going to take a look at a new functionality introduced in PowerCLI 4.1 Update 1 – namely vSphere alarms management. We assume that you are already familiar with the vSphere alarms functionality. For those of you who are not, here are some resources on the topic: vSphere Datacenter Administration Guide (see Chapter 13 “Working with Alarms”).

Here’s an excerpt from the VMware documentation – “Alarms are notifications that occur in response to selected events, conditions, and states that occur with objects in the inventory. … The vCenter Server system is configured with a set of predefined alarms that monitor clusters, hosts, datacenters, datastores, networks, and virtual machines.” The current PowerCLI 4.1 Update 1 release supports only modifying the predefined alarms that come with the installation of vCenter Server.

The new cmdlets are:

  • Get-AlarmDefinition
  • Set-AlarmDefinition
  • New-AlarmAction
  • Get-AlarmAction
  • Remove-AlarmAction
  • New-AlarmActionTrigger
  • Get-AlarmActionTrigger
  • Remove-AlarmActionTrigger

With the new cmdlets, you can modify: the alarm actions, the interval on which alarm actions repeat (if repeatable), the alarm names, the alarm descriptions, and whether the alarm is enabled or not. We’ll look at some examples of how we can use these alarm management cmdlets.

Get-AlarmDefinition is a typical PowerCLI getter. It returns all the alarms defined on the vCenter Servers you’re connected to. There are also some optional parameters which allow you to filter the results by name, by the inventory object on which the alarm is defined, and by its state (enabled or disabled).

Here are some examples:

Get-AlarmDefinition # This will return all the defined alarms on the servers you’re connected to

Get-AlarmDefinition -Name "virtual machine*" -Enabled $false # This will return all the disabled alarm definitions with names starting with “virtual machine”

Get-VMHost hostname | Get-AlarmDefinition # This will return all alarms that apply to the host “hostname”. This includes alarms defined on this host and alarms inherited from the parent entity, or from any ancestors in the inventory hierarchy.

Here’s how you can modify an alarm definition:

Get-AlarmDefinition "Host memory status" | Set-AlarmDefinition -Name "Host memory" -Enabled $false # This will rename the alarm to “Host memory” and disable it

The main part of the alarm definitions you can manage is an alarm’s actions configuration. You can create an alarm action this way:

Get-AlarmDefinition "Host storage status" | New-AlarmAction -Email -To “me@mycompany.com” -Subject "Host storage shortage" # This will create a send email action which will be triggered once when the alarm state changes from warning (yellow) to alert (red)

Here is how you can add another action trigger, which will fire earlier – when the alarm state changes from normal (green) to alert (yellow):

$action = Get-AlarmDefinition "Host storage status" | Get-AlarmAction -ActionType SendEmail # Get the action we previously created

$action | New-AlarmActionTrigger -StartStatus Green -EndStatus Yellow –Repeat # Add a new repeating trigger to the action

You can also set the interval at which the action is repeated:

Set-AlarmDefinition "Host storage status" -ActionRepeatMinutes (60 * 24) # This will configure the send email action to repeat once a day (as long as the alarm is in the yellow state)

Finally you may want to remove certain alarm actions. You can do it this way:

$action = Get-AlarmDefinition "Host storage status" | Get-AlarmAction -ActionType SendEmail

Remove-AlarmAction -AlarmAction $action

This is what you can do with the newly introduced cmdlets. The PowerCLI team has decided that the rest of the alarm functionality will not be reconfigured often enough to add cmdlets for the task. However you can always gain full control over the situation through the alarm’s View object. Here’s how you can change alarm configuration that is not available to change through the cmdlets:

# Get the alarm’s view

$alarmDefinition = Get-AlarmDefinition "Host storage status"

$alarmSpecification = $alarmDefinition. ExtensionData

# Make the desired alarm configuration changes

$alarmSpecification. Description="advanced-set description…..”

# Some other changes to the alarm configuration specification (for questions see the vSphere API Reference)

# Update the alarm

$alarmView = Get-View $alarmSpecification.Alarm

$alarmView.ReconfigureAlarm( $alarmSpecification )

 

Best regards,

-Angel Evrov, MTS at VMware

 

 

 

Still Not a PowerCLI User? 10 Solid Reasons to Become a Better Professional!

1. Cutting edge technology

PowerCLI is a cutting edge technology based on the Microsoft PowerShell. Currently PowerShell is recognized as the most advanced shell environment. PowerCLI utilizes all of the PowerShell’s great features in addition to virtualization-related business logic and this makes it the leader of vSphere automation tools.

2. Saves hundreds of hours

Regardless the size of the environment you manage, it usually takes a lot of time doing repetitive tasks. With PowerCLI you can automate all of the boring processes and focus on the real issues.

3. Easy to learn

You don’t need to be a scripting guru to use PowerCLI. Actually, you don’t need a scripting background at all. As one of the users said when he first tried PowerCLI, “Using PowerCLI is more like talking to your virtual environment”. And if you have troubles you can always check our Cmdlet Reference and Administration Guide.

4. Community

A large number of VMware and independent experts are ready to assist you in any situation. Usually, you receive the solution within a couple of minutes after posting your question.

5. Community extensions

Our most advanced users have written a lot of scripts that help them in solving daily issues.  You can download them for free and start using them right away.

6. Stable, reliable, and user-friendly

We’ve been developing PowerCLI for 3 years and in that time we’ve made 5 releases. For all these years we’ve been working hard on improving the quality and usability of the product.

7. Scalable

In all our releases we dedicate a lot of efforts improving the performance. We’ve done a lot of tests on large environments to be sure the product is fast enough for big environments.

8. User-driven product

Most of our features are requested by customers. We believe that a product should follow the customer needs.

9. All-in-one solution

PowerCLI allows you to do practically everything you need to administrate a vSphere environment:

  • Initial setup
  • Host configuration
  • Guest OS customization
  • Maintenance
  • Reporting
  • Monitoring

10. Free

PowerCLI is free. All you need to do is register and download.

Feel free to share thoughts.

Cheers,
Nedko