VMware Cloud Community
sanjaygpt171
Enthusiast
Enthusiast
Jump to solution

Export Alarms and definitions from VCenter.

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.

36 Replies
CAE0621
Enthusiast
Enthusiast
Jump to solution

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!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
CAE0621
Enthusiast
Enthusiast
Jump to solution

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")

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


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

Reply
0 Kudos
CAE0621
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
CAE0621
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


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

Reply
0 Kudos
CAE0621
Enthusiast
Enthusiast
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
CAE0621
Enthusiast
Enthusiast
Jump to solution

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

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
CAE0621
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
CAE0621
Enthusiast
Enthusiast
Jump to solution

Same outcome, I'm afraid. I even tried moving the test alarm to a datacenter in the same vCenter instance and got the same error. Maybe the script just isn't going to work in my environment

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you add a Server parameter on the Get-View cmdlet where the $alarmMgr variable is populated?


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

CAE0621
Enthusiast
Enthusiast
Jump to solution

That did it! If anyone else comes across this with the same issue, change this line:

 

  $alarmMgr = Get-View AlarmManager -Server "The One You're Moving To"
Reply
0 Kudos