4 Replies Latest reply on May 21, 2018 2:18 PM by 300

    Can we use custom property values in Windows PowerShell Monitor?

    300

      I am referring to this thread Custom Variables within Application Monitor Templates

      I have created a custom property DBName and was trying to use it in a Windows PowerShell Monitor as ${Application.DBName}.

      To test it, I was just assigning it to a variable in the PowerShell script as $var1 = ${Application.DBName}; and print this variable as Write-Host "Message: " $var1

      But instead of printing the value in the custom property, it prints blank. Output is Message:

       

      Am I trying something that is not supported or just doing it wrong way?

      If this is not supported then is there any work around? I am also open to submit a request if that helps to add this as new feature.

       

      Thank you.

        • Re: Can we use custom property values in Windows PowerShell Monitor?
          yaquaholic

          Yes, you can, but you will need to get your powershell script to retrieve the information from the database first to populate the variable:

          Here's a quick example:

           

          #DB variables

          $SQLServer = "<your DB server>"

          $SQLDBName = "<your DB>"

          $uid ="<username>"

          $pwd = "<password>"

          $nodename = hostname                                                                                                                           #This will work if the hostname is the same in Orion, else hard code

          $SqlQuery = "SELECT Application.DBName FROM Nodes WHERE Caption = $nodename"              #Guessing that Application.DBName is a custom property of the Nodes table?

           

          #Connect, query and close

          $SqlConnection = New-Object System.Data.SqlClient.SqlConnection

          $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; User ID = $uid; Password = $pwd;"

          $SqlCmd = New-Object System.Data.SqlClient.SqlCommand

          $SqlCmd.CommandText = $SqlQuery

          $SqlCmd.Connection = $SqlConnection

          $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter

          $SqlAdapter.SelectCommand = $SqlCmd

          $var1 = New-Object System.Data.DataSet

          $SqlAdapter.Fill($DataSet)

          $SqlConnection.Close()

           

          I configured a read only user which I use for such things, but there are plenty of other ways to encrypt your user creds so they are not in plain text.

           

          You can also use the SwisSnapin (from the Orion SDK) if you'd prefer.

          • Re: Can we use custom property values in Windows PowerShell Monitor?
            300

            Finally, this worked for me:

            ${Application.Custom.<custom_property_name>}

             

            Just so that if someone comes to this thread for same issue.