PowerCLI

 View Only
Expand all | Collapse all

Alarm Definitions

insearchof

insearchofJun 03, 2020 08:07 PM

insearchof

insearchofJun 03, 2020 09:40 PM

insearchof

insearchofJun 03, 2020 09:50 PM

LucD

LucDJun 04, 2020 05:41 AM

  • 1.  Alarm Definitions

    Posted Jun 03, 2020 01:11 PM

    VMware 6.7 U3   ESXI 6.7 U3

    I have setup Email notifications on my vcenter.

    Questions.

    1. Do I have to edit every Alarm to allow the alarms to send an emails?

    2. When I Edit a Alarm and click the button to send email   I type an email address myemail@mydomain.com

        Only sending email on First alarm and first reset

    Click next a couple of times  and then Save and I get an Error.  Not sure what the error is because on the console it displays the error but nothing of value.

    If I select an email address from the drop down list it works.

    How do I update the drop down list?

    Where does the Alarm get this information from?

    I have two email addresses in the drop down list but they are not defined in my users on vcenter any where

    Any ideas

    Thank you

    Tom



  • 2.  RE: Alarm Definitions

    Posted Jun 03, 2020 03:29 PM

    Hi there. You can automate the alerts definition by a PowerCLI script but unfortunately you cannot change them in bulk. Here is a helpful step-by-step How to use PowerCLI for alarm automation in vCenter

    About this error, can you try setting the alarm with PowerCLI and see if it fails? Also, a screenshot will be very helpful



  • 3.  RE: Alarm Definitions

    Posted Jun 03, 2020 03:43 PM

    Hi!

    Yes, you have to edit every alarm in order to configure the email. But you may use PowerCli in order to configure them in bulk:

    This is an example you can use:

    # Variable

    $report = @()

    # Connect to vCenter

    $vcenter=read-host "Please enter the FQDN or IP of the vCenter Server"

    connect-viserver $vcenter -alllinked

    # Mail to configure

    $correo=read-host "Insert the email adress"

    # List of Alarms definition and action

    $report+=Get-AlarmDefinition "Cannot connect to storage" | New-AlarmAction -Email -To "$correo"

    $report+=Get-AlarmDefinition "Cannot find vSphere HA master agent" | New-AlarmAction -Email -To "$correo"

    $report+=Get-AlarmDefinition "Host battery status" | New-AlarmAction -Email -To "$correo"

    $report+=Get-AlarmDefinition "Host connection and power state" | New-AlarmAction -Email -To "$correo"

    $report+=Get-AlarmDefinition "Host connection failure" | New-AlarmAction -Email -To "$correo"

    $report+=Get-AlarmDefinition "Host hardware fan status" | New-AlarmAction -Email -To "$correo"

    $report+=Get-AlarmDefinition "Host hardware power status" | New-AlarmAction -Email -To "$correo"

    $report | Select ActionType, To | Export-Csv c:\set_alarm.csv

    You just have to list all the alarm definitions you want to configure.

    I hope it would be usefull for you

    Regads



  • 4.  RE: Alarm Definitions

    Posted Jun 03, 2020 03:57 PM

    Thanks guys

    I was able to add a new email address using powercli

    PowerCLI C:\> get-alarmdefinition 'vSphere Health detected new issues in your environment' | New-AlarmAction -Email -To "systems-alert@mydom.com"                                                                                            

    ActionType      Trigger

    ----------      -------

    SendEmail       ...

    When I went to vcenter to confirm the change I saw my new email address on the alarm definition.

    It put it on the Alarm rule 2 and alarm rule  3 settings Alarm rule1 which is warning it did not

    And also did not update any of the Reset  rules

    Can I specify which rules I can apply this to using powercli ?

    Thanks

    Tom



  • 5.  RE: Alarm Definitions

    Posted Jun 03, 2020 04:23 PM

    I ran this command

    PowerCLI C:\> get-alarmdefinition 'vSphere Health detected new issues in your environment' | get-alarmaction  | get-alarmactiontrigger | select-object -property startstatus,endstatus,alarmaction                                             

    StartStatus EndStatus AlarmAction

    -----------        ---------       ----------

       Yellow       Red          SendEmail

    But the reset rules are not set



  • 6.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:00 PM

    Unfortunately, the Alarm related cmdlets do not cover all possibilities that Alarms allow.
    When a cmdlet doesn't implement what you want to do, it is time to go for the API.

    In this case, the following should make the changes to that one alarm you were testing.

    To do such a change in bulk, would require more logic in the script.

    There could for example already be other actions present.

    The reason I used a GroupAlarmAction is because that is the way you can combine multiple actions on an Alarm.

    And it seems the Web Client expects this GroupAlarmAction at the top of the actions.

    Alarms are a bit more complex then the provided cmdlets and some blogposts might suggest!

    $alarmName = 'vSphere Health detected new issues in your environment'

    $to = 'luc@local.lab'


    $alarmMgr = Get-View AlarmManager

    $alarm = Get-View -Id ($alarmMgr.GetAlarm($null)) | where{$_.Info.Name -eq $alarmName}


    $spec = $alarm.Info


    $group = New-Object VMware.Vim.GroupAlarmAction


    $action = New-Object VMware.Vim.AlarmTriggeringAction

    $action.Action = New-Object VMware.Vim.SendEmailAction

    $action.Action.ToList = $to

    $action.Action.Subject = $alarmName

    $action.Action.CcList = ''

    $action.Action.Body = ''


    $trans1 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans1.StartState = [VMware.Vim.ManagedEntityStatus]::green

    $trans1.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans2 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans2.StartState = [VMware.Vim.ManagedEntityStatus]::green

    $trans2.FinalState = [VMware.Vim.ManagedEntityStatus]::red


    $action.TransitionSpecs += $trans1

    $action.TransitionSpecs += $trans2


    $group.Action += $action


    $spec.Action = $group


    $spec.ActionFrequency = 0


    $alarm.ReconfigureAlarm($spec)



  • 7.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:11 PM

    Thanks

    I copied and created a script   named it alarm.ps1   then from the Powercli console ran this

    PowerCLI C:\util> .\alarm.ps1                                                                                         

    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "

    At C:\util\alarm.ps1:36 char:1

    + $alarm.ReconfigureAlarm($spec)

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException

    No changes made to the alarm



  • 8.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:12 PM

    Which vSphere version are you running this in?



  • 9.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:16 PM

    vsphere 6.7 U# esxi 6.7u3

    VMware PowerCLI 6.5 build 4624819



  • 10.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:22 PM

    I'm not sure if the PowerCLI version could have any impact, but that is a rather old PowerCLI version.
    I use 12.0.

    I would in any case advise you to update your PowerCLI version.

    Since the version you are using is the last MSI-based version, you will need to have a look at Welcome PowerCLI to the PowerShell Gallery – Install Process Updates

    Note that installing from the PS Gallery requires Internet access.



  • 11.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:49 PM

    LucD

    Great I uninstalled the application PowerCli and proceeded with the powershell method of installing PowerCLI

    I get this error trying to connect to my vcenter.

    Loading personal and system profiles took 519ms.
    PS C:\util> Import-Module VMware.PowerCLI
              Welcome to VMware PowerCLI!

    Log in to a vCenter Server or ESX host:              Connect-VIServer
    To find out what commands are available, type:       Get-VICommand
    To show searchable help for all PowerCLI commands:   Get-PowerCLIHelp
    Once you've connected, display all virtual machines: Get-VM
    If you need more help, visit the PowerCLI community: Get-PowerCLICommunity

           Copyright (C) VMware, Inc. All rights reserved.


    PS C:\util> Connect-VIServer -Server MY-VCSA
    Connect-VIServer : 6/3/2020 1:44:39 PM  Connect-VIServer                Error: Invalid server certificate. Use
    Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect
    once or to add a permanent exception for this server.
    Additional Information: Could not establish trust relationship for the SSL/TLS secure channel with authority
    'My-vcsa'.
    At line:1 char:1
    + Connect-VIServer -Server My-VCSA
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [Connect-VIServer], ViSecurityNegotiationException
        + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.
       Cmdlets.Commands.ConnectVIServer



  • 12.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:53 PM

    Did you run the following before the Connect-VIServer?

    Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false



  • 13.  RE: Alarm Definitions

    Posted Jun 03, 2020 05:55 PM

    LucD

    I figured the error out

    Had to run this command first

    Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

    Now I can connect to my vcsa 

    Still same error

    PS C:\util> .\alarm.ps1

    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "

    At C:\util\alarm.ps1:36 char:1

    + $alarm.ReconfigureAlarm($spec)

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException



  • 14.  RE: Alarm Definitions

    Posted Jun 03, 2020 06:05 PM

    Just tested it again in my lab with the same alarm, and for me it works.

    Are there perhaps any Actions left from an earlier manual change?

    The following removes all Actions, and should bring the Alarm back to the original state.
    Does this work?

    $alarmName = 'vSphere Health detected new issues in your environment'

    $alarmMgr = Get-View AlarmManager

    $alarm = Get-View -Id ($alarmMgr.GetAlarm($null)) | where{$_.Info.Name -eq $alarmName}


    $spec = $alarm.Info

    $spec.Action = $null

    $alarm.ReconfigureAlarm($spec)



  • 15.  RE: Alarm Definitions

    Posted Jun 03, 2020 06:46 PM

    LucD

    The remove Worked fine.  I went onto vcenter for the alarm and all settings were cleared.

    PS C:\util> .\removealarm.ps1

    PS C:\util>

    PS C:\util> .\alarm.ps1

    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "

    At C:\util\alarm.ps1:36 char:1

    + $alarm.ReconfigureAlarm($spec)

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException

    But the alarm settings still same error

    PS C:\util> get-module

    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
    Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...
    Script     12.0.0.... VMware.CloudServices                {Connect-Vcs, Get-VcsOrganizationRole, Get-VcsService, Get...
    Script     7.0.0.1... VMware.DeployAutomation             {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-D...
    Script     7.0.0.1... VMware.ImageBuilder                 {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-Esx...
    Manifest   12.0.0.... VMware.PowerCLI
    Script     7.0.0.1... VMware.Vim
    Script     12.0.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer, Disconnect-CisServer, Get-CisService}
    Script     12.0.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, G...
    Script     12.0.0.... VMware.VimAutomation.Common         {Get-Task, New-OAuthSecurityContext, Stop-Task, Wait-Task}
    Script     12.0.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAd...
    Script     12.0.0.... VMware.VimAutomation.Hcx            {Connect-HCXServer, Disconnect-HCXServer, Get-HCXAppliance...
    Script     7.12.0.... VMware.VimAutomation.HorizonView    {Connect-HVServer, Disconnect-HVServer}
    Script     12.0.0.... VMware.VimAutomation.License        Get-LicenseDataManager
    Script     12.0.0.... VMware.VimAutomation.Nsxt           {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtPolicy...
    Script     12.0.0.... VMware.VimAutomation.Sdk            {Get-ErrorReport, Get-InstallPath, Get-PSVersion}
    Script     12.0.0.... VMware.VimAutomation.Security       {Add-AttestationServiceInfo, Add-KeyProviderServiceInfo, A...
    Script     11.5.0.... VMware.VimAutomation.Srm            {Connect-SrmServer, Disconnect-SrmServer}
    Script     12.0.0.... VMware.VimAutomation.Storage        {Add-EntityDefaultKeyProvider, Add-KeyManagementServer, Ad...
    Script     1.3.0.0    VMware.VimAutomation.StorageUtility Update-VmfsDatastore
    Script     12.0.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, E...
    Script     12.0.0.... VMware.VimAutomation.Vmc            {Add-VmcSddcHost, Connect-Vmc, Disconnect-Vmc, Get-AwsAcco...
    Script     12.0.0.... VMware.VimAutomation.vROps          {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-O...
    Script     12.0.0.... VMware.VimAutomation.WorkloadMan... {Get-WMNamespace, Get-WMNamespacePermission, Get-WMNamespa...
    Script     6.5.1.7... VMware.VumAutomation                {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Complia...



  • 16.  RE: Alarm Definitions

    Posted Jun 03, 2020 07:04 PM

    The PowerCLI modules are looking fine.

    I tried all possible variations, but I can't seem to replicate the error you are seeing.

    Two things we can:

    - attach your .ps1 file so I can run it on my side. Might be something went wrong with the copy/paste

    - have a look at the vpxd log at the time you run the script. That log might hold more clues about why the script fails for you.



  • 17.  RE: Alarm Definitions

    Posted Jun 03, 2020 07:18 PM

    Attached is my script

    vCenter Server logs can be viewed from:

    • The vSphere Client connected to vCenter Server 6.0 and 6.5:

      Click Home > Administration > System Logs.

    Can find the vpxd  log



  • 18.  RE: Alarm Definitions

    Posted Jun 03, 2020 07:33 PM

    Your script runs fine in my lab (but that is vSphere 7).

    Are you using a VCSA or a Windows-based vCenter?



  • 19.  RE: Alarm Definitions

    Posted Jun 03, 2020 07:36 PM

    LUCD

    Running VCSA 6.7     HA setup also.

    Maybe something with 6.7



  • 20.  RE: Alarm Definitions

    Posted Jun 03, 2020 07:52 PM

    Could be, but the last change I see in AlarmManager happened in API 4.0.
    No apparent changes between 6.0 and 7.0 it seems.

    The following can extract the vpxd log.

    In fact it sets the logging level to 'verbose' temporarily.

    In the file that is produced search for 'verbose', and there you should also find the API method call and the error message.

    Normally it also shows the dump of the complete $spec.
    Note: I don't  need the complete file, only the part where the Alarm call was made.

    $logLevel = Get-AdvancedSetting -Entity $global:DefaultVIServer -Name 'log.level'

    Set-AdvancedSetting -AdvancedSetting $logLevel -Value 'verbose' -Confirm:$false


    # Run your script here

    .\alarm.ps1


    $log = Get-Log -Key 'vpxd:vpxd.log'

    $log.Entries | Out-File -FilePath .\vpxd.log


    Set-AdvancedSetting -AdvancedSetting $logLevel -Value $logLevel.Value -Confirm:$false



  • 21.  RE: Alarm Definitions

    Posted Jun 03, 2020 08:02 PM

    LUCB

    The VPXD.LOG file is too large to attach

    Any other way I can get it to you?

    76,439 KB



  • 22.  RE: Alarm Definitions

    Posted Jun 03, 2020 08:07 PM

    I compressed the file



  • 23.  RE: Alarm Definitions

    Posted Jun 03, 2020 08:19 PM

    Ok, think I got it.

    In the log there is the entry

    2020-06-03T15:54:32.142-04:00 verbose vpxd[41506] [Originator@6876 sub=alarmMo opID=45c8d64c] [ValidateTransitionSpecs] Unsupported transition: green->red

    Try the following change in $trans2

    $alarmName = 'vSphere Health detected new issues in your environment'

    $to = 'luc@local.lab'


    $alarmMgr = Get-View AlarmManager

    $alarm = Get-View -Id ($alarmMgr.GetAlarm($null)) | where{$_.Info.Name -eq $alarmName}


    $spec = $alarm.Info


    $group = New-Object VMware.Vim.GroupAlarmAction


    $action = New-Object VMware.Vim.AlarmTriggeringAction

    $action.Action = New-Object VMware.Vim.SendEmailAction

    $action.Action.ToList = $to

    $action.Action.Subject = $alarmName

    $action.Action.CcList = ''

    $action.Action.Body = ''


    $trans1 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans1.StartState = [VMware.Vim.ManagedEntityStatus]::green

    $trans1.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans2 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans2.StartState = [VMware.Vim.ManagedEntityStatus]::yellow

    $trans2.FinalState = [VMware.Vim.ManagedEntityStatus]::red


    $action.TransitionSpecs += $trans1

    $action.TransitionSpecs += $trans2


    $group.Action += $action


    $spec.Action = $group


    $spec.ActionFrequency = 0


    $alarm.ReconfigureAlarm($spec)



  • 24.  RE: Alarm Definitions

    Posted Jun 03, 2020 08:27 PM

    LUCD

    Yes that did it.

    All the Alarm Rules are now set with my email address.

    The Reset Rule is still not set

    We need to make that change also

    Thanks almost there.



  • 25.  RE: Alarm Definitions

    Posted Jun 03, 2020 08:41 PM

    That just requires some additional transition specs.

    $alarmName = 'vSphere Health detected new issues in your environment'

    $to = 'luc@local.lab'


    $alarmMgr = Get-View AlarmManager

    $alarm = Get-View -Id ($alarmMgr.GetAlarm($null)) | where{$_.Info.Name -eq $alarmName}


    $spec = $alarm.Info


    $group = New-Object VMware.Vim.GroupAlarmAction


    $action = New-Object VMware.Vim.AlarmTriggeringAction

    $action.Action = New-Object VMware.Vim.SendEmailAction

    $action.Action.ToList = $to

    $action.Action.Subject = $alarmName

    $action.Action.CcList = ''

    $action.Action.Body = ''


    $trans1 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans1.StartState = [VMware.Vim.ManagedEntityStatus]::green

    $trans1.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans2 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans2.StartState = [VMware.Vim.ManagedEntityStatus]::yellow

    $trans2.FinalState = [VMware.Vim.ManagedEntityStatus]::red


    $trans3 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans3.StartState = [VMware.Vim.ManagedEntityStatus]::red

    $trans3.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans4 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans4.StartState = [VMware.Vim.ManagedEntityStatus]::yellow

    $trans4.FinalState = [VMware.Vim.ManagedEntityStatus]::green


    $action.TransitionSpecs += $trans1

    $action.TransitionSpecs += $trans2

    $action.TransitionSpecs += $trans3

    $action.TransitionSpecs += $trans4


    $group.Action += $action


    $spec.Action = $group


    $spec.ActionFrequency = 0


    $alarm.ReconfigureAlarm($spec)



  • 26.  RE: Alarm Definitions

    Posted Jun 03, 2020 08:46 PM

    PS C:\util> .\alarmv3.ps1

    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "

    At C:\util\alarmv3.ps1:45 char:1

    + $alarm.ReconfigureAlarm($spec)

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException

    Back to same error as before.

    need log file again?



  • 27.  RE: Alarm Definitions

    Posted Jun 03, 2020 08:50 PM

    That would help.

    But I don't need the complete log.

    Search for the last occurrence of vim.alarm.Alarm.reconfigure.
    From that line till the end of the file.



  • 28.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:00 PM

    Found the last occurrence of vim.alarm.Alarm.reconfigure.

    Put it was a long way down to the bottom so I zipped the file again



  • 29.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:21 PM

    I only see an old call where the transition spec green to red is still in there.
    And there are no Verbose entries in the file.



  • 30.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:24 PM

    PS C:\util> $logLevel = Get-AdvancedSetting -Entity $global:DefaultVIServer -Name 'log.level'
    PS C:\util> Set-AdvancedSetting -AdvancedSetting $logLevel -Value 'verbose' -Confirm:$false

    Name                 Value                Type                 Description
    ----                 -----                ----                 -----------
    log.level            verbose              VIServer             Logging level


    PS C:\util> .\alarmv3.ps1
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv3.ps1:45 char:1
    + $alarm.ReconfigureAlarm($spec)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    PS C:\util>  $log = Get-Log -Key 'vpxd:vpxd.log'
    PS C:\util> $log.Entries | Out-File -FilePath .\vpxd.log
    PS C:\util> Set-AdvancedSetting -AdvancedSetting $logLevel -Value $logLevel.Value -Confirm:$false

    Name                 Value                Type                 Description
    ----                 -----                ----                 -----------
    log.level            verbose              VIServer             Logging level

    what I ran



  • 31.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:27 PM

    I'm afraid I don't see the call in the log extract you attached.



  • 32.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:33 PM

    Line 108382 is the error

    2020-06-03T13:06:32.736-04:00 info vpxd[40450] [Originator@6876 sub=Default opID=619b15f6] [VpxLRO] -- ERROR task-56900 -- alarm-272 -- vim.alarm.Alarm.reconfigure: vmodl.fault.InvalidArgument:

    --> Result:

    --> (vmodl.fault.InvalidArgument) {

    -->    faultCause = (vmodl.MethodFault) null,

    -->    faultMessage = <unset>,

    -->    invalidProperty = <unset>

    -->    msg = ""

    --> }

    --> Args:

    -->

    --> Arg spec:

    --> (vim.alarm.AlarmInfo) {

    -->    name = "vSphere Health detected new issues in your environment",

    -->    systemName = "vSphere Health detected new issues in your environment",

    -->    description = "vSphere Health detected new issues in your environment",

    -->    enabled = true,

    -->    expression = (vim.alarm.OrAlarmExpression) {

    -->       expression = (vim.alarm.AlarmExpression) [

    -->          (vim.alarm.EventAlarmExpression) {

    -->             comparisons = (vim.alarm.EventAlarmExpression.Comparison) [

    -->                (vim.alarm.EventAlarmExpression.Comparison) {

    -->                   attributeName = "curstatus",

    -->                   operator = "equals",

    -->                   value = "skipped"

    -->                }

    -->             ],

    -->             eventType = "vim.event.EventEx",

    -->             eventTypeId = "vsphere.online.health.alarm.event",

    -->             objectType = <unset>,

    -->             status = "green"

    -->          },

    -->          (vim.alarm.EventAlarmExpression) {

    -->             comparisons = (vim.alarm.EventAlarmExpression.Comparison) [

    -->                (vim.alarm.EventAlarmExpression.Comparison) {

    -->                   attributeName = "curstatus",

    -->                   operator = "equals",

    -->                   value = "green"

    -->                }

    -->             ],

    -->             eventType = "vim.event.EventEx",

    -->             eventTypeId = "vsphere.online.health.alarm.event",

    -->             objectType = <unset>,

    -->             status = "green"

    -->          },

    -->          (vim.alarm.EventAlarmExpression) {

    -->             comparisons = (vim.alarm.EventAlarmExpression.Comparison) [

    -->                (vim.alarm.EventAlarmExpression.Comparison) {

    -->                   attributeName = "curstatus",

    -->                   operator = "equals",

    -->                   value = "unknown"

    -->                }

    -->             ],

    -->             eventType = "vim.event.EventEx",

    -->             eventTypeId = "vsphere.online.health.alarm.event",

    -->             objectType = <unset>,

    -->             status = "gray"

    -->          },

    -->          (vim.alarm.EventAlarmExpression) {

    -->             comparisons = (vim.alarm.EventAlarmExpression.Comparison) [

    -->                (vim.alarm.EventAlarmExpression.Comparison) {

    -->                   attributeName = "curstatus",

    -->                   operator = "equals",

    -->                   value = "info"

    -->                }

    -->             ],

    -->             eventType = "vim.event.EventEx",

    -->             eventTypeId = "vsphere.online.health.alarm.event",

    -->             objectType = <unset>,

    -->             status = "green"

    -->          },

    -->          (vim.alarm.EventAlarmExpression) {

    -->             comparisons = (vim.alarm.EventAlarmExpression.Comparison) [

    -->                (vim.alarm.EventAlarmExpression.Comparison) {

    -->                   attributeName = "curstatus",

    -->                   operator = "equals",

    -->                   value = "yellow"

    -->                }

    -->             ],

    -->             eventType = "vim.event.EventEx",

    -->             eventTypeId = "vsphere.online.health.alarm.event",

    -->             objectType = <unset>,

    -->             status = "yellow"

    -->          },

    -->          (vim.alarm.EventAlarmExpression) {

    -->             comparisons = (vim.alarm.EventAlarmExpression.Comparison) [

    -->                (vim.alarm.EventAlarmExpression.Comparison) {

    -->                   attributeName = "curstatus",

    -->                   operator = "equals",

    -->                   value = "red"

    -->                }

               ],

    -->             eventType = "vim.event.EventEx",

    -->             eventTypeId = "vsphere.online.health.alarm.event",

    -->             objectType = <unset>,

    -->             status = "red"

    -->          }

    -->       ]

    -->    },

    -->    action = (vim.alarm.GroupAlarmAction) {

    -->       action = (vim.alarm.AlarmAction) [

    -->          (vim.alarm.AlarmTriggeringAction) {

    -->             action = (vim.action.SendEmailAction) {

    -->                toList = "systems-alert@tgcsnet.com",

    -->                ccList = "",

    -->                subject = "vSphere Health detected new issues in your environment",

    -->                body = ""

    -->             },

    -->             transitionSpecs = (vim.alarm.AlarmTriggeringAction.TransitionSpec) [

    -->                (vim.alarm.AlarmTriggeringAction.TransitionSpec) {

    -->                   startState = "green",

    -->                   finalState = "yellow",

    -->                   repeats = false

    -->                },

    -->                (vim.alarm.AlarmTriggeringAction.TransitionSpec) {

    -->                   startState = "green",

    -->                   finalState = "red",

    -->                   repeats = false

    -->                }

    -->             ],

    -->             green2yellow = false,

    -->             yellow2red = false,

    -->             red2yellow = false,

    -->             yellow2green = false

    -->          }

    -->       ]

    -->    },

    -->    actionFrequency = 0,

    -->    setting = (vim.alarm.AlarmSetting) {

    -->       toleranceRange = 0,

    -->       reportingFrequency = 0

    -->    },

    -->    alarmMetadata = <unset>,

    -->    key = "alarm-272",

    -->    alarm = 'vim.alarm.Alarm:alarm-272',

    -->    entity = 'vim.Folder:group-d1',

    -->    lastModifiedTime = "2020-02-15T16:55:21.644999Z",

    -->    lastModifiedUser = "VSPHERE.LOCAL\vpxd-extension-71bf5384-39f9-4785-b5cb-372cce80f1c2",

    -->    creationEventId = 0

    --> }

    2020-06-03T13:07:12.702-04:00 info vpxd[41264] [Originator@6876 sub=Default opID=sps-Main-649934-370-43] [VpxLRO] -- ERROR session[523133b2-2d8b-b2fd-486b-33e4e9fc0e74]52ad8409-016c-619b-6193-5460b785ca96 -- CatalogSyncManager -- vim.vslm.vcenter.CatalogSyncManager.queryCatalogChange: vim.fault.NotFound:

    --> Result:

    --> (vim.fault.NotFound) {

    -->    faultCause = (vmodl.MethodFault) null,

    -->    faultMessage = <unset>

    -->    msg = "The object or item referred to could not be found."

    --> }

    --> Args:

    -->

    --> Arg catalogChangeSpec:

    --> (vim.vslm.CatalogChangeSpec) {

    -->    datastore = 'vim.Datastore:ds:///vmfs/volumes/5d629aba-2f383bce-c113-000af7a052c4/',

    -->    startVClockTime = (vim.vslm.VClockInfo) {

    -->       vClockTime = 1

    -->    },

    -->    fullSync = false

    --> }

    2020-06-03T13:07:12.704-04:00 warning vpxd[41431] [Originator@6876 sub=VpxProfiler opID=TaskLoop-host-3030] InvokeWithOpId [TotalTime] took 2566 ms

    2020-06-03T13:07:12.736-04:00 info vpxd[41269] [Originator@6876 sub=Default opID=sps-Main-649934-370-f4] [VpxLRO] -- ERROR session[523133b2-2d8b-b2fd-486b-33e4e9fc0e74]522ce5b9-b83b-c3a9-43ac-c424169e589f -- CatalogSyncManager -- vim.vslm.vcenter.CatalogSyncManager.queryCatalogChange: vim.fault.NotFound:

    --> Result:

    --> (vim.fault.NotFound) {

    -->    faultCause = (vmodl.MethodFault) null,

    -->    faultMessage = <unset>

    -->    msg = "The object or item referred to could not be found."

    --> }

    --> Args:

    -->

    --> Arg catalogChangeSpec:

    --> (vim.vslm.CatalogChangeSpec) {

    -->    datastore = 'vim.Datastore:ds:///vmfs/volumes/5d5de123-31532546-1805-000af73fc80c/',

    -->    startVClockTime = (vim.vslm.VClockInfo) {

    -->       vClockTime = 1

    -->    },

    -->    fullSync = false

    --> }



  • 33.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:36 PM

    But that code only contains 2 transition specs, including the one with green to red.
    Perhaps your latest version of the script doesn't correspond with what I posted last.



  • 34.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:40 PM

    Here is the script



  • 35.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:49 PM

    Oops, my bad.
    I still had the old green to red in there.
    I updated the script in place.



  • 36.  RE: Alarm Definitions

    Posted Jun 03, 2020 09:50 PM

    LUCD

    Please send me updated code

    Thanks



  • 37.  RE: Alarm Definitions

    Posted Jun 04, 2020 12:11 AM

    LUCD,

    I got it I fixed the RED Green

    Now the reset rules have an email address

    Only thing is Reset Rule 2 and reset rule 3 do not have send email option enabled

    I see the email address

    See attached



  • 38.  RE: Alarm Definitions

    Posted Jun 04, 2020 05:41 AM

    They do!



  • 39.  RE: Alarm Definitions

    Posted Jun 04, 2020 12:16 PM

    LUCD

    I see what you mean now

    Rules 2 & 3 use the same setting as Rule 1.  

    I will try to set some other alarms today

    Will post results

    Thank you

    Tom



  • 40.  RE: Alarm Definitions

    Posted Jun 04, 2020 12:20 PM

    Watch out with other alarms.
    This alarm didn't have any Actions yet, so it was all rather easy to add the MailAction.

    If there are already actions present, the way the Actions are added shall be slightly different.



  • 41.  RE: Alarm Definitions

    Posted Jun 04, 2020 01:08 PM

    LUCD

    I noticed some only have 1 Alarm Rule and one Reset Rule

    Is that what your talking about?

    The whole point was to be able to modify the alarms without going into each one

    Do I need to review each alarm?



  • 42.  RE: Alarm Definitions

    Posted Jun 04, 2020 01:14 PM

    No, the Rules don't matter.
    It is when there is already one more Actions on an Alarm, that the script would need a change.

    I'll check if I can do that checking with some minimal changes to the script.



  • 43.  RE: Alarm Definitions

    Posted Jun 04, 2020 01:28 PM

    LUCD

    Thanks   that would be great doing this manually is painful.

    by the way I now can manually add the email address to another Alarm.

    It must be because when we did this with the script it added the email address to the list

    But sill I think the script will be the best approach

    Currently I am disabling alarms that I do not need.

    Thanks

    Tom



  • 44.  RE: Alarm Definitions

    Posted Jun 04, 2020 01:49 PM

    The fact that you can now see the address in the suggestions for that field on the form, is most probably due to the browser in which you have the Web Client open, which caches that info from previous entries you made in that form.


    I don't think that list comes from the vCenter.



  • 45.  RE: Alarm Definitions

    Posted Jun 04, 2020 03:40 PM

    LUCD

    Yes I agree sometimes the browser session hoses things up.  I use EDGE.

    I modified the script to accept my input I have a spreadsheet with a list of all the alarms  and I can do one at a time now.

    eventually  would like to input the entire csv file and run the script .

    clear-host
    $alarmName = Read-host -Prompt "AlarmName"

    #$alarmName = 'vSphere Health detected new issues in your environment'
    $to = 'systems-alert@tgcsnet.com'

    Simple and works

    Next will be to import the csv  file as input.

    But I want to make sure I can update all the alarms.

    Thanks,

    Tom



  • 46.  RE: Alarm Definitions

    Posted Jun 04, 2020 03:50 PM

    What exactly do you intend to have in that CSV?

    The name of the Alarm and the email address for the To field.

    Anything else?



  • 47.  RE: Alarm Definitions

    Posted Jun 04, 2020 03:53 PM

    Just the Alarm name

    the TO: filed will be the same it is a group email address not individuals.



  • 48.  RE: Alarm Definitions

    Posted Jun 04, 2020 05:18 PM

    There are many different combinations possible.
    And I don't have all of them in my test environment.
    So my testing was limited in scope.

    The following should tackle the configuration of the Send Email action.

    Note: make sure you have a backup of your alarms, before you run this!

    $to = 'user@domain'

    $alarmMgr = Get-View AlarmManager

    $allAlarms = Get-View -Id ($alarmMgr.GetAlarm($null))


    $trans1 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans1.StartState = [VMware.Vim.ManagedEntityStatus]::green

    $trans1.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans2 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans2.StartState = [VMware.Vim.ManagedEntityStatus]::yellow

    $trans2.FinalState = [VMware.Vim.ManagedEntityStatus]::red


    $trans3 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans3.StartState = [VMware.Vim.ManagedEntityStatus]::red

    $trans3.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans4 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans4.StartState = [VMware.Vim.ManagedEntityStatus]::yellow

    $trans4.FinalState = [VMware.Vim.ManagedEntityStatus]::green


    # CSV is expected to have a column AlarmName


    Import-Csv -Path .\alarms.csv -UseCulture -PipelineVariable row |

    ForEach-Object -Process {

        $alarm = $allAlarms | where{$_.Info.Name -eq $row.AlarmName}

        $spec = $alarm.Info


        Write-Host "Looking at $($spec.Name)"


        if($spec.Action){

            if($spec.Action -is [VMware.Vim.GroupAlarmAction]){

            # Group, with one or more Actions

                $mail = $spec.Action.Action | where{$_.Action -is [VMware.Vim.SendEmailAction]}

                if($mail){

                    $mail.Action.ToList = $to

                    $mail.TransitionSpecs = $trans1,$trans2,$trans3,$trans4                

                }

                else{

                    $action = New-Object -TypeName VMware.Vim.AlarmTriggeringAction


                    $mail = New-Object -TypeName VMware.Vim.SendEmailAction

                    $mail.ToList = $to

                    $mail.Subject = $spec.Name

                    $mail.CcList = ''

                    $mail.Body = ''


                    $action.Action = $mail

                    $action.TransitionSpecs = $trans1,$trans2,$trans3,$trans4

                    $spec.Action.Action += $action

                }

            }

            elseif($spec.Action -is [VMware.Vim.AlarmTriggeringAction]){

            # Single Action

                Write-Host "Alarm $($spec.Name) needs further investigation"

            }

        }

        else{

        # No Action present

            $group = New-Object VMware.Vim.GroupAlarmAction

         

            $action = New-Object VMware.Vim.AlarmTriggeringAction

            $action.Action = New-Object VMware.Vim.SendEmailAction

            $action.Action.ToList = $to

            $action.Action.Subject = $spec.Name

            $action.Action.CcList = ''

            $action.Action.Body = ''

         

            $action.TransitionSpecs  = $trans1,$trans2,$trans3,$trans4

         

            $group.Action += $action

         

            $spec.Action = $group

        }

        $spec.ActionFrequency = 0


        $alarm.ReconfigureAlarm($spec)

    }



  • 49.  RE: Alarm Definitions

    Posted Jun 04, 2020 05:30 PM

    LUCD

    I am currently not using the alarms so no need to back them up

    I backup my vcsa once a week.

    CSV does have column name of AlarmName.

    Side Note:I am trying to run this command so I can disable the alarms from powercli

    PS C:\util> get-alarmdefinition -name 'vsan*' | Set-AlarmDefinition -enabled:false

    Set-AlarmDefinition : Cannot convert 'System.String' to the type 'System.Boolean' required by parameter 'Enabled'.

    At line:1 char:66

    + ... et-alarmdefinition -name 'vsan*' | Set-AlarmDefinition -enabled:false

    +                                                                     ~~~~~

        + CategoryInfo          : InvalidArgument: (:) [Set-AlarmDefinition], ParameterBindingException

        + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.Alarm.SetAlarmDefinition

    Looking to disable all alarms that are VSAN related

    I found the command to disable them

    Get-AlarmDefinition -Entity (Get-Folder -NoRecursion) -Name "vsan*" | Set-AlarmDefinition -Enabled:$False

    Thanks

    Tom



  • 50.  RE: Alarm Definitions

    Posted Jun 04, 2020 05:41 PM

    You forgot the dollar-sign on false

    Get-AlarmDefinition -Name *vsan* | Set-AlarmDefinition -Enabled:$false



  • 51.  RE: Alarm Definitions

    Posted Jun 05, 2020 01:48 PM

    LUCD

    I just ran your last version of the script.

    PS C:\util> .\alarmv5.ps1
    Looking at Active Directory Service Health
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Appliance Management Health Alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Autodeploy Disk Exhaustion on TGCSNET-VCSA-2
    Alarm Autodeploy Disk Exhaustion on TGCSNET-VCSA-2 needs further investigation
    Looking at Backup job status
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Boot Disk Exhaustion on TGCSNET-VCSA-2
    Alarm Boot Disk Exhaustion on TGCSNET-VCSA-2 needs further investigation
    Looking at Cannot connect to storage
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Cannot find vSphere HA master agent
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Certificate Status
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Cis License Health Alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Component Manager Service Health Alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Content Library Service Health Alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Core and Inventory Disk Exhaustion on TGCSNET-VCSA-2
    Alarm Core and Inventory Disk Exhaustion on TGCSNET-VCSA-2 needs further investigation
    Looking at CPU Exhaustion on TGCSNET-VCSA-2
    Alarm CPU Exhaustion on TGCSNET-VCSA-2 needs further investigation
    Looking at Data Service Health Alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Database Health Alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Datastore capability alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Datastore cluster is out of space
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Datastore compliance alarm
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Datastore is in multiple datacenters
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Looking at Datastore usage on disk
    Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: "
    At C:\util\alarmv5.ps1:77 char:5
    +     $alarm.ReconfigureAlarm($spec)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

    Any ideas?

    Thanks

    Tom



  • 52.  RE: Alarm Definitions

    Posted Jun 05, 2020 02:18 PM

    I had again this transition green-->red in there.

    I corrected the code above.



  • 53.  RE: Alarm Definitions

    Posted Jun 05, 2020 02:38 PM

    LUCD

    That was it

    Now All I have is the ones that show needs further investigation      12 Alarms reported that message.

    Should I just modify them manually?  Or do you have an idea?

    Thank you

    Tom



  • 54.  RE: Alarm Definitions

    Posted Jun 05, 2020 02:56 PM

    Up to you.


    Out of technical interest.
    Do you have the names of those alarms?

    If I have them too in my vSphere 7, I can investigate further.

    Otherwise, I would need to see how they are defined.
    The following should give me that info

    $alarm = Get-AlarmDefinition -Name <alarm-name>

    $alarm.ExtensionData.Info | Format-Custom -Depth 5 | Out-File -FilePath .\alarm-struc.txt


    Attach the file to your reply (provided you want to me look at these 12).



  • 55.  RE: Alarm Definitions

    Posted Jun 05, 2020 03:09 PM

    Attaching the out of each alarm

    Thank you

    I will send the others next message



  • 56.  RE: Alarm Definitions

    Posted Jun 05, 2020 03:14 PM

    the others 



  • 57.  RE: Alarm Definitions

    Posted Jun 05, 2020 03:15 PM

    last two

    That's all twelve



  • 58.  RE: Alarm Definitions

    Posted Jun 05, 2020 03:28 PM

    Thanks, I'll see if I can come up with a solution for these



  • 59.  RE: Alarm Definitions

    Posted Jun 05, 2020 03:53 PM

    Thanks



  • 60.  RE: Alarm Definitions
    Best Answer

    Posted Jun 05, 2020 07:39 PM

    This is the latest version that should handle all cases.
    I did notice that the Web Client shows the same Reset rule twice for those 12 alarms after the script.

    But that might be a Web Client thing.

    Since the internals look ok.

    $to = 'user@domain'

    $alarmMgr = Get-View AlarmManager

    $allAlarms = Get-View -Id ($alarmMgr.GetAlarm($null))


    $trans1 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans1.StartState = [VMware.Vim.ManagedEntityStatus]::green

    $trans1.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans2 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans2.StartState = [VMware.Vim.ManagedEntityStatus]::yellow

    $trans2.FinalState = [VMware.Vim.ManagedEntityStatus]::red


    $trans3 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans3.StartState = [VMware.Vim.ManagedEntityStatus]::red

    $trans3.FinalState = [VMware.Vim.ManagedEntityStatus]::yellow


    $trans4 = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec

    $trans4.StartState = [VMware.Vim.ManagedEntityStatus]::yellow

    $trans4.FinalState = [VMware.Vim.ManagedEntityStatus]::green


    # CSV is expected to have a column AlarmName

    Import-Csv -Path .\alarms.csv -UseCulture -PipelineVariable row |

    ForEach-Object -Process {

        $alarm = $allAlarms | where{$_.Info.Name -eq $row.AlarmName}

        $spec = $alarm.Info


        Write-Host "Looking at $($spec.Name)"


        if($spec.Action){

            if($spec.Action -is [VMware.Vim.GroupAlarmAction]){

            # Group, with one or more Actions

                $mail = $spec.Action.Action | where{$_.Action -is [VMware.Vim.SendEmailAction]}

                if($mail){

                    $mail.Action.ToList = $to

                    $mail.TransitionSpecs = $trans1,$trans2,$trans3,$trans4               

                }

                else{

                    $action = New-Object -TypeName VMware.Vim.AlarmTriggeringAction


                    $mail = New-Object -TypeName VMware.Vim.SendEmailAction

                    $mail.ToList = $to

                    $mail.Subject = $spec.Name

                    $mail.CcList = ''

                    $mail.Body = ''


                    $action.Action = $mail

                    $action.TransitionSpecs = $trans1,$trans2,$trans3,$trans4

                    $spec.Action.Action += $action

                }

            }

            elseif($spec.Action -is [VMware.Vim.AlarmTriggeringAction]){

            # Single Action

                $group = New-Object -TypeName VMware.Vim.GroupAlarmAction

                $group.Action += $spec.Action


                $trigger = New-Object -TypeName VMware.Vim.AlarmTriggeringAction


                $mail = New-Object -TypeName VMware.Vim.SendEmailAction

                $mail.ToList = $to

                $mail.Subject = $spec.Name

                $mail.CcList = ''

                $mail.Body = ''


                $trigger.Action = $mail

                $trigger.TransitionSpecs = $trans1,$trans2,$trans3,$trans4


                $group.Action += $trigger

                $spec.Action = $group

            }

        }

        else{

        # No Action present

            $group = New-Object VMware.Vim.GroupAlarmAction

        

            $action = New-Object VMware.Vim.AlarmTriggeringAction

            $action.Action = New-Object VMware.Vim.SendEmailAction

            $action.Action.ToList = $to

            $action.Action.Subject = $spec.Name

            $action.Action.CcList = ''

            $action.Action.Body = ''

        

            $action.TransitionSpecs  = $trans1,$trans2,$trans3,$trans4

        

            $group.Action += $action

        

            $spec.Action = $group

        }

        $spec.ActionFrequency = 0


        $alarm.ReconfigureAlarm($spec)

    }



  • 61.  RE: Alarm Definitions

    Posted Jun 05, 2020 08:32 PM

    LUCD

    All Alarms are now setup with email address

    Your the Man......

    Is there a way I can test to see if the email is sent ?  Some command line method ?



  • 62.  RE: Alarm Definitions

    Posted Jun 05, 2020 08:38 PM

    Not that I know of I'm afraid.

    I normally test trigger an alarm by temporarily adapting the conditions.
    Or you can create a test Alarm that fires on a specific condition that you can control.



  • 63.  RE: Alarm Definitions

    Posted Jun 03, 2020 04:02 PM

    Moderator: Thread moved to the PowerCLI area, since the thread has moved in that direction.