This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Powershell - Output Critical

I am trying to run a Powershell monitor that outputs data from a SQL select statement, so that I can use the data in my alert bodies.

The below script runs against my database, and outputs a statistic value in char form.

$results = Invoke-Sqlcmd -Query "set nocount on;begin select ip.policyno as [Stat1]

from i1.dbo.DD_InstalmentPlan ip where ip.Status IN ('L', 'F', 'D', 'N')

end " -ServerInstance "********************" -Username "*********" -Password "*******"

$statistic1 = $results  | select -expand Stat1

write-host "Statistic.Stat1: $statistic1";

How do you get the output to be critical when it outputs a char rather than an integer?

Thanks

  • I want to say that the powershell script monitor won't even accept a character as the "statistic"

    You probably need to set logic in the script itself that would just output a dummy number for the statistic and then includes a message with the actual character in it, and then use exit codes to enforce the up/down/warning/critical status of the monitor.

    You can see all that explained in this post

    The Basics of PowerShell (part 3)

  • I can output as text, and hopefully if the text is not null then I can output a critical exit code

    I'll have a go and post my results. Thanks messverum

  • Or you can create a hash table with the matching lookups.

    $LookupTable = @{ 'L' = 1; 'F' = 2; 'D' = 3; 'N' = 4 }

    And then use that with...

    if ( -not ( $Statistic1 ) )

    {

        Write-Host "Statistic.Stat1: $( $LookupTable[$Statistic1] )"

        Write-Host "Message.Stat1: The command returned $Statistic1"

    }

    else

    {

       Write-Host "Statistic.Stat1: 0"

       Write-Host "Message.Stat1: The command returned nothing."

    }