VMware Cloud Community
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

script to collect "Triggered Alarms" from 4 VC's in a single report

Hi Team,

I am looking for script to collect "Triggered Alarms" from 4 VC's in a single report. We are using ESXi 4.1 Ver in all VC's.

Is it possible to collect all Triggered Alarms from 4 VC's in a sigle report and automatically through mail with Excel report.

Thank You,

Regards,

Srinivasu

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
1 Solution

Accepted Solutions
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Finally the below script helped for my requirement.

Hi Try below script to collect triggered alarms from multiple vCenters:

How to run this scripts: .\Get-TriggeredAlarms -vCenters vc001,vc002 vc03

Output file location: c:\temp\alarms.csv

Script:

______________________________________________________________________________

param (

    [String[]]$vCenters

)

Function Get-TriggeredAlarms {

    param (

        $vCenter = $(throw "A vCenter must be specified."),

        [System.Management.Automation.PSCredential]$credential

    )

    if ($credential) {

        $vc = Connect-VIServer $vCenter -Credential $credential

    }

    else {

        $vc = Connect-VIServer $vCenter

    }

    if (!$vc) {

        Write-Host "Failure connecting to the vCenter $vCenter."

        exit

    }

    $rootFolder = Get-Folder -Server $vc "Datacenters"

    foreach ($ta in $rootFolder.ExtensionData.TriggeredAlarmState) {

        $alarm = "" | Select-Object VC, EntityType, Alarm, Entity, Status, Time, Acknowledged, AckBy, AckTime

        $alarm.VC = $vCenter

        $alarm.Alarm = (Get-View -Server $vc $ta.Alarm).Info.Name

        $entity = Get-View -Server $vc $ta.Entity

        $alarm.Entity = (Get-View -Server $vc $ta.Entity).Name

        $alarm.EntityType = (Get-View -Server $vc $ta.Entity).GetType().Name   

        $alarm.Status = $ta.OverallStatus

        $alarm.Time = $ta.Time

        $alarm.Acknowledged = $ta.Acknowledged

        $alarm.AckBy = $ta.AcknowledgedByUser

        $alarm.AckTime = $ta.AcknowledgedTime       

        $alarm

    }

    Disconnect-VIServer $vCenter -Confirm:$false

}

Write-Host ("Getting the alarms from {0} vCenters." -f $vCenters.Length)

$alarms = @()

foreach ($vCenter in $vCenters) {

    Write-Host "Getting alarms from $vCenter."

    $alarms += Get-TriggeredAlarms $vCenter

}

$alarms | export-csv c:\temp\alarms.csv

__________________________________________________________________

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini

View solution in original post

Reply
0 Kudos
17 Replies
LucD
Leadership
Leadership
Jump to solution

Make sure you are running in "multi" mode

Set-PowerCLICOnfiguration -DefaultVIServerMode Multiple

Then connect to all 4 vCenters, and then run something like this

Get-VIEvent -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | 
where {$_ -is [VMware.Vim.AlarmActionTriggeredEvent]} |
Select CreatedTime,FullFormattedMessage,@{N="Entity";E={$_.Entity.Name}}

Let me know if that produces the kind of information you're looking for ?

Note that this looks back for 7 days, you can adjust the interval as you want


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

Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

Thanks for your script, I will test and get back to you.

This script will help to exports all current alarms in to a CVS file?

Regards,

Srini

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

To export to a CSV file you will have to pipe the results to an Export-Csv cmdlet.

Not sure what you mean with "current alarms", this script will export information about triggered alarms.


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

Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

Yes, I am looking for triggered alarams but only what ever current avilable in the VC (not older 7 days) ..like when we select the VC name and click on Alarm tab...which are showing current alarms.

Can you modify the script with export to CSV or Excel.

Regards,

Srini

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Here you go

Get-VIEvent -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | 
where {$_ -is [VMware.Vim.AlarmActionTriggeredEvent]} | 
Select CreatedTime,FullFormattedMessage,@{N="Entity";E={$_.Entity.Name}} |
Export-Csv
C:\Triggered-Alarms.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Receiving below errors:

[vSphere PowerCLI] C:\temp> .\alarms.PS1
Export-Csv : A parameter cannot be found that matches parameter name 'UseCultur
e'.
At C:\temp\alarms.PS1:4 char:65
+ Export-Csv C:\Triggered-Alarms.csv -NoTypeInformation -UseCulture <<<<

Regards,

Srini

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The UseCulture parameter is available since PowerShell v2.

I suspect you are running this on a PowerShell v1 engine.

Leave out the UseCulture parameter, or better yet upgrade PowerShell to v2.


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

Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi,

Below is the output as per your script:

But I am looking only the current triggered alarms..for example:

I want a script to collect current alarms from below location:

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It looks like the screenshots are missing


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

Reply
0 Kudos
Andy_Stewart
Contributor
Contributor
Jump to solution

