5 Replies Latest reply on Dec 22, 2017 2:55 PM by tdanner

    Querying Via .NET


      Using SWQL, I am able to log into Orion and able to see the structure of the IPAM.IPNode and can query data.

      When I use .NET to connect, it accepts my login but when I try to query I get a response of connection refused.


      Using the SDK sample for VB.NET I get the same results.  I am able to see the alert data that the sample queries for on the web site.  I can see the IPAM infor as well.


      Is there a right that has to be turned on to allow me to query via code?

        • Re: Querying Via .NET

          No, there is no special right that needs to be turned on. If you can query via SWQL Studio, you can query via other clients.


          The current set of samples (OrionSDK/Samples at master · solarwinds/OrionSDK · GitHub ) does not include VB.NET, so I think you may be using older samples. But I don't know how old.


          Can you share your code?

            • Re: Querying Via .NET


              Thank you for the reply.


              You are correct, there were no online VB.NET samples, they only exist in C# in the .NET.

              I was using the documentation outlined in the Orion SDK.  Mine installed in the following location:

              "C:\Program Files (x86)\SolarWinds\Orion SDK\Documentation\Orion SDK.pdf"

              Below is the text from that document that I was using, it starts on page 18.


              The error was appearing for me on the line:

              GetOneAlert = alert

              in the function GetOneAlert.


              I put this in a format that I am hoping is easy to follow.  Obviously the credentials are the generic ones, change as needed.


              Imports Microsoft.VisualBasic
              Imports System.Net
              Imports System.Net.Security
              Imports System.Security.Cryptography.X509Certificates
              Imports System.Text
              Imports System.Xml
              Imports System.Runtime.Serialization
              Imports VBClient.SolarWinds.InformationService

              <DataContract(Name:="AlertInfo", [Namespace]:="http://schemas.solarwinds.com/2008/Orion")> _
              Class AlertInfo
                  <DataMember(Order:=1)> Public DefinitionId As String
                  <DataMember(Order:=2)> Public ObjectType As String
                  <DataMember(Order:=3)> Public ObjectId As String
              End Class


              Module Module1
                  Sub Main()
                      ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateRemoteCertificate
                      Using swis As InformationServiceClient = GetSwisClient()
                          Dim alert As AlertInfo = GetOneAlert(swis)
                          AcknowledgeAlert(swis, alert)
                      End Using
                  End Sub

                  Function ValidateRemoteCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
                      If My.Settings.IgnoreSslErrors Then
                          Return True
                      Else : Return sslPolicyErrors = Security.SslPolicyErrors.None
                      End If
                  End Function


                  Function GetSwisClient(Optional ByVal host As String = "localhost") As InformationServiceClient
                      Dim address As String = String.Format("https://{0}:17778/SolarWinds/InformationService/OrionBasic", host)
                      GetSwisClient = New InformationServiceClient("BasicHttpBinding_InformationService", address)
                      GetSwisClient.ClientCredentials.UserName.UserName = "admin"
                      GetSwisClient.ClientCredentials.UserName.Password = ""
                  End Function


                  Function GetOneAlert(ByVal swis As InformationServiceClient) As AlertInfo
                      Dim query As String, result As XElement
                      query = "SELECT TOP 1 A.AlertDefID, A.ActiveObject, A.ObjectType FROM Orion.AlertStatus A WHERE A.Acknowledged=0 ORDER BY A.TriggerTimeStamp DESC"
                      result = swis.QueryXml(query)
                      Dim ns As XNamespace = "http://schemas.solarwinds.com/2007/08/informationservice"
                      Dim alertData As XElement = result.Element(ns + "data").Element(ns + "A")
                      Dim alert As New AlertInfo With { _
                          .DefinitionId = alertData.Element(ns + "AlertDefID").Value, _
                          .ObjectType = alertData.Element(ns + "ObjectType").Value, _
                          .ObjectId = alertData.Element(ns + "ActiveObject").Value _
                      GetOneAlert = alert
                  End Function


                  Sub AcknowledgeAlert(ByVal swis As InformationServiceClient, ByVal ParamArray alerts() As AlertInfo)
                      Dim dcs As New DataContractSerializer(GetType(AlertInfo()))
                      Dim doc As New XmlDocument()
                      Using writer As XmlWriter = doc.CreateNavigator().AppendChild()
                          dcs.WriteObject(writer, alerts)
                      End Using
                      Dim arguments(0) As XmlElement
                      arguments(0) = doc.DocumentElement
                      Dim result As XElement
                      result = swis.Invoke("Orion.AlertStatus", "Acknowledge", arguments)

                  End Sub


              End Module