Automation

 View Only
Expand all | Collapse all

Export Alarms and definitions from VCenter.

sanjaygpt171

sanjaygpt171Jun 25, 2020 01:46 PM

  • 1.  Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 08:02 AM

    HI LuCD,

    I am opening a new thread to export all alarms whether enable or disable in the Venter. I have taken reference from thread Re: Export All Alarms and definitions from VCenter.  but it's not working for me correctly. It's exporting partila number of alarms. I want to export all alarms from vcenter which either enabled or disabled from vcenter. Could you please help me with it.



  • 2.  RE: Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 08:08 AM

    What do you want to see in the export, besides Name,Description,Entity,Enabled?



  • 3.  RE: Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 08:30 AM

    Moderator: You're already actively engaged in another thread - no need to create your own as well.

    Thread locked.



  • 4.  RE: Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 08:36 AM

    scott28tt This request is different, the other thread wanted to have all triggers on a separate line.

    Thread unlocked



  • 5.  RE: Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 08:51 AM

    OK thanks - I'll leave you to it :smileyhappy:



  • 6.  RE: Export Alarms and definitions from VCenter.
    Best Answer

    Posted Jun 25, 2020 09:07 AM

    Let's start with this one

    Get-AlarmDefinition -PipelineVariable alarm |

    ForEach-Object -Process {

        New-Object -TypeName PSObject -Property ([ordered]@{

            Alarm = $alarm.Name

            Description = $alarm.Description

            Enabled = $alarm.Enabled

            Entity = $alarm.Entity

            Action = (Get-AlarmAction -AlarmDefinition $alarm).ActionType -join ' | '

            'Last Modified' = $alarm.ExtensionData.Info.LastModifiedTime

            'Last Modified By' = $alarm.ExtensionData.Info.LastModifiedUser

        })

    } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture



  • 7.  RE: Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 11:29 AM

    Hi LuCd,

    Thanks for help. It is working perfectly. Need one more help.

    What will be script if i want to export these alarms and import in other vcenter to make them as a standard.

    We don't want different vcenter at have different alarm definitions , they all should have same definitions.

    Thanks



  • 8.  RE: Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 01:29 PM

    Then you could have a look at KB1032660



  • 9.  RE: Export Alarms and definitions from VCenter.

    Posted Jun 25, 2020 01:46 PM

    Thanks LuCD for help



  • 10.  RE: Export Alarms and definitions from VCenter.

    Posted Aug 24, 2021 08:21 AM

    Was trying to copy alarms VC7 to VC7 without any luck. Is this script support VC7 as well?



  • 11.  RE: Export Alarms and definitions from VCenter.

    Posted Aug 24, 2021 09:38 AM

    My crystal ball is currently out for maintenance, can you provide some more details on how you ran this and what goes wrong?



  • 12.  RE: Export Alarms and definitions from VCenter.

    Posted Aug 24, 2021 10:30 AM

    I was trying to copy alarms and definitions between two vCenter Servers (Version 7 U2) with help of the following VM KB without luck.

    https://kb.vmware.com/s/article/1032660



  • 13.  RE: Export Alarms and definitions from VCenter.

    Posted Aug 24, 2021 10:39 AM

    That is not a lot of information to go on.



  • 14.  RE: Export Alarms and definitions from VCenter.

    Posted Aug 24, 2021 11:03 AM

    Sorry, my bad. I have a requirement of copying the existing alarms and definition from one vCenter to another vCenter. Both vCenters are in 7.U2

    I did the following steps. 

    Downloaded the scrip from the following VMware KB

    https://kb.vmware.com/s/article/1032660

    When I tried to run for the first time it gave an error related to the certificate. With the following command, I was able to run script

    Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

    Then I ran the script with the Souce and Destination vCenter information. Script ran without any error throwing but no alarms were copied to the destination vCenter from source vCenter.

     

     

     



  • 15.  RE: Export Alarms and definitions from VCenter.

    Posted Aug 24, 2021 11:53 AM

    I didn't write that script, so you probably have to open an SR mentioning that KB.

    To start, did you change line 92 (as the comments state)?
    Otherwise only alarms whose name matches "MY.*" will be copied.

    Do you see any tasks (Alarm creation) appearing in VC2?

    You could enable Verbose output (set variable $verbosePreference to 'Continue') and check if that sheds any light on the issue.

    Ultimately you can run the script in an IDE (for example Visual Studio Code) and set some breakpoints.
    That might help finding out where things go wrong.



  • 16.  RE: Export Alarms and definitions from VCenter.

    Posted Aug 25, 2021 03:36 AM

    I'm too lazy a reader. Thank you very much . It was line 92. I changed and everything working fine. 

     

    Thank you once again.



  • 17.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 25, 2022 04:09 PM

    LucD,

    This KB is now deleted, is there a copy somewhere I can access? Google can't find it.

     

    Thanks!



  • 18.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 25, 2022 05:08 PM

    The script in that KB hasn't worked since vSphere 6.* it seems.
    That probably explains why the KB was removed.

    Might the script in Solved: copy alarms from root to many datacenters - VMware Technology Network VMTN help?



  • 19.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 25, 2022 07:32 PM

    Gave it a shot and updated likes 69 & 70 as he suggested, getting more than a few errors from them. I'll poke at them, but if anything comes to mind when you see it please share:

     

    WriteError: 
    Line |
      68 |  $alarmLength = 80
         |  ~~~~~~~~~~~~~~~~~
         | Cannot overwrite variable alarmLength because it is read-only or constant.
    
    MethodInvocationException: 
    Line |
      32 |      $alarmObj.ReconfigureAlarm($updateAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: name"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"
    
    MethodInvocationException: 
    Line |
      32 |      $alarmObj.ReconfigureAlarm($updateAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: name"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"
    
    MethodInvocationException: 
    Line |
      32 |      $alarmObj.ReconfigureAlarm($updateAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: name"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"
    
    MethodInvocationException: 
    Line |
      32 |      $alarmObj.ReconfigureAlarm($updateAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "ReconfigureAlarm" with "1" argument(s): "A specified parameter was not correct: name"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"
    
    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct: spec"

     



  • 20.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 25, 2022 07:58 PM

    It's close to working as written. I read back through the whole conversation to get clues, here's where I'm hung up:

    WriteError: 
    Line |
      68 |  $alarmLength = 80
         |  ~~~~~~~~~~~~~~~~~
         | Cannot overwrite variable alarmLength because it is read-only or constant.

    I get that error, not sure what to do about it.

     

    But the main issue is one that SteJeh references in his post, "- 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?"

    So I'll run the script to move the alarm Test1 from DC1 to DC2, and the alarm will stay in DC1 but the name will be changed to "Test1 (moved to DC2). They said they fixed it by deleting the alarm from the target DC (if I'm reading it correctly), but it doesn't even exist in the target DC so I'm not sure where to go from here.

     

    Thanks in advance!



  • 21.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 25, 2022 08:18 PM

    Which version of the script in that thread did you use?
    The attachment in the last reply?



  • 22.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 25, 2022 08:52 PM

    Yes, the one SteJah marked as correct and attached - Move-Alarm-v2


    The only changes I made to it was I made $to a single datacenter ($to = Get-DataCenter -Name "DC2")



  • 23.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 06:40 AM

    I suspect you ran the script from my Alarms – Moving them around post before.
    That script defines the variable $alarmLength as a constant.
    If you haven't stopped your PS session, that variable will stay a constant.



  • 24.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 02:46 PM

    Restarted the session and you're right, didn't get that alert. But it's still doing the thing where it doesn't move it, it just renames it. Here's the only error it throws and some screenshots:

    MethodInvocationException: 
    Line |
      62 |      $alarmMgr.CreateAlarm($destination.ExtensionData.MoRef,$newAlarm)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Exception calling "CreateAlarm" with "2" argument(s): "The object 'vim.Datacenter:datacenter-3' has already been deleted or has not been completely created"

    Let me know if you have any thoughts



  • 25.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 06:48 PM

    It looks as if the Datacenter is not found.
    Is that Datacenter moved/changed/created after you populate the content of the $destination variable?



  • 26.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 07:19 PM

    No, all the datacenters are connected and responding to powershell when tested.



  • 27.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 07:30 PM

    This error

    The object 'vim.Datacenter:datacenter-3' has already been deleted or has not been completely created

    seems to say that the value in $destination is not correct though.

    Do a stop/start of your PS session.
    Check you have only 1 vCenter connection open.



  • 28.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 07:32 PM

    Oh, dang, well that definitely is the problem! I'm trying to copy alarms to a datacenter in a different vCenter instance! Is that not supported?



  • 29.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 07:37 PM

    That should be possible when you have 2 vCenters open and you have the DefaultVIServerMode set to Multiple.
    Check with Get-PowerCLIConfiguration and eventually change with Set-PowerCLIConfiguration



  • 30.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 07:39 PM
      |   view attached

    Hm, yeah, I have both connected and it was already set to multiple.



  • 31.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 07:57 PM

    Do you have 2 Datacenters with the same name in the 2 vCenters?



  • 32.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 08:03 PM
      |   view attached

    No sir. In the screenshot I've attached, I'm moving the alarms from 1 to 2. They don't even share a matching character



  • 33.  RE: Export Alarms and definitions from VCenter.

    Posted Jan 26, 2022 09:59 PM

    Try adding the Server parameter with the name of the destination vCenter on the Get-Datacenter cmdlet



  • 34.  RE: Export Alarms and definitions from VC