12 Replies Latest reply on Feb 12, 2019 8:15 AM by yaquaholic

    HP Hardware monitor by Powershell script

    krishna mishra

      Hi All,

       

      there is a lot of challenge, when we are doing HP hardware monitoring by Solarwinds, many time we are not getting alert and it leads the problem and question for solarwinds which are not able to monitor the h/w component

       

      So i have come in one next steps for monitoring of HP hardware by Powershell script.

       

      I installed the below HPILO CMD let into one DEV machine.

      Download and install HPiLOCmdlets-x64.msi

      Cmdlet Get-HPiLOHealthSummary

       

      Post installation i ran the below PS script to get the out put of HP hardware with status.

       

      --------------------

      $ErrorActionPreference= 'silentlycontinue'

      $Username="Administrator"

      $Password="XYZ"

      $path = "C:\HPiLOCmdlets\Samples\test.csv"

      $csv = Import-Csv $path

       

       

      $data=foreach ($thisILO in $csv){

      Get-HPiLOHealthSummary -server $thisILO.ILOIPv4Address -username $Username -password $Password|Select-Object @{N="ILOIPv4Address";E={$thisILO.ILOIPv4Address}},`

      @{N="BATTERY_STATUS";E={$_.BATTERY_STATUS}},@{N="BIOS_HARDWARE_STATUS";E={$_.BIOS_HARDWARE_STATUS}},@{N="FANS_STATUS";E={$_.FANS.STATUS[0]}},@{N="FANS_REDUNDANCY";E={$_.FANS.REDUNDANCY[1]}},`

      @{N="MEMORY_STATUS";E={$_.MEMORY_STATUS}},@{N="NETWORK_STATUS";E={$_.NETWORK_STATUS}},@{N="POWER_SUPPLIES_STATUS";E={$_.POWER_SUPPLIES.STATUS[0]}},@{N="POWER_SUPPLIES_REDUNDANCY";E={$_.POWER_SUPPLIES.REDUNDANCY[1]}},`

      @{N="PROCESSOR_STATUS";E={$_.PROCESSOR_STATUS}},@{N="STORAGE_STATUS";E={$_.STORAGE_STATUS}},@{N="TEMPERATURE_STATUS";E={$_.TEMPERATURE_STATUS}},@{N="HOSTNAME";E={$thisILO.HostName}},`

      @{N="CLUSTERNAME";E={$thisILO.Cluster}},@{N="DATACENTERNAME";E={$thisILO.Datacenter}}

      }

      $data|export-csv -NoTypeInformation -path "C:\HPiLOCmdlets\Samples\result.csv"

       

       

      $Hostname = "nodename"

      $Date = Get-Date

      $Email_To="your email address"

      $Email_From = "Email address"

      $Prioritystate="Low"

      $Email_Header = ""

      $SMTPSRV = "IP address" #"SMTP address"

      $Email_Subject = "HPE ILO Status as of $Date"

      $Email_Body = ""

      $Email_Body += $Email_Header

      $Email_Footer = "`n `nBest regards, `n$Hostname"

       

       

      $header = @"

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

      <head>

      <title>HPE ILO Status Report</title>

      <style type="text/css">

      <!--

      body {

      background-color: peachpuff;

      font-family: sans-serif;

      font-size:7pt;

      }

      TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}

      TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}

      TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}

      }

      -->

      </style>

      "@

      $body = @"

      <h1>HPE ILO Status</h1>

      <p>The following report was run on $(get-date).</p>

      "@ # + ($csvHTML[5..($csvHTML.length-2)] | Out-String)

      #how-to-replace-multiple-strings-in-a-file-using-powershell One option is to chain the -replace operations together. The ` at the end of each line escapes the newline, causing PowerShell to continue parsing the expression on the next line

      $csvHTML = Import-Csv C:\HPiLOCmdlets\Samples\result.csv  | ConvertTo-Html -head $header -body $body |foreach {

          $PSItem -replace "<td>Degraded</td>", "<td style='background-color:#FF8080'>Degraded</td>" `

          -replace "<td>Unkown</td>", "<td style='background-color:#FF8080'>Unknown</td>" `

          -replace "<td>Other</td>", "<td style='background-color:#FF8080'>Other</td>" `

          -replace "<td>Failed</td>", "<td style='background-color:#FF8080'>Failed</td>"

          #

          #$prioritystate="High"

      } #| Out-File C:\HPiLOCmdlets\Samples\result.html

       

       

      $Email_Body +=$csvHTML

       

       

      $Email_Body += $Email_Footer

      if ($Flag_Send_Email -eq 0) {

      echo $Email_Body

      }

      else {

      send-Mailmessage -To $Email_To -From $Email_From -Subject $Email_Subject -SmtpServer $SMTPSRV -Bodyashtml $Email_Body -Priority $Prioritystate

      }

       

       

      ------------------------------------------

       

      However I need your help to create a SAM template, so by SAM template PS script will run and check the h/w status and return result with error if found any failed in h/w.

       

      Provide your suggestion, So we can achieve this.

        • Re: HP Hardware monitor by Powershell script
          designerfx

          If you are not getting SAM hardware health from HP servers, my first guess would be because your agent is not on a current enough version. Update the HP SIM agent and you'll find you get the data.  See the requirements here: Asset inventory and hardware health monitoring requirements in SAM - SolarWinds Worldwide, LLC. Help and Support . An easy way to check this if this is a single server is to look at the asset inventory. The requirement is that this agent is installed, but you can then pull the data via WMI.

          • HP servers with HP System Insight Manager (SIM) 6.2 or later
            • Re: HP Hardware monitor by Powershell script
              krishna mishra

              We are getting the h/w details of physical server in console, but sometime when we check in ILO of hp where issue is there, but same is not reflecting in solarwinds console.

               

              recent scenario  - we have battery issue on physical box (checked by ILO ) but same is not reflecting into Solarwinds console and it lead the question on alerting system.

               

              that's why i want to create a SAM template with Powershell query that query run against the physical node to check the h/w status, if found the abnormal then template will generate a alert.

               

              hope it will clear my requirement

            • Re: HP Hardware monitor by Powershell script
              yaquaholic

              Hi Krishna,

               

              You need to get your script to Write-Host the results using the "Statistic:"  and (optional)  "Message:" output for the SAM template to pick up on them.

              The script will have to be alter to run on the host in question, use Execution Mode: Remote Node to run the script locally on the server in question and then return only one Statistic (and Message) per result.

              You can have up to ten of these, returned by each script. Any more will be ignored by the SAM PowerShell component.

               

              Write-Host "Message.<unique id>: $message"

              Write-Host "Statistic.<unique id>: $statistic"

               

              I am just arranging a blade to play with and I will have a crack at formatting an example for you.

               

              A good place to start reading up: The Basics of PowerShell (part 3)

              Also: Create Scripts for SAM Script Monitors - SolarWinds Worldwide, LLC. Help and Support

               

              Yaquaholic

                • Re: HP Hardware monitor by Powershell script
                  krishna mishra

                  Hello Yaquaholic,

                   

                  thanks for input.

                   

                  Please can you test the below unique PS command on the target Hp node by SAM template to get the status in $message.

                   

                  >Get-HPiLOHealthSummary -server 10.x.x.x -username ADMINISTRATOR -password ADMIINISTRATOR|Select-Object @{N="ILOIPv4Address";E={$thisILO.ILOIPv4Address}},` @{N="BATTERY_STATUS";E={$_.BATTERY_STATUS}}

                    • Re: HP Hardware monitor by Powershell script
                      yaquaholic

                      The platform team have just given me a test system, so I will have a crack at this today for you.

                        • Re: HP Hardware monitor by Powershell script
                          yaquaholic

                          The following code should work, as a PowerShell monitor, returning a 1 for OK status and a zero for anything else. Each value is returned with a unique Statistic (and optional Message) name, of which there are under 10. Create an ILO monitoring template, add a Windows PowerShell Monitor to it and add the script body, and the template can then be assigned to the ILO card

                          Don't forget to set the Execution Mode to Local Host, which will be your Orion server, which will need the HP iLO Cmdlets installed.

                           

                          Even if the scripts doesn't suit your needs, hopefully you know understand how Orion is expecting the results.

                           

                          #---------------------------Start of Script---------------------------------#

                          # Testing HP ILO cmdlets for SAM template

                          # https://thwack.solarwinds.com/thread/124417

                          # 2019/02/11

                          # Yaquaholic (AKA Richard Graham)

                           

                          #ILO details

                          $user="Admin"

                          $passwd="password"

                          $ilo = ${IP}

                           

                          $result = Get-HPiLOHealthSummary -server $ilo -username $user -password $passwd

                          $identifier = $result.Hostname

                          $ip = $result.IP

                          $storage = $result.STORAGE_STATUS

                          $proc = $result.PROCESSOR_STATUS

                          $network = $result.NETWORK_STATUS

                          $temp = $result.TEMPERATURE_STATUS

                          $mem = $result.MEMORY_STATUS

                          $bios = $result.BIOS_HARDWARE_STATUS

                          $fan = $result.FANS_STATUS

                           

                           

                          If ( $storage -ne 'OK' ) { Write-Host "Message.Storage: $storage"

                                                                Write-Host "Statistic.Storage: 0" }

                          Else                             { Write-Host "Statistic.Storage: 1"}

                           

                          If ( $proc -ne 'OK' ) { Write-Host "Message.Processor: $proc"

                                                            Write-Host "Statistic.Processor: 0" }

                          Else                         { Write-Host "Statistic.Processor: 1"}

                           

                          If ( $network -ne 'OK' ) { Write-Host "Message.Network: $network"

                                                                 Write-Host "Statistic.Network: 0" }

                          Else                              { Write-Host "Statistic.Network: 1"}

                           

                          If ( $temp -ne 'OK' ) { Write-Host "Message.Temperature: $temp"

                                                             Write-Host "Statistic.Temperature: 0" }

                          Else                          { Write-Host "Statistic.Temperature: 1"}

                           

                          If ( $mem -ne 'OK' ) { Write-Host "Message.Memory: $mem"

                                                            Write-Host "Statistic.Memory: 0" }

                          Else                         { Write-Host "Statistic.Memory: 1"}

                           

                          If ( $bios -ne 'OK' ) { Write-Host "Message.BIOS: $bios"

                                                           Write-Host "Statistic.BIOS: 0" }

                          Else                        { Write-Host "Statistic.BIOS: 1"}

                           

                          If ( $fan -ne 'OK' ) { Write-Host "Message.Fan: $fan"

                                                         Write-Host "Statistic.Fan: 0" }

                          Else                      { Write-Host "Statistic.Fan: 1"}

                           

                          #---------------------------End of Script---------------------------------#

                           

                           

                          I hope it helps!

                            • Re: HP Hardware monitor by Powershell script
                              krishna mishra

                              Thank you very Much.

                               

                              I have divide the script based on the individual h/w component, i.e Fan, Battery, Proc, Storage. So every time we can get the alert for all component in template..

                               

                              As per your script, we created the below template for battery.

                              ------------------------------

                              #ILO details

                              $user="Administrator"

                              $passwd="Password"

                              $ilo = ${IP}

                              $result = Get-HPiLOHealthSummary -server $ilo -username $user -password $passwd

                              $identifier = $result.Hostname

                              $ip = $result.IP

                              $Battery = $result.BATTERY_STATUS

                              If ( $Battery -ne 'OK' ) { Write-Host "Message.Battery: $Battery"

                               

                               

                                                             Write-Host "Statistic.Battery: 0" }

                               

                               

                              Else                      { Write-Host "Statistic.Battery: 1"}

                              ---------------------------------------------------------

                               

                              And i tested it on two node, (One node have battery issue and another node is in healthy) however we are getting the statistic value against the both node is "Zero"

                               

                              if i am correct, As per your script the statistic value should be "one" for healthy node and for problematic node it should be "Zero"

                              below is the error:-

                              Can you suggest i am doing anything wrong.

                               

                              thank in advance.

                                • Re: HP Hardware monitor by Powershell script
                                  yaquaholic

                                  The clue is in the error message

                                   

                                  The server you are running it against, doesn't have the Get-HPilo commandlets installed.

                                  Try switching to Remote Host execution and have the Get-HPilo commandlets installed, on your Orion server.

                                    • Re: HP Hardware monitor by Powershell script
                                      krishna mishra

                                      yes, Hp ILO CMD is installed on the Orion server.

                                       

                                      But when we are selecting the remote host, it require an additional setting like below, do we need to some additional config on ILO Server

                                       

                                      • Re: HP Hardware monitor by Powershell script
                                        krishna mishra

                                        As i am sure, Script will run by local host, and i tested the above script from Orion server (PS IDE), which is working fine, but we need to set the variable hostname instead on IP, So script can pic the hostname and give the result as expected.

                                         

                                        #ILO details

                                        $user="Administrator"

                                        $passwd="password"

                                        $ilo = "1x.x.x.x" # hostname should be variable

                                        $result = Get-HPiLOHealthSummary -server $ilo -username $user -password $passwd

                                        $identifier = $result.Hostname

                                        $ip = $result.IP # hostname should be

                                        $Battery = $result.BATTERY_STATUS

                                         

                                         

                                        If ( $Battery -ne 'OK' ) { Write-Host "Message.Battery: $Battery"

                                         

                                         

                                                                       Write-Host "Statistic.Battery: 0" }

                                         

                                         

                                        Else                      { Write-Host "Statistic.Battery: 1"}

                                         

                                         

                                        thanks

                                          • Re: HP Hardware monitor by Powershell script
                                            yaquaholic

                                            Try using one of the other macros, I would guess that ${Node.DNS} would be the best, as I seem to remember the hostname needs to match DNS for the commandlet to work.

                                             

                                            From: Best practices for SAM templates

                                            Use SolarWinds macros

                                            When using SolarWinds macros, consider assigning them to named variables in your scripts.

                                            The following SolarWinds macros are available for Linux/Unix, Nagios, Windows Script, and PowerShell script monitors:

                                            • ${USER}
                                            • ${PASSWORD}
                                            • ${PORT}
                                            • ${Node.SysName}
                                            • ${Node.Caption}
                                            • ${Node.DNS} - Use this instead of ${IP}.
                                            • ${Node.ID}
                                            • ${Component.ID}
                                            • ${Component.Name}
                                            • ${Application.Id}
                                            • ${Application.Name}
                                            • ${Application.TemplateId
                                            • ${Threshold.Warning}
                                            • ${Threshold.Critical}
                                            • Node Custom Property Macros${Node.CustomPropertyName}
                                            • Application Custom Property Macros${Application.CustomPropertyName}