Automation

 View Only
Expand all | Collapse all

Vcenters triggered Alarms Information.

sivagndl

sivagndlDec 22, 2014 03:40 PM

  • 1.  Vcenters triggered Alarms Information.

    Posted Oct 18, 2014 04:50 PM

    HI All,

    My organization having 10 +  Vcenters. I need script like triggered alarms information. We have many alerts host disconnections, Data store full, network connection lose,  
    Out put like Vcenter Name, Object(host,datastore,vm), Status , Alarm Name and triggered date.

    Thanks for Advanced.



  • 2.  RE: Vcenters triggered Alarms Information.

    Posted Oct 18, 2014 06:39 PM

    Are your vCenters in linked mode ?

    Then you could something like

    $start = (Get-Date).AddDays(-1)

    Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |

    where {$_ -is [VMware.Vim.AlarmStatusChangedEvent] -and ($_.To -match "red|yellow")} |

    Select @{N="Time";E={$_.CreatedTime}},

        @{N="Entity";E={$_.Entity.Name}},

        @{N="State";E={$_.To}},

        @{N="vCenter";E={(Get-View $_.Entity.Entity).Client.ServiceUrl.Split('/')[2]}},

        FullFormattedMessage



  • 3.  RE: Vcenters triggered Alarms Information.

    Posted Dec 22, 2014 04:10 AM

    Hi LucD, sorry for late reply.

    The Script shows events of vm's and Hosts.
    We do not have any linked mode on VC.

    ###############################

    Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState} | %{  $_.ExtensionData.triggeredAlarmState | 

    Select @{N="Entity";E={Get-View $_.Entity | Select -ExpandProperty Name}},@{N="Alarm";E={Get-View $_.Alarm | Select -ExpandProperty Info | Select -ExpandProperty Name}},Time,OverallStatus,

    @{N="vCenter";E={$_.Uid.split('@')[1].Split(':')[1]}}}

    This one i am getting triggered Alarms information 90%. Can you please correct me to show Vcenter Name.



  • 4.  RE: Vcenters triggered Alarms Information.

    Posted Dec 22, 2014 06:37 AM

    Try like this

    foreach($dc in (Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState})){

        $dc.ExtensionData.triggeredAlarmState |

        Select @{N="Entity";E={Get-View $_.Entity | Select -ExpandProperty Name}},

            @{N="Alarm";E={Get-View $_.Alarm | Select -ExpandProperty Info | Select -ExpandProperty Name}},Time,OverallStatus,

            @{N='vCenter';E={$dc.Uid.Split('@:')[1]}}

    }



  • 5.  RE: Vcenters triggered Alarms Information.

    Posted Dec 22, 2014 09:15 AM

    Hi LucD,
    Thanks a lot.. It's looks good.

    I need exclude "Virtual machine cpu usage" in Alarm Object. Please help me..


    @{N="Alarm";E={Get-View $_.Alarm | Select -ExpandProperty Info | Select -ExpandProperty Name}}

    Where-object {$_.Alarm -ne  "Virtual Machine cpu usage"} --- How can i use this please correct me. 



  • 6.  RE: Vcenters triggered Alarms Information.

    Posted Dec 22, 2014 09:55 AM

    With a Where-Clause after the Select

    foreach($dc in (Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState})){

        $dc.ExtensionData.triggeredAlarmState |

        Select @{N="Entity";E={Get-View $_.Entity | Select -ExpandProperty Name}},

            @{N="Alarm";E={Get-View $_.Alarm | Select -ExpandProperty Info | Select -ExpandProperty Name}},Time,OverallStatus,

            @{N='vCenter';E={$dc.Uid.Split('@:')[1]}} |

        where {$_.Alarm -notmatch 'Virtual machine cpu usage'}

    }



  • 7.  RE: Vcenters triggered Alarms Information.

    Posted Dec 22, 2014 03:40 PM

    Thanks a lot LucD.. It's sounds good....



  • 8.  RE: Vcenters triggered Alarms Information.

    Posted Dec 23, 2014 06:09 AM

    Hi LucD,

    While connect one vCenter output looks good. When ever connect multiple VCenters Alarm object shows incorrect Data might be data is looping .
    Please find the attached image.



  • 9.  RE: Vcenters triggered Alarms Information.

    Posted Dec 23, 2014 09:09 AM

    What exactly is incorrect, the vCenter or the Entity, or both ?

    Do these properties always show the same value ?



  • 10.  RE: Vcenters triggered Alarms Information.

    Posted Dec 23, 2014 11:40 AM

    hi Lucd,

    Vcenter and Entity shows correctly.. But Alarm(field) showing wrong data. (repeating the alarm data).



  • 11.  RE: Vcenters triggered Alarms Information.

    Posted Dec 23, 2014 12:21 PM

    Just tried it again with multiple vCenter connections, and I see the correct alarms.

    If you go to the vSphere client and select the Datacenter, then select the Alarms tab, do you see the alarms the script is showing ?



  • 12.  RE: Vcenters triggered Alarms Information.

    Posted Dec 23, 2014 06:56 PM

    Yes Lucd,

    When i connect single Vcenter that script output perfectly matched  at  Powercli and vSphere client alarm tab. While  connect multiply Vcenters that powercli data and Vshere data is different.

    Example(output) like this,

    Single 1 Vcenter connected: AAA.

    Vcenter: AAA

    Entity:- VMHost1

    Alarm :- host connection Failure.

    Entity:- VMHost2

    Alarm :- Memory usage

    Entity:- Datastore 1

    Alarm :- usage on disk.

    Single  2 Vcenter connected: BBB

    Vcenter: BBB

    Entity:- VMHostxxx

    Alarm :- host connection Failure.

    Entity:- VMHostyyy

    Alarm :- Memory usage

    Entity:- Datastore11

    Alarm :- usage on disk.

    Mulitpule VC connected 1 and 2(new session) : AAA & BBB

    Vcenter: AAA

    Entity:- VMHost1

    Alarm :- host connection Failure. Memory usage,usage on disk. 

    Entity:- VMHost2

    Alarm :- Memory usage,host connection Failure,usage on disk..

    Entity:- Datastore 1

    Alarm :- usage on disk,host connection Failure. Memory usage.


    Vcenter: BBB

    Entity:- VMHostxxx

    Alarm :- host connection Failure. Memory usage,usage on disk.

    Entity:- VMHostyyy

    Alarm :- Memory usage,host connection Failure,usage on disk.

    Entity:- Datastore11

    Alarm :- usage on disk,host connection Failure. Memory usage.

    Regards,

    Siva Reddy G



  • 13.  RE: Vcenters triggered Alarms Information.

    Posted Dec 23, 2014 08:20 PM

    Can you attach the actual script you are running as a file attachment to this thread ?

    I don't succeed in reproducing the issue you report.



  • 14.  RE: Vcenters triggered Alarms Information.

    Posted Dec 24, 2014 02:48 AM

    This is script i am running 10+ Vcneter at a time.

    foreach($dc in (Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState})){

        $dc.ExtensionData.triggeredAlarmState |

        Select @{N='vCenter';E={$dc.Uid.Split('@:')[1]}},@{N="Entity";E={Get-View $_.Entity | Select -ExpandProperty Name}},

            @{N="Alarm";E={Get-View $_.Alarm | Select -ExpandProperty Info | Select -ExpandProperty Name}},Time,OverallStatus|

    Where-object{$_.Alarm -notmatch 'Virtual machine cpu usage' -and $_.Alarm -notmatch 'Host IPMI System Event Log status'}

    }



  • 15.  RE: Vcenters triggered Alarms Information.

    Posted Dec 24, 2014 06:44 AM

    Check if this variation of the script produces better results.

    foreach($dc in (Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState})){

    `   $dc.ExtensionData.TriggeredAlarmState |     

        Select @{N='vCenter';E={$vcenter = $dc.Uid.Split('@:')[1]; $vcenter}},

          @{N="Entity";E={Get-View $_.Entity -Server $vcenter | Select -ExpandProperty Name}},

          @{N="Alarm";E={Get-View $_.Alarm -Server $vcenter  | Select -ExpandProperty Info | Select -ExpandProperty Name}},

          Time,OverallStatus |

        Where-object{$_.Alarm -notmatch 'Virtual machine cpu usage' -and

                     $_.Alarm -notmatch 'Host IPMI System Event Log status*'}

    }



  • 16.  RE: Vcenters triggered Alarms Information.

    Posted Dec 24, 2014 07:44 AM

    Error like this..

    ***********************************************************************************************

    The term ' ' is not recognized as the name of a cmdlet, function, script file,

    or operable program. Check the spelling of the name, or if a path was included,

    verify that the path is correct and try again.

    At C:\Users\filename.ps1:2 char:3

    + `  <<<<   $dc.ExtensionData.TriggeredAlarmState |

        + CategoryInfo          : ObjectNotFound: ( :String) [], CommandNotFoundEx

       ception

        + FullyQualifiedErrorId : CommandNotFoundException

    The term ' ' is not recognized as the name of a cmdlet, function, script file,

    or operable program. Check the spelling of the name, or if a path was included,

    verify that the path is correct and try again.

    + `  <<<<   $dc.ExtensionData.TriggeredAlarmState |

        + CategoryInfo          : ObjectNotFound: ( :String) [], CommandNotFoundEx

       ception

        + FullyQualifiedErrorId : CommandNotFoundException

    *************************************************************************************

    When i remove ` key in second  line, and run  that shows same output...



  • 17.  RE: Vcenters triggered Alarms Information.

    Posted Dec 24, 2014 07:54 AM

    It looks as if you might have an issue with the copy.

    I attach the script to make sure



  • 18.  RE: Vcenters triggered Alarms Information.

    Posted Dec 24, 2014 08:02 AM

    Same error Lucd..

    The term '    ' is not recognized as the name of a cmdlet, function, script fil

    e, or operable program. Check the spelling of the name, or if a path was includ

    ed, verify that the path is correct and try again.

    At C:\Users\GONNESIV\Desktop\Alarms-triggered.ps1:2 char:3

    + `     <<<<   $dc.ExtensionData.TriggeredAlarmState |

        + CategoryInfo          : ObjectNotFound: (    :String) [], CommandNotFound



  • 19.  RE: Vcenters triggered Alarms Information.

    Posted Dec 24, 2014 08:27 AM

    And now ?

    There were some extra blanks at the end of the 2nd line., I removed those.



  • 20.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 04:41 AM

    Hi Lucd,

    the below error i am getting.

    +++++++++++++++++++++++++++++++++++++++++++++++++++

    The term '    ' is not recognized as the name of a cmdlet, function, script fil

    e, or operable program. Check the spelling of the name, or if a path was includ

    ed, verify that the path is correct and try again.

    Alarms-triggered.ps1:2 char:3

    + `     <<<<   $dc.ExtensionData.TriggeredAlarmState |

        + CategoryInfo          : ObjectNotFound: (    :String) [], CommandNotFound

    Ex    ception

        + FullyQualifiedErrorId : CommandNotFoundException

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



  • 21.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 08:32 AM

    There seems to be some strange characters in the script you are running.

    Can you attach the script, redact out all confidential information, to this thread ?



  • 22.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 09:51 AM

    Hi Lucd,

    Please find the attached file.



  • 23.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 09:56 AM

    It seems you had a continuation character on the start of the 2nd line.

    Try the attached file.



  • 24.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 12:26 PM

    Hi Lucd,

    When i connected single vCenter out put shows perfect .

    when i connected multiple Vcenters (More then 2 Vcs) shows different output.

    Please find the attached CSV files  for 1vc , 2 vcs and 3 Vcs outputs.

    Check the Alarm Column details are mixed.



  • 25.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 03:40 PM

    Does this make a difference ?

    foreach($dc in (Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState})){

        $dc.ExtensionData.TriggeredAlarmState |

        Select @{N='vCenter';E={$vcenter = $dc.Uid.Split('@:')[1]; $vcenter}},

          @{N="Entity";E={Get-View $_.Entity -Server $vcenter | Select -ExpandProperty Name}},

          @{N="Alarm";E={Get-View $_.Alarm -Server $vcenter  | %{$_.Info.Name}}},

          Time,OverallStatus |

        Where-object{$_.Alarm -notmatch 'Virtual machine cpu usage' -and

                     $_.Alarm -notmatch 'Host IPMI System Event Log status*'}

    }



  • 26.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 04:55 PM

    No difference  lucd,

    Still showing mixed data on Alarm column.



  • 27.  RE: Vcenters triggered Alarms Information.

    Posted Jan 05, 2015 05:07 PM