Highlighted
Contributor
Contributor

Export All Alarms and definitions from VCenter.

Jump to solution

I found the following article which helps but its not exactly what I am looking for. Script to export Alarms from VCenter to analyze. I am looking to export all alarms and definitions to csv, not just the alarms with just actions set. 

pastedImage_6.png

From the screen shot above, if possible I am looking to export the Name\Description\Trigger Events.


Any help is much appreciated.

Thanks,

Chris

1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

Try something like the following.

Note that an alarm might appear on multiple rows, once for each trigger.

The expression(s) are in 1 column, but separated with a '|'.

Hope this helps

Get-AlarmDefinition -PipelineVariable alarm |

ForEach-Object -Process {

    Get-AlarmAction -AlarmDefinition $_ -PipelineVariable action |

    ForEach-Object -Process {

        Get-AlarmActionTrigger -AlarmAction $_ |

        select @{N='Alarm';E={$alarm.Name}},

            @{N='Description';E={$alarm.Description}},

            @{N='Enabled';E={$alarm.Enabled}},

            @{N='Last Modified';E={$alarm.ExtensionData.Info.LastModifiedTime}},

            @{N='Last Modified By';E={$alarm.ExtensionData.Info.LastModifiedUser}},

            @{N='Entity';E={$alarm.Entity}},

            @{N='Expression';E={

                ($alarm.ExtensionData.Info.Expression.Expression |

                ForEach-Object -Process {"{0} ({1}) - {2} - {3}" -f $_.EventType,

                                                                    $_.EventTypeId,

                                                                    $_.ObjectType,

                                                                    ([VMware.Vim.ManagedEntityStatus]$_.Status.value__)}) -join '|'

            }},

            @{N='Trigger';E={

                "{0}:{1}->{2} (Repeat={3})" -f $action.ActionType,

                                               $_.StartStatus,

                                               $_.EndStatus,

                                               $_.Repeat

            }}

    }

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


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

View solution in original post

26 Replies
Highlighted
User Moderator
User Moderator

What is the purpose of the exported Alarms?

If it is just to export/import, you could have a look at Angel's functions in Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers


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

0 Kudos
Highlighted
Contributor
Contributor

We are using the VEEAM Management pack for SCOM to monitor the environment.  We had a meeting yesterday with our VMware Rep and SE to go through vmware alarms.  My takeaway from that meeting was to export all of the Alarms and definitions to an excel spreadsheet so the we could review all of the alarms and definitions easily.  The SE thought I could just copy and paste out of vcenter but that didn't work so I started searching the web.  I don't need to import anything when done, just need to export a list of all alarms, their definitions and triggers if possible.

Thanks,

Chris

0 Kudos
Highlighted
User Moderator
User Moderator

Try something like the following.

Note that an alarm might appear on multiple rows, once for each trigger.

The expression(s) are in 1 column, but separated with a '|'.

Hope this helps

Get-AlarmDefinition -PipelineVariable alarm |

ForEach-Object -Process {

    Get-AlarmAction -AlarmDefinition $_ -PipelineVariable action |

    ForEach-Object -Process {

        Get-AlarmActionTrigger -AlarmAction $_ |

        select @{N='Alarm';E={$alarm.Name}},

            @{N='Description';E={$alarm.Description}},

            @{N='Enabled';E={$alarm.Enabled}},

            @{N='Last Modified';E={$alarm.ExtensionData.Info.LastModifiedTime}},

            @{N='Last Modified By';E={$alarm.ExtensionData.Info.LastModifiedUser}},

            @{N='Entity';E={$alarm.Entity}},

            @{N='Expression';E={

                ($alarm.ExtensionData.Info.Expression.Expression |

                ForEach-Object -Process {"{0} ({1}) - {2} - {3}" -f $_.EventType,

                                                                    $_.EventTypeId,

                                                                    $_.ObjectType,

                                                                    ([VMware.Vim.ManagedEntityStatus]$_.Status.value__)}) -join '|'

            }},

            @{N='Trigger';E={

                "{0}:{1}->{2} (Repeat={3})" -f $action.ActionType,

                                               $_.StartStatus,

                                               $_.EndStatus,

                                               $_.Repeat

            }}

    }

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


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

View solution in original post

Highlighted
Contributor
Contributor

Thank you for the quick reply.  I am getting the following error when trying to run the script.

pastedImage_0.png

0 Kudos
Highlighted
User Moderator
User Moderator

Which PowerShell version and PowerCLI version are you using?


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

0 Kudos
Highlighted
Contributor
Contributor

PowerCLI 6.3 Release 1.

I am about to download 11.0.0 now.

0 Kudos
Highlighted
User Moderator
User Moderator

With PowerCLI 11.0.0 the PipelineVariable should work.


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

Highlighted
Contributor
Contributor

Thanks again for your help on this!

0 Kudos
Highlighted
Enthusiast
Enthusiast

How can we customize this script to run through multiple vCenters and export as csv?

0 Kudos
Highlighted
User Moderator
User Moderator

You would need to use an outer ForEach loop, and then use the Server parameter on the cmdlets.
The script already has an export to a CSV


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

0 Kudos
Highlighted
Contributor
Contributor

Hi LucD,

thank you for your script.

Is it posible to export Alarms from vCenter server to csv, then import them to other vCenter?

I know that VMware provided script to copy alarms from one vCenter to another, but for my case i do not have network connectivity between both VCs.

That is why for me is better to export, copy and import.

Thank you in advance.

0 Kudos
Highlighted
User Moderator
User Moderator

The script above copies the alarm definitions to a CSV file.
Can you copy that CSV file to the other location and import the alarm definitions from there?


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

0 Kudos
Highlighted
Contributor
Contributor

hi,

thank you for quick answer.

your script export only alarms with enabled "actions" option. In my case there is 30 alarms.

I need to have all alarms available on vCenter, becasue i'll setup definitions on one vCenter and import them to all of under my support.

i can copy csv, but how can i import them to second vCenter?

0 Kudos
Highlighted
User Moderator
User Moderator
0 Kudos
Highlighted
Contributor
Contributor

LucD,

Have three new vCenters 2- are production and 1 is more for QA and test.

All alarms are set to default however need some guidance on setting them up quickly.

I really like this idea: http://www.cloudyfuture.net/2017/08/08/powercli-script-configure-vcenter-alarm-email/

However few flaws:

1. IT would seem from the comments it overwrites the subject field of the email to recipients.

2. Feel he also has an issue in 6.7 vcsa with multiple recipients in the TO as the ; and , is an issue.

3. Doesn't really provide for a way to copy EXACTLY what is there today and re-import if needed, meaning you need to set back to a default date.

4. He doesn't have a most recent copy of alarms for 6.7 U2c

5. When I look at avail alerts like my "CPU Exhaustion on psc-mydatacenter01-0001" I dont see this is his list, and worried what it will do if it finds or does not find it.

Really just looking for a way to get up and running quickly in 6.7 vcenter with alarms sent to two or more recipients, and dont want to loose the default if an issue.

In the end it would also be nice to either perform the same action on both Production vCenters (keep in sync) then alter the emails sent from the non-prod vCenter.- meaning i dont want to send from here as no one really cares about Dev/QA env.

Have you seen anything avail like he referenced script above that will really do the job in 6.7u2c vCenter?

0 Kudos
Highlighted
User Moderator
User Moderator

Interesting idea, and yes, what you envisage should be possible.

May I suggest opening a new thread for this, since the concept goes way beyond the original question in this thread.

And it would make it easier for others to find it,


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

HI LuCD,

I tried to excute this script and it'sworking but in output file , i am geting multiple duplicate values. Could you please fix this.

Below is the same output:

Alarm Description Enabled

Host connection and power state Default alarm to monitor host connection and power state TRUE

Host connection and power state Default alarm to monitor host connection and power state TRUE

Host connection and power state Default alarm to monitor host connection and power state TRUE

Host connection and power state Default alarm to monitor host connection and power state TRUE

vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE

vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE

vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE

vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE

vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE

vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE

vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE

vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE

 
Alarm Description Enabled
Host connection and power state Default alarm to monitor host connection and power state TRUE
Host connection and power state Default alarm to monitor host connection and power state TRUE
Host connection and power state Default alarm to monitor host connection and power state TRUE
Host connection and power state Default alarm to monitor host connection and power state TRUE
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE
0 Kudos
Highlighted
User Moderator
User Moderator

The same alarm might be defined on multiple entities.
I would need to see the Entity column to see if these are actually duplicates or not.


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

0 Kudos
Highlighted
Enthusiast
Enthusiast
Alarm Description Enabled Last Modified Last Modified By Entity
Host connection and power state Default alarm to monitor host connection and power state TRUE 11/6/2015 7:18 Datacenters
Host connection and power state Default alarm to monitor host connection and power state TRUE 11/6/2015 7:18 Datacenters
Host connection and power state Default alarm to monitor host connection and power state TRUE 11/6/2015 7:18 Datacenters
Host connection and power state Default alarm to monitor host connection and power state TRUE 11/6/2015 7:18 Datacenters
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
vSAN health alarm 'Hosts with connectivity issues' Default alarm to monitor changes for the health test 'Hosts with connectivity issues' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
vSAN health alarm 'Data health' Default alarm to monitor changes for the health group test 'Data health' TRUE 11/6/2015 7:20 com.vmware.vsan.health Datacenters
0 Kudos