sanjaygpt171
Enthusiast
Enthusiast

Export Alarms and definitions from VCenter.

Jump to solution

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.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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


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

View solution in original post

36 Replies
LucD
Leadership
Leadership

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


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

0 Kudos
scott28tt
VMware Employee
VMware Employee

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

Thread locked.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

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

Thread unlocked


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

0 Kudos
scott28tt
VMware Employee
VMware Employee

OK thanks - I'll leave you to it Smiley Happy


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

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


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

sanjaygpt171
Enthusiast
Enthusiast

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

0 Kudos
LucD
Leadership
Leadership

Then you could have a look at KB1032660


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

sanjaygpt171
Enthusiast
Enthusiast

Thanks LuCD for help

0 Kudos
yangjie8366
Contributor
Contributor

I am very grateful to LucD for providing this script and helping me a lot. Thank you so much

0 Kudos
ArunaLakshitha
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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


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

0 Kudos
ArunaLakshitha
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

That is not a lot of information to go on.


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

ArunaLakshitha
Contributor
Contributor

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.

 

 

 

0 Kudos
LucD
Leadership
Leadership

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.


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

ArunaLakshitha
Contributor
Contributor

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

 

Thank you once again.

0 Kudos
CAE0621
Enthusiast
Enthusiast

LucD,

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

 

Thanks!

0 Kudos
LucD
Leadership
Leadership

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?


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

0 Kudos
CAE0621
Enthusiast
Enthusiast

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"

 

0 Kudos