0 Replies Latest reply on Mar 28, 2016 5:49 PM by someniceuser

    Passing metrics from powershell to Hyperic HQ errors

    someniceuser Novice

      Good Evening,

       

      We are running a custom script that pulls metrics from Dell open manage. The script is supposed to push the metrics to the hyperic agent. But we I am not sure how to convert the script into hyperic?

       

       

      Where should we start?

       

      Here is copy of script:

       

       

      Param($action, $alertcode)

      #uses dell omsa commands,

      # set the variables below to suit environment.  The script will default to using localhost and port 25 if neither value is specified
      # Change the $MailSubject as preferred "COMPUTERNAME" and "ALERTDETAIL" will be replaced with the appropriate values if left in place.

      # For Gmail accounts:
      # set SMTPServer = "smtp.gmail.com"
      # set SMTPUser and SMTPPassword for gmail credentials, do not include @gmail.com part in the username
      # set SMTPPort = 587. Set EnableSSL = $true

      ## Change variables here

      # actual email to be sent from
      $EmailFrom = ""
      $EmailTo = ""
      $SMTPServer = ""
      # use 587 for gmail,
      $SMTPPort = "25"
      $SMTPUser = ""
      $SMTPPassword = ""
      $EnableSSL = $false
      $MailSubject = "Dell Server Alert on COMPUTERNAME - ALERTDETAIL"

      # Don't mess with mail subject, unless you will change more below

      ## End of variable ##

      # Start Functions

      function SetDellAlert
      {
              Param($DellEvent, $DellEventDescription, $EventID)
              $omsacommand = "omconfig system alertaction event=$DellEvent execappath=`"$powershellpath -executionpolicy unrestricted $scriptpath email $EventID`" "
              "Configuring Alert: $DellEvent ($DellEventDescription)"
              Invoke-Expression $omsacommand
      }


      function SendAlert($Subject)
      {
          $MailClient = new-object system.net.mail.smtpClient
          $MailClient.EnableSSL = $EnableSSL

          if ($SMTPServer -eq "") {$SMTPServer = "localhost"}
          if ($SMTPPort -eq "") {$SMTPPort = "25"}
          if ($SMTPUser -ne "")
          {
              $MailClient.UseDefaultCredentials = "false"
              $MailClient.Credentials = New-Object System.Net.NetworkCredential($SMTPUser, $SMTPPassword)
          }
        
          $MailMessage = New-Object system.net.mail.mailmessage
          $MailMessage.from = ($EmailFrom)
          $MailMessage.to.add($EmailTo)
          $MailMessage.subject = $Subject
          $MailMessage.body = ""
          $MailClient.Host = $SMTPServer
          $MailClient.Port = $SMTPPort
          $MailClient.Send($MailMessage)
      }


      Function CreateMessageBody
      {
          $result = invoke-expression "omreport chassis info"
          $result = $result + (invoke-expression "omreport system alertlog")
          $result  
      }
      # this can be changed after | to as need

      $AlertConfig = "powersupply|Power supply failure", "powersupplywarn|Power supply warning", "tempwarn|Temperature warning", "tempfail|Temperature failure", "fanwarn|Fan speed warning", "fanfail|Fan speed failure", "voltwarn|Voltage warning", "voltfail|Voltage failure", "intrusion|Chassis intrusion", "redundegrad|Redundancy degraded", "redunlost|Redundancy lost", "memprefail|Memory pre-failure", "memfail|Memory failure", "hardwarelogwarn|Hardware log warning", "hardwarelogfull|Hardware log full", "processorwarn|Processor warning", "processorfail|Processor failure", "watchdogasr|Watchdog asr", "batterywarn|Battery warning", "batteryfail|Battery failure", "systempowerwarn|Power warning", "systempowerfail|Power failure", "systempeakpower|Peak power", "removableflashmediapresent|Removable flash media present", "removableflashmediaremoved|Removable flash media removed", "removableflashmediafail|Removable flash media failure", "storagesyswarn|Storage System warning", "storagesysfail|Storage System failure", "storagectrlwarn|Storage Controller warning", "storagectrlfail|Storage Controller failure", "pdiskwarn|Physical Disk warning", "pdiskfail|Physical Disk failure", "vdiskwarn|Virtual Disk warning", "vdiskfail|Virtual Disk failure", "enclosurewarn|Enclosure warning", "enclosurefail|Enclosure failure", "storagectrlbatterywarn|Storage Controller Battery warning", "storagectrlbatteryfail|Storage Controller Battery failure"

      $ComputerName = gc env:computername

      $a = New-Object -ComObject Scripting.FileSystemObject
      $f = $a.GetFile("$pshome\powershell.exe")
      $powershellpath = $f.Path
      $fullscriptpath=$MyInvocation.Mycommand.path
      $f = $a.GetFile($fullscriptpath)
      $scriptpath=$f.shortpath

      if ($action)
          {
              $action = $action.trim().tolower()
              switch ($action)
                  {
        
                      "setup"
                      {
                          for ($i = 0; $i -lt $AlertConfig.count; $i++)
                              {
                                  $AlertDetails = $AlertConfig[$i].split("|")
                                  SetDellAlert $AlertDetails[0] $AlertDetails[1] $i
                              }
                      }
                      "email"
                      {
                          $AlertDetails = $AlertConfig[$alertcode].split("|")
                          $MailSubject = $MailSubject -replace('COMPUTERNAME', $ComputerName)              
                          $MailSubject = $MailSubject -replace('ALERTDETAIL', $AlertDetails[1])
                          Sendalert $MailSubject
                      }
                      "testemail"
                      {
                          $MailSubject = $MailSubject -replace('COMPUTERNAME', $ComputerName)
                          $MailSubject = $MailSubject -replace('ALERTDETAIL', "Test Alert")
                          Sendalert $MailSubject
                      }
         
                  }
          }