I wrote a PS script that carries out a load of daily stats checks where I work.  One of these is currently outstanding triggered alarms - hope it helps:

(assumes you're already connected, and you call it with Get-TriggeredAlarms ("name_of_vcserver) - returns an array of alarms

----------

Function Get-TriggeredAlarms
{
param ([string]$vCenter)

$rootFolder = Get-Folder -Server $vCenter "Datacenters"

foreach ($ta in $rootFolder.ExtensionData.TriggeredAlarmState)
{
  $alarm = "" | Select-Object VC, EntityType, Alarm, Entity, Status, Time, Acknowledged, AckBy, AckTime, AlarmExpr
  $alarm.VC = $vCenter
  $alarm.Alarm = (Get-View -Server $vCenter $ta.Alarm).Info.Name
  $entity = Get-View -Server $vCenter $ta.Entity
  $alarm.Entity = (Get-View -Server $vCenter $ta.Entity).Name
  $alarm.EntityType = (Get-View -Server $vCenter $ta.Entity).GetType().Name
  $alarm.Time = $ta.Time
  $alarm.Acknowledged = $ta.Acknowledged
  $alarm.AckBy = $ta.AcknowledgedByUser
  $alarm.AckTime = $ta.AcknowledgedTime

  $alarm.Status = $ta.OverallStatus

  $expr = ((Get-View -Server $vCenter $ta.Alarm).info.expression.expression).SyncRoot[0]

  #Additional code here to decode the yellow/red values from $expr - removed as its quite specific to my needs

  #$alarm.AlarmExpr = "xxxxxxxx"


  $alarm
}
}

Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi

I have attached missied screenshots...as per attachments I am looking like these...for script the output.

--Srini

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi Andy,

I have run your below script, but I haven't received any output or error.

Can you modifiy the script to export the current trigerred logs into a CSV file.

--Srini

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
Andy_Stewart
Contributor
Contributor
Jump to solution

Connect-VIServer "nameofserver"

$TriggeredAlarms = @()

$TriggeredAlarms = Get-TriggeredAlarms "nameofserver"

$TriggeredAlarms | Export-CSV "nameofcsv.csv"

Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi,

As requested, I am looking for to export trigerred alarms from multiple VC's in a single file(.CSV). Could you please reply with entire script(as Im poor in scripting knowledge).

Format should be:

Object|    Status|    Name|    Defined In|    Triggered|    Acknowledged| Acknowledged By

ObjectStatusNameDefined InTriggeredAcknowledgedAcknowledged By
------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi Guys,

Can someone help me for my requirement?

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Finally the below script helped for my requirement.

Hi Try below script to collect triggered alarms from multiple vCenters:

How to run this scripts: .\Get-TriggeredAlarms -vCenters vc001,vc002 vc03

Output file location: c:\temp\alarms.csv

Script:

______________________________________________________________________________

param (

    [String[]]$vCenters

)

Function Get-TriggeredAlarms {

    param (

        $vCenter = $(throw "A vCenter must be specified."),

        [System.Management.Automation.PSCredential]$credential

    )

    if ($credential) {

        $vc = Connect-VIServer $vCenter -Credential $credential

    }

    else {

        $vc = Connect-VIServer $vCenter

    }

    if (!$vc) {

        Write-Host "Failure connecting to the vCenter $vCenter."

        exit

    }

    $rootFolder = Get-Folder -Server $vc "Datacenters"

    foreach ($ta in $rootFolder.ExtensionData.TriggeredAlarmState) {

        $alarm = "" | Select-Object VC, EntityType, Alarm, Entity, Status, Time, Acknowledged, AckBy, AckTime

        $alarm.VC = $vCenter

        $alarm.Alarm = (Get-View -Server $vc $ta.Alarm).Info.Name

        $entity = Get-View -Server $vc $ta.Entity

        $alarm.Entity = (Get-View -Server $vc $ta.Entity).Name

        $alarm.EntityType = (Get-View -Server $vc $ta.Entity).GetType().Name   

        $alarm.Status = $ta.OverallStatus

        $alarm.Time = $ta.Time

        $alarm.Acknowledged = $ta.Acknowledged

        $alarm.AckBy = $ta.AcknowledgedByUser

        $alarm.AckTime = $ta.AcknowledgedTime       

        $alarm

    }

    Disconnect-VIServer $vCenter -Confirm:$false

}

Write-Host ("Getting the alarms from {0} vCenters." -f $vCenters.Length)

$alarms = @()

foreach ($vCenter in $vCenters) {

    Write-Host "Getting alarms from $vCenter."

    $alarms += Get-TriggeredAlarms $vCenter

}

$alarms | export-csv c:\temp\alarms.csv

__________________________________________________________________

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
bapowercli
Contributor
Contributor
Jump to solution

Hi

Do we have any option to configure in schedule task and sent mail

Reply
0 Kudos