VMware Cloud Community
AlanR
Contributor
Contributor

Script to Move/Copy All VC alarms from root folder to sub folder

How do you take this script http://www.lucd.info/2010/02/20/alarms-moving-them-around/  and make it move ALL alarms to a new folder.

The reason is we find that having all alarms at the top level stop us from defining alarms for specific needs.

This is based on buisness requiments and have seperate folders for them. So:-

With new/exisitng VC's we need to be able to do:-

1) Move all alarms to a new folder from the root object, for general purpose (majority of systems)
2) Copy all alarms from 1) to second folder so they can be deleted/disabled as needed (smaller subset)

The version of VC is 5.0U1

Thanks.

Tags (2)
Reply
0 Kudos
30 Replies
LucD
Leadership
Leadership

Do you mean all alarms defined at the top level in the vCenter ?

Or all alarms defined anywhere in the vCenter environment ?


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

Reply
0 Kudos
AlanR
Contributor
Contributor

Yes all alrams defined at the top level.

Once moved however, the ablility to copy the alarms to another folder.

Root

     Folder 1

          DC 1

          DC 2

     Folder 2

          DC 3

The goal is to have ALL the default alrams moved from Root to Folder 1, with all object below inheriting the alarms.

As per a special requirement, where certain alarms need to be disabled, copy the Alarms from Folder 1 to Folder 2, and disable certain alarms in Folder 2 as need requires with all object below inheriting the alarms.

Reply
0 Kudos
LucD
Leadership
Leadership

If I'm not mistaken, that is exactly what my script, albeit an old one, should be doing.

Did you try to run it and specify the destination folders (both) in $to1 and $to2 ?

Which alarms are not moved ?


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

Reply
0 Kudos
AlanR
Contributor
Contributor

I have played with the script, on both VC4.1 and 5.0, is if you use -DeleteOriginal:$false the result is only a few of the alarms are moved, with the rest generating errors.

If you use -DeleteOriginal:$true  Then all the alrams get moved without issue.

We need to use the $False as this give a backout if all goes wrong.

Reply
0 Kudos
LucD
Leadership
Leadership

There can be a problem when the names of the alarms are quite long.

Would you mind showing those error messages ?

And perhaps one of the alarms that causes an error and where the move fails ?


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

Reply
0 Kudos
AlanR
Contributor
Contributor

These are all the default alarms that ship with VC.

The only ones that move are the HP alarms that get added with HP Insight Control.

I will try and re-run it and post the errors.

Reply
0 Kudos
AlanR
Contributor
Contributor

Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct.

"

At C:\PS\MoveAlarms.ps1:67 char:24

+ $alarmMgr.CreateAlarm <<<< ($destination.MoRef,$newAlarm)

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

From this block of Code

}

$alarmMgr.CreateAlarm($destination.MoRef,$newAlarm)

$newAlarm.Name = $oldName

$newAlarm.Description = $oldDescription

}

Lines 71-73 from the code page.

Reply
0 Kudos
LucD
Leadership
Leadership

Do you happen to know which alarm caused this error ?

It's difficult to debug the script when I don't know which alarm causes the error.


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

Reply
0 Kudos
AlanR
Contributor
Contributor

It happens on all of the in built default alarms with the $false setting.

Reply
0 Kudos
LucD
Leadership
Leadership

Try the attached script, it moves 1 disabled alarm from the root of the vCenter to a specific folder.


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

Reply
0 Kudos
AlanR
Contributor
Contributor

That script moved the alram from the root to the 'SYC' folder. Renamed the old alarm with (moved to SYC) appened, and copied the orginal alarm over with the orginal name. with no errors.

noticed a difference between the code.

new

function Move-Alarm{
param($Alarm, $To, [switch]$DeleteOriginal = $false)

old webpage code

function Move-Alarm{
param($Alarm, $From, $To, [switch]$DeleteOriginal = $false)

Reply
0 Kudos
LucD
Leadership
Leadership

That is correct, the From parameter is not required.

I'll update my blog post.


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

Reply
0 Kudos
AlanR
Contributor
Contributor

This still doesn't work.

I used the Advanced settings to restore the Alarms but to install defaults.

Run the script, it falls over at each alarm with the following error

Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter wa
s not correct.
"
At C:\PS\MoveAlarms.ps1:67 char:24
+         $alarmMgr.CreateAlarm <<<< ($destination.MoRef,$newAlarm)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Now here is the strange thing, If I now go back and clean up by deleting the newly created alarms at the new Folder level, and edit all of the disabled alarms, at the root level, by removing the (moved to x and y) and removing the 'Original Description' text.

So I am now back where I started. If I ru-run the script it fails on the next alarm with the same error. If I rinse and repeat it move on 1 more alram each time. This says to me that

Reply
0 Kudos
fireskyer
Enthusiast
Enthusiast

Hello guys

Do i Need a Folder structure to move the alarms from the root host  down in the hirarchy.

cause we don't any folder Structure we have  only the  Root Tree with:  root host,  one DC, Cluster with 3 Host's and the Virtual Machines at the bottom.

so is it possible to  move alarms in this Environment ?

regards  John s.

Reply
0 Kudos
LucD
Leadership
Leadership

No, that is not needed.

You can move Alarms to any container


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

Reply
0 Kudos
fireskyer
Enthusiast
Enthusiast

Hello LucD

Thanks for help

Sounds good ....

well I'm gonna try to modify  the script  that fit my Needs ...

maybe in later time i've some questions anymore

regards John s.

Reply
0 Kudos
fireskyer
Enthusiast
Enthusiast

So...

I tried to understand the script which you've written. But my knowledge about Powershell Scripting is not so good

Here is the Script which i've modified so that only one Alarm should be moved for testing purposes:

http://pastebin.com/e3AVYg5e

So i've got some questions:

1 Question :

  1. $alarmMgr= Get-View AlarmManager
  2. $from= Get-Folder -Name"Datacenter"
  3. $to1= Get-Datacenter -Name"VM-Name"

In this Lines i think there are the  Source and the Destinations  where the alarms should be copied.

But if i want to move the alarm from the root center to an specfied vm,  is it  correct to insert the name from the vm in as well as in line   3.  ?

2. Question:

  1. $alarm=(Get-AlarmDefinition -Name “Virtual machine total disk latency”).ExtensionData
  2. Move-Alarm -Alarm $alarm-From $from-To $to1-DeleteOriginal:$false


In this lines i think there is the call to move only one Alarm  is it so correct ? 

Thanks for help

regards john s. 



Reply
0 Kudos
fireskyer
Enthusiast
Enthusiast

have i  forgot some details  to mention  ???

regards john s. 

Reply
0 Kudos
LucD
Leadership
Leadership

No, it was me lacking time 😉

I uploaded a revised version of your script in http://pastebin.com/yW8EMj71


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

Reply
0 Kudos