1 2 Previous Next 20 Replies Latest reply on Dec 7, 2015 1:02 PM by LucD

    PowerCLI script for Alarms check

    jessem Enthusiast

      Hi All,

       

      I am looking for a script to check about 5 vCenters to see what alarms are disabled whether it's on a host, a cluster or even a datacenter.  And that I would like that emailed to me with only those objects that are disabled.

        • 1. Re: PowerCLI script for Alarms check
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Try something like this

          The script assumes there is a connection to all vCenters.

           

          $toAddr = 'lucd@lucd.com'

          $fromAddr = 'report@lucd.com'

          $smtpServer = 'mail.lucd.com'

           

          Send-MailMessage -To $toAddr -From $fromAddr -Subject 'Disabled Alarms' -SmtpServer $smtpServer -BodyAsHtml -Body (

              Get-AlarmDefinition |

              where{!$_.Enabled} |

              Select Name,@{N='Entity';E={$_.Entity.Name}},@{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}} |

              ConvertTo-Html |

              Out-String

          )

           

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: PowerCLI script for Alarms check
            jessem Enthusiast

            LucD, I ran it and it did not pickup the alarm.  I disabled alarm actions on a host and it did not show that.  Any ideas?

            • 3. Re: PowerCLI script for Alarms check
              LucD Guru
              vExpertUser ModeratorsCommunity Warriors

              Does the following return any alarms, that are disabled ?

               

              Get-AlarmDefinition -Enabled:$false

               

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: PowerCLI script for Alarms check
                jessem Enthusiast

                Yes, but that alarm is not the one I am looking for.  We disable alarms on host objects.  Right-click host, disable alarm actions.  That's the one I am looking for to report on.

                • 5. Re: PowerCLI script for Alarms check
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  That options disables all alarms for that host.

                  You can report on those ESXi server with this

                   

                  $toAddr = 'lucd@lucd.com'

                  $fromAddr = 'report@lucd.com'

                  $smtpServer = 'mail.lucd.com'

                   

                  Send-MailMessage -To $toAddr -From $fromAddr -Subject 'Disabled Alarms' -SmtpServer $smtpServer -BodyAsHtml -Body (

                      Get-VMHost |

                      where{!$_.ExtensionData.AlarmActionsEnabled} |

                      Select Name |

                      ConvertTo-Html |

                      Out-String

                  )

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: PowerCLI script for Alarms check
                    jessem Enthusiast

                    hey LucD that worked out great!  Now is there a way that I can have that check all 5 vcenters and email me like this below

                     

                    Subject: Disabled Alarms

                     

                    VCENTER 01

                    esxihost01

                    esxihost02

                     

                    VCENTER02

                    esxihost99

                    esxihost100

                     

                    VCENTER03

                    esxihost09

                    esxihost10

                    • 7. Re: PowerCLI script for Alarms check
                      jessem Enthusiast

                      also, would there be a reason the html email comes in and has an asterisks at the beginning like seen here?

                       

                         *

                      esxihost01

                      esxihost02

                      • 8. Re: PowerCLI script for Alarms check
                        LucD Guru
                        User ModeratorsCommunity WarriorsvExpert

                        This version will include the vCenter on each line.

                         

                        On the asterisk, which PowerShell version are you using ?

                        Display the contents of $PSVersionTable

                         

                        $toAddr = 'lucd@lucd.com'

                        $fromAddr = 'report@lucd.com'

                        $smtpServer = 'mail.lucd.com'

                         

                        Send-MailMessage -To $toAddr -From $fromAddr -Subject 'Disabled Alarms' -SmtpServer $smtpServer -BodyAsHtml -Body (

                            Get-VMHost |

                            where{!$_.ExtensionData.AlarmActionsEnabled} |

                            Select @{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}},Name |

                            ConvertTo-Html |

                            Out-String

                        )

                         

                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 9. Re: PowerCLI script for Alarms check
                          jessem Enthusiast

                          LucD,

                           

                          I am using version PowerCLI v6.2.9200.16481.

                           

                          I tried the script and it works.  However, I guess I am still confused on where I specify the multiple vCenters.  When I open up PowerCLI and I do a connect-viserver, I am specifying just 1 vCenter and of course the script works for that one vCenter.  Is there a trick that I am missing on how to specify multiples?

                          • 10. Re: PowerCLI script for Alarms check
                            LucD Guru
                            Community WarriorsvExpertUser Moderators

                            Try connecting to all vCenters before running the script.

                            You can the connections in $global:defaultviservers.

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 11. Re: PowerCLI script for Alarms check
                              jessem Enthusiast

                              like this?

                               

                              $global:defaultviservers = 'vcenter01,vcenter02'

                              $toAddr = 'lucd@lucd.com'

                              $fromAddr = 'vmalarms@lucd.com'

                              $smtpServer = 'smtp.com'

                               

                              Send-MailMessage -To $toAddr -From $fromAddr -Subject 'Disabled Alarms' -SmtpServer $smtpServer -BodyAsHtml -Body (

                                  Get-VMHost |

                                  where{$_.ExtensionData.AlarmActionsEnabled} |

                                  Select @{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}},Name |

                                  ConvertTo-Html |

                                  Out-String

                              )

                              • 12. Re: PowerCLI script for Alarms check
                                LucD Guru
                                User ModeratorsCommunity WarriorsvExpert

                                No, on the Connect-VIServer cmdlet you can pass all 5 vCenters.

                                You can check afterwards what is connected by looking at the content of $global:defaultvirservers

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 13. Re: PowerCLI script for Alarms check
                                  jessem Enthusiast

                                  Got it!  As you can see, quite a novice here.  So I ran the script and it worked but when I checked the output, a bunch of hosts that are listed in the email do not have the alarms disabled.  I went into vCenter and double-checked and sure enough a bunch of hosts the report listed as alarms disabled are not.  What do you think?

                                  • 14. Re: PowerCLI script for Alarms check
                                    LucD Guru
                                    vExpertUser ModeratorsCommunity Warriors

                                    No problem, we all had to start at some point

                                     

                                    What does it show when you execute the following for one of the ESXi nodes that is wrongfully listed in the email ?

                                    Update the Name !

                                     

                                    Get-VMHost -Name WrongHost |

                                    Select Name,@{N='Alarm Enabled';E={$_.ExtensionData.AlarmActionsEnabled}}

                                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                    1 2 Previous Next