5 Replies Latest reply on Oct 12, 2011 2:07 PM by tdanner

    Create a Node and interfaces and add pollers with .NET

    trondf

      I'm just getting started with testing out the SDK writing a program to compare data from our dokumentation DB to make sure that every Node and Interfaces with a connectionID exists in Orion and is polled.

      So far getting info from Orion is OK, the question is now how do I add a Node and interfaces using c# and .NET.

      swiclient.Create() takes string entityType and a dataset as args. This the right one to use? And if so how? Im lost at the dataset parameter :)

      swisclient.Invoke() Can this be used? Can't find a "create" verb in the documentation

       

      Any tips would be appreciated on how to solve this. 

       

      -TrondF

        • Re: Create a Node and interfaces and add pollers with .NET
          tom.rybka

          Orion SDK 1.3 contains samples in the documentation how you can use the experimental API for adding nodes and interfaces or changing their properties. This experimental API uses the generic CRUD operations. The samples are written in PowerShell but it shouldn't take much effort to rewrite them in C#.

          Have you took a look at it? Let us know if you have any questions.

            • Re: Create a Node and interfaces and add pollers with .NET
              trondf

              Yep well I had another look at it. 
              However it returns a protocol error wich I can't figure out. 

              "The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.solarwinds.com/2007/08/informationservice:properties. The InnerException message was 'There was an error deserializing the object of type SolarWinds.InformationService.Core.PropertyBag. Element 'item' was not found. Line 1, position 424.'.  Please see InnerException for more details."

              (The InnerException is null so no more info there)

              Heres my code if you could be so kind to see if there is something wrong there:

               

               

              
               
              using System;
              using System.Data;
              using System.Collections.Generic;
              using System.Linq;
              using System.Text;
               
              namespace OrionTest
              {
                  class Program
                  {
                      static void Main(string[] args)
                      {
                          Solarwinds.OrionService.InformationServiceClient client = new Solarwinds.OrionService.InformationServiceClient("BasicHttpBinding_InformationService");
                          System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
                          client.ClientCredentials.UserName.UserName = "XXXXXX";
                          client.ClientCredentials.UserName.Password = "XXXXXX";
               
               
               
                          System.Data.DataSet testNode = new System.Data.DataSet();
               
                          DataTable dt = new DataTable();
                          DataColumn EntityType = new DataColumn("EntityType",typeof(string));
                          DataColumn IPAddress = new DataColumn("IPAddress",typeof(string));
                          DataColumn Caption = new DataColumn("Caption",typeof(string));
                          DataColumn DynamicIP = new DataColumn("DynamicIP",typeof(bool));
                          DataColumn EngineID = new DataColumn("EngineID",typeof(int));
                          DataColumn Status = new DataColumn("Status",typeof(int));
                          DataColumn Allow64BitCounters = new DataColumn("Allow64BitCounters",typeof(bool));
                          DataColumn ObjectSubType= new DataColumn("ObjectSubType",typeof(string));
                          DataColumn SysObjectID = new DataColumn("SysObjectID",typeof(string));
                          DataColumn MachineType = new DataColumn("MachineType", typeof(string));
                          DataColumn VendorIcon = new DataColumn("VendorIcon",typeof(string));
                          DataColumn Community = new DataColumn("Community", typeof(string));
                          DataColumn SNMPVersion = new DataColumn("SNMPVersion",typeof(int));
               
                          dt.Columns.Add(EntityType);
                          dt.Columns.Add(IPAddress);
                          dt.Columns.Add(Caption);
                          dt.Columns.Add(DynamicIP);
                          dt.Columns.Add(EngineID);
                          dt.Columns.Add(Status);
                          dt.Columns.Add(Allow64BitCounters);
                          dt.Columns.Add(ObjectSubType);
                          dt.Columns.Add(SysObjectID);
                          dt.Columns.Add(MachineType);
                          dt.Columns.Add(VendorIcon);
                          dt.Columns.Add(Community);
                          dt.Columns.Add(SNMPVersion);
               
               
                          DataRow dr = dt.NewRow();
                          dr["EntityType"] = "OrionNodes";
                          dr["IPAddress"] = "192.168.1.55";
                          dr["Caption"] = "HP2610-Test";
                          dr["DynamicIP"] = false;
                          dr["EngineID"] = 1;
                          dr["Status"] = 1;
                          dr["Allow64BitCounters"] = true ;
                          dr["ObjectSubType"] = "SNMP";
                          dr["SysObjectID"] = "";
                          dr["MachineType"] = "";
                          dr["VendorIcon"] = "";
                          dr["Community"] = "public";
                          dr["SNMPVersion"] = 2;
               
                          dt.Rows.Add(dr);
                          testNode.Tables.Add(dt);
               
                          Console.WriteLine(dt.Rows);
               
               
               
                          string newNodeURI = client.Create("OrionNodes", testNode);
                          Console.WriteLine(newNodeURI);
               
                          Console.ReadKey();
                      }
                  }
              }
              
              


                • Re: Create a Node and interfaces and add pollers with .NET
                  derhally

                  There is an issue with how the proxy is generated when using svcutil or VisualStudio that makes it not compatible with the service.   You have two options to work around this issue    

                  You can either use the powershell snap-in to use the Create, Update, Delete methods or you can reference the assembly from 

                  "C:\Program Files\Common Files\SolarWinds\InformationService\SolarWinds.InformationService.Contract2.dll"

                  in your net project and use the InfoServiceProxy class.

                  Note this assembly has a dependency on SolarWinds.Logging and the log4net assemblies.

                    • Re: Create a Node and interfaces and add pollers with .NET
                      taylorfc

                      Can you provide an example?  I've added the DLL's to a new project and not making any headway.

                        • Re: Create a Node and interfaces and add pollers with .NET
                          tdanner

                          Here's a sample using SolarWinds.InformationService.Contract2.dll:

                           

                          using System;

                          using System.Diagnostics;

                          using System.Net;

                          using System.Net.Security;

                          using System.Security.Cryptography.X509Certificates;

                          using System.ServiceModel;

                          using System.ServiceModel.Channels;

                          using SolarWinds.InformationService.Contract2;

                           

                          namespace AddNode

                          {

                              class Program

                              {

                                  static void Main(string[] args)

                                  {

                                      ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate;

                           

                                      const string username = "admin";

                                      const string password = "";

                           

                                      var address = new Uri("https://localhost:17778/SolarWinds/InformationService/OrionBasic");

                           

                                      var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

                                      binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

                           

                                      var credentials = new UsernameCredentials(username, password);

                           

                                      var swis = new InfoServiceProxy(address, binding, credentials);

                           

                                      string uri = swis.Create("Orion.Nodes", new PropertyBag

                                                                                {

                                                                                    {"EntityType", "Orion.Nodes"},

                                                                                    {"IPAddress", "192.168.1.55"},

                                                                                    {"Caption", "HP2610-Test"},

                                                                                    {"DynamicIP", false},

                                                                                    {"EngineID", 1},

                                                                                    {"Status", 1},

                                                                                    {"Allow64BitCounters", true},

                                                                                    {"ObjectSubType", "SNMP"},

                                                                                    {"SysObjectID", ""},

                                                                                    {"MachineType", ""},

                                                                                    {"VendorIcon", ""},

                                                                                    {"Community", "public"},

                                                                                    {"SNMPVersion", 2}

                                                                                });

                                      Console.WriteLine(uri);

                           

                                      if (Debugger.IsAttached)

                                      {

                                          Console.WriteLine("Press enter to exit.");

                                          Console.ReadLine();

                                      }

                                  }

                           

                                  //Function ValidateRemoteCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean

                                  private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

                                  {

                                      return true;

                                  }

                              }

                          }