1 2 3 4 Previous Next 49 Replies Latest reply on Sep 18, 2013 3:29 AM by svneswar Go to original post
      • 15. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
        aevrov Enthusiast
        VMware Employees

        Hi,

         

        This will work for the most cases. But note that on older VC versions, the name of the root folder is different (cant remember the exact name though). You can omit the folder name for an all-case solution.

         

         

         

        Regards,

         

         

         

        -Angel

        • 16. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
          RS_1 Enthusiast
          vExpert

          Hi, i found that you can used deserialized AlarmInfo without conversion with this method (attached ps1)

           

          It works (http://www.screencast.com/users/hypervisor/folders/Default/media/2b64e1fc-da6f-4d69-bc8e-1cc0a1b8da4c) but maybe i'm missing something ?

          • 17. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
            LucD Guru
            Community WarriorsvExpertUser Moderators

            You're assuming that all alarms are all defined on the rootfolder, whcih is not the case.

             

            And I think you're overlooking the fact that the alarm import will use the same MoRefs for the alarm itself and for the entity on which it is defined, on the import side. While the root-folder might look to be 'Folder-group-d1' all the time, you can't be sure of this. And it will definitely not work for alarms defined on other entities.

             

             

             

             

            ____________

            Blog: LucD notes

            Twitter: lucd22

            • 18. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
              RS_1 Enthusiast
              vExpert

              Thanks Luc, i must have specify that it was only for root alarm in my case.

              To avoid MoRefs issues, i was thinking about filtering on name,Description,Enabled,Expression,Action before xml export.

              Do you think it could do the trick ?

              • 19. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                LucD Guru
                User ModeratorsvExpertCommunity Warriors

                Ok, I see.

                 

                Afaik, there are no MoRefs in the Actions nor Expressions.

                So that shouldn't be a problem.

                 

                Another point to remember are the MetricAlarmExpression objects.

                They use the id for metric which is not necessarily the same on the target vCenter.

                 

                Similar remark for the EventAlarmExpression object.

                Some of these events can be EventEx or ExtendedEvent events and they rely on the extensions (Converter,Update Manager...) installed on a vCenter. You would first have to make sure that your target vCenter has the same extensions as your source vCenter.

                 

                 

                 

                 

                ____________

                Blog: LucD notes

                Twitter: lucd22

                • 20. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                  RS_1 Enthusiast
                  vExpert

                  Thanks Luc, the MetricAlarmExpression part seems really more difficult than it looks like

                   

                  EDIT : maybe an id translation table ?

                  • 21. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                    jer0nim0 Novice

                    Hi there,

                     

                    is there a solution that "just works as one would expect", somewhere?

                    Alarms defined in vcenter root only would be fine in my case.

                     

                    @RS_1:

                    1) The script that you posted bails out with

                     

                    Exception calling "CreateAlarm" with "2" argument(s): "spec"
                    At C:\Users\user\Desktop\copy-alarms.ps1:55 char:27
                    +         $alarmMgrDst.CreateAlarm <<<< ($EntityDst.moref,$AlarmDstInfo)
                        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
                        + FullyQualifiedErrorId : DotNetMethodException

                     

                    on import. (It does a "foreach ($AlarmDstInfo in $AlarmListSrcInfo)", however there is no AlarmListSrcInfo...)

                     

                    2) Does it actually restore *actions* etc.?

                    I'm asking because I was searching for an email address of an email notification that I have set up, yet I could not find the email address in the XML file, only abstract stuff like <T>VMware.Vim.GroupAlarmAction</T>.

                    Meaning: is there any added value to Get-AlarmDefinition and Set-AlarmDefintion? (http://blogs.vmware.com/vipowershell/2010/12/managing-vsphere-alarms-with-powercli.html)

                     

                    Greetings

                    JM

                    • 22. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                      LucD Guru
                      User ModeratorsCommunity WarriorsvExpert

                      2) You do not see the email address because the Xport-Alarm script doesn't explictely use the -Depth parameter on the Export-CliXml cmdlet.

                      The default is 2, and the email address is located deeper in the Alarm object.

                       

                      Replace that line for exampe with

                       

                      $AlarmListSrcInfo| Export-CliXML $xmlpath -Depth 5

                      and the email address will be in there. And the export/import will work.

                      • 23. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                        jer0nim0 Novice

                        Yeah I figured out the -Depth parameter already, but no, Xport-alarms.ps1 from http://communities.vmware.com/message/1654109#1654109 is not working. At least not the import part.

                         

                        AlarmManager.CreateAlarm seems to need an AlarmSpec and I wouldn't know exactly where to get it from (the import-clixml'ed data).

                        • 24. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                          LucD Guru
                          Community WarriorsvExpertUser Moderators

                          The Export-CliXml/Import-CliXml cmdlets serialise and deserialise your object (an Alarm in this case).

                          After the Import-CliXml you will notice that the typename of the object is now 'Deserialized.VMware.Vim.AlarmInfo'.

                          That's where the script from Angel, earlier in this thread comes into play.

                          Angel's script will reconstruct a VMware.Vim.AlarmInfo object from the imported Deserialized.VMware.Vim.AlarmInfo object.

                          And when you pass that to the CreateAlarm method, the alarm will be created.

                           

                          There are some pitfalls with this method:

                          • MoRef that are valid on one vCenter will not necessarily be valid on another vCenter or will point to another object
                          • Metric alarms use metricIds. These are not the same on every vCenter
                          • Event alarms can use events generated by Extensions, these Extensions are not necessarily present on the new vCenter

                           

                          So there is a bit more to it then what you can find in this thread.

                          • 25. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                            jer0nim0 Novice

                            I am now copy/pasting alarms this way:

                             

                            Note that some alarms are imported correctly while others trigger without reason and the "Triggers" tab says "triggers for this alarm cannot be displayed or changed through the vSphere Client. Use the vSphere API to modify these alarm triggers".

                            Even though both vcenter servers are the same build.

                             

                            ### this script is only tested with alarms defined on root vcenter item

                            # load Vmware Module
                            $xPsCheck = Get-PSSnapin | Select Name | Where {$_.Name -Like "*VMware*"}
                            If ($xPsCheck -eq $Null) {Add-PsSnapin *VMware*}

                            # change to multi-mode vcenter management
                            Set-PowerCLIConfiguration -ProxyPolicy NoProxy -DefaultVIServerMode Multiple -Confirm:$false

                            # connect to vcenters
                            $srv1 = Read-Host "source vcenter"
                            $creds1 = get-credential
                            connect-viserver -server $srv1 -credential $creds1 -NotDefault:$false
                            $srv2 = Read-Host "destination vcenter"
                            $creds2 = get-credential
                            connect-viserver -server $srv2 -credential $creds2 -NotDefault:$false

                            $alarmMgr2 = Get-View AlarmManager -server $srv2

                            # prepopulated $alarm item needed below
                            # there is no New-AlarmDefinition cmdlet, so we do this manually
                            $alarm = New-Object VMware.Vim.AlarmSpec
                            $alarm.expression = New-Object VMware.Vim.OrAlarmExpression
                            $expression1 = New-Object VMware.Vim.EventAlarmExpression
                            $expression1.EventType = $null
                            $expression1.eventTypeId = $null
                            $expression1.objectType = $null
                            $expression1.status = $null
                            $alarm.expression.expression += $expression1

                            $matches = @("YD-*", "JM-*")
                            foreach ($m in $matches) {
                                Get-AlarmDefinition -Server $srv1 -Name $m | foreach {
                                    $alarm.Name = $_.Name
                                    $alarm.Description = $_.Description

                                    $root = Get-Folder -NoRecursion -Server $srv2 | Get-View
                                    $DEVNULL = $alarmMgr2.CreateAlarm($root.MoRef, $alarm)

                                    # populate the newly created alarm
                                    $adst_spec = (Get-AlarmDefinition -Server $srv2 -Name $_.Name).ExtensionData
                                    $alarmView = Get-View $adst_spec.Alarm
                                    $alarmView.ReconfigureAlarm( $_.ExtensionData )
                               
                                    Write-Host -Fore Green Done: $_
                                }
                            }

                            • 26. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                              rhor Novice

                              Hi Aevrov,

                               

                              Firstable I wanted to thank you for sharing your script, which I'm sure took a lot of efforts to make (as anyone elses scripts to).

                              I tried to use your script, as it perfectly met my requirements for moving alarms definition from one VC to another - unfortunatelly I cannot be connected with both at the same time.

                               

                              While trying to export alarms definition from source VC I got:

                               

                              Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Supply an argument that is not nu
                              ll or empty and then try the command again.
                              At Z:\SerializeSpec.ps1:4 char:19
                              +     $a = Get-View -Id <<<<  $alarmToExport.Id
                              + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException
                              + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInte
                              rop.GetVIView

                               

                              The problem is that I cannot see any (Get-AlarmDefinition).Id value, Get-AlarmDefinition only brings: 'Name', 'Description' and 'Enabled' parameters.

                              I'm new with PowerCLI same as with PowerShell, so maybe there is something I did wrong. Despite of if i made some silly mistake or if there is an issue in that script I would kindly ask for some help.

                               

                              Both VCs are 4.1.0, 258902

                              PowerCLI version is 4.1 U1 build 332441 (snapin is the same)

                               

                              Thanks in advance.

                               

                               

                               

                              P.S. I know this is an old thread but still hope somebody will notice.

                              • 27. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                                aevrov Enthusiast
                                VMware Employees

                                Hi Rhor,

                                 

                                I'm really sorry for the late reply. I've been quite busy with the the development of the new PowerCLI release and did't have any time for the community lately.

                                 

                                In case you haven't figured this out already: I think the problem is that the alarm you're trying to export is not found.

                                On line 3 of the script:

                                > $alarmToExport = Get-AlarmDefinition $alarmToExportName

                                Please check if alarm with this name ($alarmToExportName) exists on your source VC and $alarmToExport has some value after the above line is executed.

                                Also - the way the script is written now - it expects a single alarm to be selected. If you set $alarmToExportName to a star (*) - all alarms will be selected and the script will not work as expected. You should tweak it a little bit if you want to export all the alarms. Let me know if you need help with this.

                                 

                                I hope this helps.

                                 

                                Regards,

                                - Angel

                                • 28. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                                  malabelle Enthusiast

                                  Hi Angel,

                                   

                                  is there a way to export ALL the alarms?

                                  I tried * but it won't work...

                                  • 29. Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers
                                    rhor Novice

                                    Hi Aevrov,

                                     

                                    Let me also apollogy for the late reply, I to had many things on my head (and still have) and didn't have a time to look here.

                                    I wanted to thank you for you reply as it correctly point to what was wrong with what I was trying to do. I tried do import all the alarms with $alarmToExportName set as "" (blank) or "*" (star) so it didn't work, but it works fine for a single alarm. Later I will try to tweak your script to be able to export all the alarms (or even all the alarms where description is starting with "customized" as it is my main interest). Any help would be appreciated.

                                    Many thanks!

                                     

                                    Regards,

                                    - Rhor