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.

SAM Powershell Citrix Server Monitoring

Hoping someone here can give me a hand. I have a script to check for offline servers in Citrix that we are trying to run from SAM. I have tested the below script through powershell on the polling engine against the remote server via the invoke method. It works flawlessly that way. When trying to set it up in SAM I get Output Result: Not Defined. Here is the script:

Add-PSSnapin Citrix.XenApp.Commands

$AllXAServers = Get-XAServer | Sort-Object ServerName

$XAServers = @()

ForEach( $XAServer in $AllXAServers )

{

       $XAServers += $XAServer.ServerName

}

$OnlineXAServers = Get-XAZone | Get-XAServer -OnlineOnly | Sort-Object ServerName

$OnlineServers = @()

ForEach( $OnlineServer in $OnlineXAServers )

{

       $OnlineServers += $OnlineServer.ServerName

}

$OfflineServers = @()

ForEach( $Server in $XAServers )

{

       If( $OnLineServers -notcontains $Server )

       {

              $OfflineServers += $Server

       }

}

Write-Output $OfflineServers

I know there are probably some changes in regards to the write-output and I think that I have to have a statistic line but a bit lost there.

  • Any ideas out there? I have even tried some straight forward scripts that pull computername that work just fine from the polling engine itself but not through the SAM interface itself.

  • Script output must be properly formatted and use the proper exit code for the script to work properly with SAM.

    Scripts Must Report Status Through Exit Codes

    Scripts must report their status by exiting with the appropriate exit code:

    Exit Code

    Meaning

    0

    Up

    1

    Down

    2

    Warning

    3

    Critical

    Any other value

    Unknown

    For example, if you want to inform SolarWinds SAM that a VBScript reports Up status, you would exit the script using code similar to the following, where 0 reports Up:

    Wscript.quit(0)

    Scripts with Text Output

    Scripts report additional details by sending text to the script’s standard output. SAM supports multiple values returned by a script using the following format.

    Statistic.Name1: x
    Message.Name1: abc

    Statistic.Name2: y
    Message.Name2: abc

    Detail Type

    Required

    Meaning

    Statistic

    Yes

    A numeric value used to determine how the monitor compares to its set thresholds. This must be an integer value, (negative numbers are supported).

    Statistic.Name1: 123
    Statistic.Name2: 456

    Message

    No

    An error or information message to be displayed in the monitor status details. Note: Multi-line messages are supported. To use this functionality print each line using a separate command. For example:
    Message.Name1: abc
    Message.Name2: def

    There is a limit of ten Statistic and Message pairs for the script. These can be placed anywhere in the script output. The Statistic and Message names you give must contain valid letters and/or numbers.

    Sample output:

    # Script comment: This shows two pairs. Ten pairs are possible.

    Statistic.CPU: 31.08
    Message.CPU: svchost.exe cpu usage
    Statistic.RAM: 1234.56
    Message.RAM: svchost.exe ram usage

  • Thank you for the response Alterego. I have made some modifications since I posted and this is what I have now. It runs successfully from the local server when using the invoke-command. I have also verified that I am running winrm 2 and powershell 2. The polling engine itself is a Server 2008 R2 SP1 server. This is what the script looks like now. I have tried with an exit code but it still returns no output defined.

    Add-PSSnapin Citrix.XenApp.Commands

    $AllXAServers = Get-XAServer | Sort-Object ServerName

    $count = 0

    $XAServers = @()

    ForEach( $XAServer in $AllXAServers )

    {

           $XAServers += $XAServer.ServerName

    }

    $OnlineXAServers = Get-XAZone | Get-XAServer -OnlineOnly | Sort-Object ServerName

    $OnlineServers = @()

    ForEach( $OnlineServer in $OnlineXAServers )

    {

           $OnlineServers += $OnlineServer.ServerName

    }

    $OfflineServers = @()

    ForEach( $Server in $XAServers )

    {

           If( $OnLineServers -notcontains $Server )

           {

                  $OfflineServers += $Server

                  $count ++

           }

    }

    Write-Host $OfflineServers

    write-Host "Statistic: $count"

    The output from the write-host $OfflineServers all comes out in one long line so I figure that would only be one message output with one statistic output as well. Any other advice because I am 100% stumped right now. I keep wondering if it is something server side and have seen multiple threads where people installed .net, etc but I do have .net 4.5 and 3.5 was the original framework on the machine as well. Still getting output not defined though. If it matters even a simple script to check for computername fails miserably.

  • What is the exact error message? If you are receiving "PowerShell script error. Script output values are not defined or improperly defined." then you need to go to the application template setting page, open the component and "Edit script". There you have to test the script by running it against some node with some credentials. Then you should be able to see output something like "Statistic.Statistic: <value>". Then, when you hit save, the component template will be appended by "Script Output #1" section where the output will be defined and where you have another options to set for the value returned, but after hitting the submit / save and continue working, the monitors should start to work.

    Also, instead of "Write-Host $OfflineServers", you should output it like "Write-Host "Message: $OfflineServers"", because only statistic and messages are parsed and outputted.

  • A few noteworthy items worth pointing out...

    1. It looks like you're trying to pass a message to stdout without defining its output properly in "Write-Host $OfflineServers" This should instead read "Write-Host "Message: $OfflineServers".
    2. Based upon the XenApp SDK I downloaded it appears these cmdlets are 64bit, not 32bit. For compatibility purposes SAM used 32bit PowerShell by default. You can see if this is the problem by opening a 32bit PowerShell window and attempting to run your script. If it fails there, then it will fail in SAM. To use 64bit PowerShell with SAM you will need to edit the assigned application and change the "Platform to run polling job on". from x86 to x64. This will tell the application to use 64bit PowerShell instead of 32bit.

    x86.png

  • I actually read a post before hand where you mentioned the 64 bit portion. I have tried it on both but have kept it on x64 because it did fail on 32 bit. I have also adjusted the write-host with the message syntax and still get "Output Not Defined". Script run fines as a .ps1 on the polling engine where SAM is installed itself. Like I did say earlier though the odd thing is just a quick script to get the computer name of the remote machine that I got from Thwack ends up with the same results.

  • Can you take a screenshot of the output of the script as run from a PowerShell prompt outside of SAM? Your output variables suggest multiple values, though how those are formatted will determine if they can be read. As with any other script based monitoring solution, the script output must be properly structured so the product can read and interpret the results properly.

  • This is from the polling engine itself run against the remote host I have been testing against:

    SAM PS.PNG

    The output appears all in one line, excuse the fact that it was cut off on the right also please.

  • SInce the message field is optional, can you try removing it and seeing if that resolves the issue? Also, reviewing your script output again it doesn't appear as though you're properly exiting. You should have something to the effect of "exit(0)" as the last line so the script returns with an "Up" status. Another possibility are the permissions/credentials being used. Verify the script is configured to execute remotely and that the credentials being used are administrator or equivalent. Ideally they would be the same ones used that you are testing when executing the script from a PowerShell prompt.

    I would also suggest trying a very simple PowerShell script like the one below to eliminate the script as the issue. If this doesn't work, then there's something else going on likely WinRM related.

    $Test = $env:Processor_Architecture

    Write-Host 'Message:' $Test

    Write-Host 'Statistic: 1'

    exit(0)

  • So I tested the script you provided and it runs correctly from the polling engine itself but not from the SAM application itself. Is there any winrm output I can provide you with? I did also redo the credentials to make sure that they were correct.