VMware Cloud Community
NeedToKnowBasis
Enthusiast
Enthusiast

Edit Alarm Action E-mail Recipients

I was wondering if anybody had a script for PowerCLI/vCenter 5.5 to mass edit the e-mail recipients under "Configuration" for 'Send a notification email' under Alarm->Actions in vCenter.

I looked throughout Google but I had only found broken links or scripts that are for version < 5.0

I would ideally like it to over-write the entire list of values but if there is one available that will simply append new recipients to all alarms, I could deal with that as well

Thanks for any help you may provide

26 Replies
LucD
Leadership
Leadership

Mh, wondering if this could be a regional settings thing.
I'm working in EN-us, and you?
Did you change any of the regional settings, like separator for example?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
NeedToKnowBasis
Enthusiast
Enthusiast

Yup, EN-US as well for me - I don't think anybody has touched any regional settings

0 Kudos
LucD
Leadership
Leadership

Then it looks like a 5.5 vs 6.5 change.
Unfortunately I don't have a 5.5 environment to test anymore.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
NeedToKnowBasis
Enthusiast
Enthusiast

Oh okay, well thanks so much for all of your help with this! I will try to noodle around with the script to see if I can get it to budge.

When you mention specifying the alarm (as to avoid wiping out my entire alarm sendemail triggers), if I wanted to change the Cannot connect to storage alarm, would it look something like this:

foreach($alarm in Get-AlarmDefinition){

foreach($action in (Get-AlarmAction -AlarmDefinition Cannot connect to storage)){

if($action.ActionType -eq 'SendEmail'){

if($action.To.Split(',') -contains $oldEmail){

$newTo = @($action.To.Split(',') | %{

if($_ -eq $oldEmail){

$newemail


else{

$_


if($action.To -ne $newTo){

Remove-AlarmAction -AlarmAction $action -Confirm:$false


New-AlarmAction -AlarmDefinition $alarm -Email -To $newTo -Subject $mail.Subject -Confirm:$false


0 Kudos
LucD
Leadership
Leadership

Change the first line

foreach($alarm in (Get-AlarmDefinition -Name 'Cannot connect to storage')){

    foreach($action in (Get-AlarmAction -AlarmDefinition $alarm)){

        if($action.ActionType -eq 'SendEmail'){

            if($action.To.Split(',') -contains $oldEmail){

                $newTo = @($action.To.Split(',') | %{

                    if($_ -eq $oldEmail){

                        $newemail

                    }

                    else{

                        $_

                    }

                })

                if($action.To -ne $newTo){

                    Remove-AlarmAction -AlarmAction $action -Confirm:$false

                    New-AlarmAction -AlarmDefinition $alarm -Email -To $newTo -Subject $mail.Subject -Confirm:$false

                }

            }

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
kondrichRHI
Enthusiast
Enthusiast

We are also facing the problem that multiple email addresses get separated by semicolon via PowerCLI, whereas VCSA 6.5d and above and VCSA 6.7 require a colon between email addresses for emails to get sent.

New-AlamAction documentation tells us that an array of strings should be fine: Online Documentation - Cmdlet Reference - VMware {code}

But actually, it's not. It does not matter, if I create the alarm action via my box with German regional settings or with another user on another box using English settings from GUI to deepest number and date settings in Windows: VCSA receives semicolons.

I found tweo workarounds for this: Either correct or create the alarm actions manually which is awkward or open Postgres port in VCSA database, connect to the VCDB using any ODBC driver and issue an UPDATE statement replacing the seperators directly in vc.vpx_alarm_action table (don't forget to restart VCSA after that). Of course, the latter is completely evil and is unsupported by me, by VMware and even higher instances. 😉

0 Kudos
Q1t1
Contributor
Contributor

Hi all,

To modify the recipients to multiple email addresses, use :

$newEmail = @("abc@domain.com","xyz@domain.com")

Regards,

0 Kudos