Automation

 View Only
Expand all | Collapse all

copy alarms from root to many datacenters

  • 1.  copy alarms from root to many datacenters

    Posted May 21, 2013 12:36 PM

    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!



  • 2.  RE: copy alarms from root to many datacenters

    Posted May 21, 2013 12:41 PM

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



  • 3.  RE: copy alarms from root to many datacenters

    Posted May 21, 2013 12:52 PM

    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”.



  • 4.  RE: copy alarms from root to many datacenters

    Posted May 21, 2013 06:00 PM

    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 ?



  • 5.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 08:07 AM

    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.



  • 6.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 08:51 AM

    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 ?



  • 7.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 08:58 AM

    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.



  • 8.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 10:59 AM

    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 ?



  • 9.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 11:21 AM

    looks better then before :smileywink: . 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.



  • 10.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 11:40 AM

    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
    }


  • 11.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 12:01 PM

    wuhu great :smileyhappy: . 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.



  • 12.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 12:06 PM

    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}



  • 13.  RE: copy alarms from root to many datacenters

    Posted May 22, 2013 01:36 PM

    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?



  • 14.  RE: copy alarms from root to many datacenters

    Posted May 24, 2013 12:39 PM

    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!



  • 15.  RE: copy alarms from root to many datacenters
    Best Answer

    Posted May 24, 2013 01:10 PM

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

    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 :smileyhappy: