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.
LucD schrieb:
No, it was me lacking time 😉
I uploaded a revised version of your script in http://pastebin.com/yW8EMj71
No problem.... i wanted to make sure that my post doesn't lack at all : )
So i think the script is almost clear.
But in order to avoid missunderstandings and maybe worse consequential results.
I think from line 1 to 70 i don't have to modify anything except the original should be deleted or not ... ( am I correct ?)
I think only these Line are count:
$to = Get-VM -Name "VM"
$alarm = Get-AlarmDefinition -Name "Test1"
Move-Alarm -Alarm $alarm -To $to -DeleteOriginal:$false
But one thing i don't understand in the updated Script....
Where i can setup the source destination from the alarm ?
best regards john s.
That is correct, those are the only lines you would need to change.
In the script, the alarm is found based on it's name.
There is no need to define a source.
The destination is the VI Container that you pass on the To parameter (in this case the VM)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Okay Sounds good
one more two questions:
1. i would like to save the inventory before i changed anything so is the addon snapshot inventory addon from vmlabs proofed and reliable for a production Environment ? ( do you know this addon ?)
2. in which i have to modify the script for more than one Alarm .. can i duplicate the last lines in the script in order to archieve this ?
best regards
John s.
1. I'm afraid I don't know that add-on.
Do you have a link ?
2. You can get all the alarms, and then move them one-by-one in a foreach loop.
Something like this
...
Get-AlarmDefinition | %{
Move-Alarm -Alarm $_ -To $to -DeleteOriginal:$false
}
If the alarms need to go to different location, you will have to add some logic to update the contents of $to accordingly
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1. Sure here is the link: https://labs.vmware.com/flings/inventorysnapshot
2. I think there is my Problem. Cause i mention i'm not so good with the powershell stuff ... it will be much more uncomplicate to make a placeholder for several alarms that i can insert in script and then i have only modify the vm destionation .... maybe i'll try the logic way if i have more spare time availiable.
best regards
john s.
1. Ok, I know that one.
Remember that it is a "fling", nice features but totally unsupported.
So use at your own risk :smileygrin:
2. Give it a try.
If you stumble upon a problem feel free to ask in this community
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
is it possible to add more alarms in this way ( no time for logic atm .. : ) )
$alarm = Get-AlarmDefinition -Name "Test1" , "test2" "test3"
first of all i need an quick'n dirty solution
best regards
john s.
Yes, somewhat similar to what I mentioned earlier
...
Get-AlarmDefinition -Name "Test1","Test2","Test3" | %{
Move-Alarm -Alarm $_ -To $to -DeleteOriginal:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Luc,
First - thx for all the hard work you do! You've made our lives much easier!
Im attempting to use your script for "moving/copying" some alarms from the root level to a datacenter. A few copy just fine, however the following fail:
Insufficient vSphere HA failover resources |
Network connectivity lost |
Network uplink redundancy lost |
Storage DRS recommendation |
Virtual machine Consolidation Needed status |
Virtual machine cpu usage |
Virtual machine memory usage |
vSphere HA failover in progress |
vSphere HA virtual machine failover failed |
in their attempt to copy to a datacenter object in the same datacenter with the messages:
Exception calling "CreateAlarm" with "2" argument(s): "A specified parameter was not correct.
Only problem is.. I don't know what the incorrect parameter is to correct it and I don't know how to look!
If you have spare minute ( ha! I know, funny right?), could you point me in the direction to see what parameters are needed for creating these alarms a la powercli?
Thank you so much!
Ok, I was able to gleen some information from other LucD and user articles, seems to be related to later versions of the API (5.x)
I have nailed the parameter in question down to SystemName of the AlarmCreate Dataobject.
As per the vmware docs - Since vSphere API 5.0
This value is used for system designated variables, however I don't know what values it can be, and it doesnt seem to like $null or "", it errors out with those, also if you have anything else in there, it gives the error I mentioned above.
Anyone seen/used a workaround?
I have developed a workaround as it seems to be the systemname variable.
Its looks like the field cannot be touched after creating the vmware.vim.alarmspec object. It can't be touched at all or it seems to fault the variable into something undocumented at this time (at least, I can't find it.)
Here is how with a 5.x infrastructure I was able to duplicate any rule from the system root level to a datacenter lower down the chain. Not sure if it would work between vcenters, but here is the code to try:
I use a csv to input the names of the alarms to copy, you can change this as you wish:
$to = get-view (Get-Datacenter "DATACENTER NAME")
Foreach ($a in $alarm){
$alarms=Get-AlarmDefinition | where {$_.Name -eq $a.RuleName}
$alarmview = Get-View $Alarms
$alarmMgr = Get-View AlarmManager
ForEach($alarm in $alarmview){
Get-AlarmDefinition -Name $alarms.name | Set-AlarmDefinition -Enabled:$false
$newalarm = $null
$newAlarm = New-Object VMware.Vim.AlarmSpec
$newalarm.Name = PREFIX IF YOU WANT TO CHANGE RULE NAME FROM ORIGINAL" + $alarm.Info.Name
$newalarm.Description = $alarm.Info.description
$newalarm.Enabled = $alarm.Info.enabled
$newalarm.Expression = $alarm.Info.expression
$newalarm.Action = $alarm.Info.action
$newalarm.ActionFrequency = $alarm.Info.ActionFrequency
$newalarm.Setting = $alarm.Info.setting
$newalarm.DynamicType = $alarm.Info.DynamicType
$newalarm.DynamicProperty = $alarm.Info.DynamicProperty
$alarmMgr.CreateAlarm($to.MoRef,$newAlarm)
}
}
Enjoy!