3 Replies Latest reply on Sep 7, 2018 2:13 PM by rushcoil

    Issues getting PowerShell monitor script output in Alert Email

    rushcoil

      Hello,

       

      We have a PowerShell monitor set up to run an exe. We have PowerShell returning numerical codes based on result. The monitor appears to work correctly.

       

      We have an alert set up to monitor the PowerShell Monitor component for a few servers using this alert.

       

      The team has asked to see either the code that is generated or more preferably the script output in the alert email.

       

      I found this from a different Thwack thread but I do not see anything when we run simulate or execute for the email.

       

      I also do not see any error message. Here is what we are using in the Message body:

       

      ${SQL:Select StringData from APM_MultiValueAlertsData Where ComponentID=${ComponentID}}

       

      Do you know if this is set up correctly?

       

      Thanks!

        • Re: Issues getting PowerShell monitor script output in Alert Email
          muckman

          Lets back up to make sure your PowerShell is outputting the values correctly.

           

          All PowerShell scripts run within the context of SolarWinds SAM must use the following 2 outputs - An exit code to determine status of the component and a statistic. The statistic can mirror the exit code, can be hard coded to 0 or something valuable like counts or response time of an invoke-webrequest. Message is optional but helpful to pass a string into the alert like an exception.

           

          ## Pass in variables from SAM.
          ## Pass in arguments from SAM.
          
          ## PowerShell script does stuff.
          
          ## Exit codes (Outcome of stuff)
          Write-Host "Message: " $WhatEverStringYouWant
          Write-Host "Statistic: " $SomeInteger
          Exit 0
          

           

          To pass the message into the alert use this alert variable: ${N=SwisEntity;M=ComponentAlert.StatusOrErrorDescription}

          To pass the statistic into the alert use this alert variable: ${N=SwisEntity;M=ComponentAlert.StatisticData}

          1 of 1 people found this helpful
            • Re: Issues getting PowerShell monitor script output in Alert Email
              rushcoil

              Hello again and thanks for the details.

               

              Using your info I did get the status and the statistic but I cannot seem to get the message which is the main issue.

               

              Here is what I get using your two variables:

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

              Component is critical.

               

              128

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

               

              Unfortunately we still can't see the message.

               

              This is the PS script we are testing in the powershell monitor body to try and get a message:

               

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

              cd "D:\XXXXXX"

              .\YYYYY.exe

              if ($LASTEXITCODE -eq 0)

              {

                  Write-Host "Message.Success:0"

              }

              if ($LASTEXITCODE -eq 128)

              {

                  Write-Host "Message:  RadarStationFailureTest - 128"

              }

              Write-Host "Message: Testing 123"

              $outputvar = "Statistic.Success: " + $LASTEXITCODE

              Write-Host $outputvar

               

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

               

              This is how I have the alert set up:

               

               

               

              This is what I have in the Message of the Send an Email alert. I added another variable, the ComponentAlert.ComponentMessage which I thought may be the missing link but it still does not show the message.

               

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

              An issue on an object you are monitoring occurred at ${N=Alerting;M=AlertTriggerTime;F=DateTime}.

               

               

              Component Name = ${N=SwisEntity;M=ComponentAlert.ComponentName}

              Server Name = ${N=SwisEntity;M=Application.Node.Caption}

               

              ${N=SwisEntity;M=ComponentAlert.ComponentMessage}

               

              ${N=SwisEntity;M=ComponentAlert.StatusOrErrorDescription}

               

              ${N=SwisEntity;M=ComponentAlert.StatisticData}

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

               

              Thanks for any help if any of this looks way off. We are still quite new to SolarWinds.

            • Re: Issues getting PowerShell monitor script output in Alert Email
              nks7892

              Few points to note here -

              a. Script is running successfully when you are using Power Shell monitor template on Target Machine.

              b. Script contains variables defined for Statistic and Message.

               

              If answer to above points is yes then you can call Statistic and Message variable in the alert email body using - Statistic -Numeric value and Message Application/Component.

              1 of 1 people found this helpful