VMware Cloud Community
SteJah
Contributor
Contributor
Jump to solution

copy alarms from root to many datacenters

hi there.

i try some scripts, read some discussions and websites, but have no success to reach our needs.

we have vcenter 5.0 with some datacenters, where some of them have esx cluster and some of them have standalone esx hosts.

we create new alarms to execute external scripts. all works fine and now we want to make our alarms more granular on each of our datacenter. to copy these alarms will be the easy way.

i dont want to make new alarms manual and disable the alarm on the root.

what i need is a handy script which copy three alarms from the root (or the hidden folder datacenter) to all datacenters except two of them and optional disable this three alarms in root.

i try LucD "alarms-moving-them-around", some variants of this and other scripts, but ends up with many errors that i dont understand.

PowerCLI Version: VMware vSphere PowerCLI 5.0 build 435427

thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
SteJah
Contributor
Contributor
Jump to solution

with the help of lucd i reached our needs. i attached the working script (then you dont need to read all posts Smiley Wink )

change line 69 for the dc's that you dont need and in line 70 you can put in the alarms to copy to all other dc's in the connected vcenter.

and thanks again to the holy lucd Smiley Happy

View solution in original post

14 Replies
LucD
Leadership
Leadership
Jump to solution

Could you attach the errors you get with my script in a file ?


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

Reply
0 Kudos
SteJah
Contributor
Contributor
Jump to solution

of course.

i dont know what i changed last, but sometimes i got also the error:

Get-View : Cannot bind parameter ‘Id’. Cannot convert the “VMware.Vim.Alarm” value of type “VMware.Vim.Alarm” to type “VMware.Vim.ManagedObjectReference”.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Forgot to ask, how do you call the Move-Alarm function ?

In other words, what did you pass on the Alarm, From and To parameters ?


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

Reply
0 Kudos
SteJah
Contributor
Contributor
Jump to solution

i hope you mean this:

$from = Get-Folder -Name "Datencenter"

$to = Get-Datacenter -name "testsystem"

$tgtAlarm = "Testalarm"

$alarms = (Get-AlarmDefinition -name "Neuer Alarm").extensiondata.moref

$alarms | % {

  Move-Alarm -Alarm $alarm -To $to.ExtensionData -DeleteOriginal:$false

}

"Datencenter" for a german powercli/vSphere Client/ vcenter - root dir

//edit

ah, i'm sorry. for the first test, i try it with one alarm to understand the script. later i want to expand for three alarms with the productive alarms.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that is what I meant.

But I suspect that this line

Move-Alarm -Alarm $alarm -To $to.ExtensionData -DeleteOriginal:$false

should be

Move-Alarm -Alarm $_ -To $to.ExtensionData -DeleteOriginal:$false

And I'm not so sure if the value on the To parameter should be a $to.ExtensionData.

Since there seem to be many version of my original script floating around, could you attach the version you are using ?


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

Reply
0 Kudos
SteJah
Contributor
Contributor
Jump to solution

i use some variations of your original script i think.

i attached the errors when i change the suspect line and the whole script i use.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I made a few changes to the attached script.

It will copy 1 alarm, called TestAlarm, to the Datacenter, called testsystem.

Can you give that a try ?


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

Reply
0 Kudos
SteJah
Contributor
Contributor
Jump to solution

looks better then before Smiley Wink . make an mistake with the alarmname. this is not "testalarm", is "neuer alarm". "testalarm" is in the description of the alarm. changed this in your script.

i try it and got the attached three errors.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It seems like I forgot to define $alarmLength.

Can you change the last lines as follows ?

$alarmLength = 80
$to = Get-Datacenter -name "testsystem"
$tgtAlarm = "neuer alarm"

$alarms = Get-AlarmDefinition -name $tgtAlarm
$alarms | % {
 
Move-Alarm -Alarm $_ -To $to -DeleteOriginal:$false
}


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

SteJah
Contributor
Contributor
Jump to solution

wuhu great Smiley Happy . works like a charm. thanks a lot lucd!

perhaps you can help me to copy three (productive) alarms to all datacenter except the both datacenter "testsystem" and "temp"?

i will give it a try, but for any help im appreciate.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

How do you select these 3 alarms ? By name, location... ?

You will have to get all 3 into the $alarms array.

On the To parameter you can specify more than 1 destination.

So you could do something like

$to = Get-DataCenter | where {"testsystem","temp" -notcontains $_.Name}


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

SteJah
Contributor
Contributor
Jump to solution

by alarm name.

i give it a next try on some dc's before i made it for the whole "farm".

change the last lines of the scripts to:

$alarmLength = 80

$to = Get-DataCenter | where {"testsystem","temp" -notcontains $_.Name}

$tgtAlarm =  "test1", "test2", "test3"

$alarms = Get-AlarmDefinition -name $tgtAlarm

$alarms | % {

  Move-Alarm -Alarm $_ -To $to -DeleteOriginal:$false

}

some new errors:

- somewhere alarm "test1" will rename to "test" but the description is "original name: test1"

- two errors in powercli that "test" already exist

- the copied alarms in root will be named in "alarm name (moved to dc1, dc2, dc3, dc4, dc5 ... )"; how to change your great script to rename the original name one time?

Reply
0 Kudos
SteJah
Contributor
Contributor
Jump to solution

ok there was some crazy problems with existing alarms. delete all these alarms with (for example - need some more to do) the following oneliner:

Get-Datacenter| Get-AlarmDefinition |where {$_.name -match "test"} | %{$_.ExtensionData.RemoveAlarm()}

after that i tried the great script from lucd again and all works fine. thanks a lot!

Reply
0 Kudos
SteJah
Contributor
Contributor
Jump to solution

with the help of lucd i reached our needs. i attached the working script (then you dont need to read all posts Smiley Wink )

change line 69 for the dc's that you dont need and in line 70 you can put in the alarms to copy to all other dc's in the connected vcenter.

and thanks again to the holy lucd Smiley Happy