VMware Cloud Community
drheim
Enthusiast
Enthusiast

Maintenance Window for VmCPUUsageAlarm on specific VM?

I am running vSphere 6.5 and applying my alarms at the VCSA level.  They are fine for a few hundred VMs, but we have 1 VM that is pegged during a specific time in the early morning every day.  It is a specific job and we are not wanting to add more vCPUs, etc.  Is there a way to create an exception for the emails we get from this specific VM during a specific time window?

Reply
0 Kudos
1 Reply
ThompsG
Virtuoso
Virtuoso

Hi drheim,

You are probably not going to like this but this is what I did to resolve a similar issue where we need to disable alarms for periods of time. In our case it was for our SQL servers during backups so we did the following:

1. Created a VM folder and put the VMs in here

2. Created an alarm definition for this folder with the appropriate Triggers and Actions

3. Create scheduled task to run a PowerShell script called "ManageAlertsDefinitions" at set times to ENABLE and DISABLE the alarm

The script I used is pretty basic and rough however here is it:

Start-Transcript -Path c:\scripts\ManageAlertsDefinitions.log -Append

$Alarms = "Virtual Machine CPU usage for SQL"
$EnableHour = "06"
$DisableHour = "22"

$vcServer = "myvcenter"

Function Test-AlarmState {
     Param( $alarm )
    

     $AlarmState = Get-AlarmDefinition -Name $alarm | Select-Object Enabled
     return $AlarmState.Enabled
}

Connect-VIServer -Server $vcServer


Switch ( (Get-Date -UFormat %H) ) {

     "$EnableHour" {

          Foreach ($alarm in $Alarms) {

               If ( !(Test-AlarmState($alarm)) ) {

               Set-AlarmDefinition -AlarmDefinition "$alarm" -Enabled:$True 
               }
          }
      }

      "$DisableHour" {

          Foreach ($alarm in $Alarms) {

               If ( Test-AlarmState($alarm) ) {

                    Set-AlarmDefinition -AlarmDefinition "$alarm" -Enabled:$False    
               }
          }
     }
}

Disconnect-VIServer -Confirm:$False
Stop-Transcript

There are a couple of variables to update:

  1. $Alarms vairable with the name of your alarm definition
  2. $EnableHour and $DisableHour variables
  3. $vcServer variable with the name of the vCenter server

The script should be parameterized, so if you find it useful then we could modify.

Kind regards.

Reply
0 Kudos