Issue while importing alarms from one vCenter to another vCenter using PowerCLI script.
search cancel

Issue while importing alarms from one vCenter to another vCenter using PowerCLI script.

book

Article ID: 423476

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

Importing alarms from one vCenter Server to another using a PowerCLI script fails.

The issue occurs only for alarms that reference performance metrics.

Environment

VMware vCenter Server 8.x

VMware PowerCLI 13.x

Cause

During the alarm import process, the XML file contains a CounterId value that is specific to the source vCenter. If this CounterId does not match the corresponding CounterId in the destination vCenter, the import operation fails and the alarm cannot be created successfully.

The exported alarm XML file contains a CounterId that is specific to the source vCenter Server. If the CounterId referenced in the XML does not exist or does not match the corresponding metric CounterId in the destination vCenter Server, the alarm import operation fails.

CounterIds are not guaranteed to be identical across different vCenter environments, even when they monitor the same performance metric.

Resolution

Modify the CounterId in the alarm XML file to match the correct CounterId in the destination vCenter Server before importing the alarm.

Steps to resolve

  1. Identify the correct CounterId for the required performance metric in the destination vCenter Server.

  2. Open the exported alarm XML file in a text editor.

  3. Locate the <CounterId> entry used by the alarm definition.

  4. Replace the existing CounterId with the CounterId from the destination vCenter.

  5. Save the XML file.

  6. Re-run the PowerCLI script to import the alarm.

After updating the CounterId, the alarm should import successfully into the destination vCenter Server.

Note: Please find the attached PowerCLI sample script to Export and Import Alarms.

Additional Information

  • CounterIds may differ between vCenter versions or environments.
  • It is recommended to validate CounterIds when migrating alarms across vCenter Servers.

# Using below script we can validate CounterIds across vCenter Servers.

Connect-VIServer -Server "vc-ip" -user "user" -password "password"

$perfMgr = Get-View (Get-View ServiceInstance).Content.PerfManager

# Fetch the lable based on the CounterId.
$perfMgr.PerfCounter |
Where-Object {
    $_.key -eq "CounterId" # CounterId needs to be changed.
} |
Select Key, @{N="Label";E={$_.NameInfo.Label}}

# Fetch the CounterId based on the lable.
$perfMgr.PerfCounter |
Where-Object {
    $_.NameInfo.label -eq "Lable" # Lable needs to be changed.
} |
Select Key, @{N="Label";E={$_.NameInfo.Label}}

Attachments

ExportAlarmScript.txt get_app
ImportAlarmScript.txt get_app