7 Replies Latest reply on Aug 6, 2014 11:40 AM by juniordev

    Modern Examples for .NET 4.5

    taylorfc

      Curious if anyone has gotten the VB.NET or C# examples in the SDK running in Visual Studio 2013?  Solarwinds, when do you plan to provide updated .NET examples in the SDK?

        • Re: Modern Examples for .NET 4.5
          klinejw

          X2!  Appears that the API has been updated and the .Net examples are still old and out-of-date.

            • Re: Re: Modern Examples for .NET 4.5
              tdanner

              Here's a quick port of the old CSClient example to a more up-to-date style. It does the same thing as the old sample (query for the first unacknowledge alert and ack it) but it uses .NET 4.5, the System.Net.Http.HttpClient async client, and the SWIS REST API instead of SOAP.

               

              Send me your feedback on what you'd like to see in this sample and I'll get it rolled in to the next SDK drop.

                • Re: Modern Examples for .NET 4.5
                  ade

                  Drar tdanner,

                   

                  I downloaded the CSClient but still don't know how to compensate it to retrieve data from our solarwinds database

                   

                          private const string hostname = "localhost" ==>Should be the IP of the server hosting the solarwind

                          private const string username = "XXX"; ==> a valid username to access the solarwind web

                          private const string password = "XXX";

                   

                  but Still i am getting connection error. I think there are more parameters to change like

                  client.BaseAddress = new Uri(string.Format("https://{0}:17778/SolarWinds/InformationService/v3/Json/", hostname));

                   

                  Note that I am able to run the SWQL Studio

                   

                  please explain how to customize the class !

                    • Re: Re: Modern Examples for .NET 4.5
                      Steven Klassen

                      Hi Ade,

                       

                      The lines you quoted that set the hostname, username, and password need to be updated with your information. Once you've done that, the line you mentioned that sets the client.BaseAddress needs no further modification - it uses the hostname value you specified at the top of the file. The methods in the class are a little hard to explain without going into async/await but you can read up on it and then it should make more sense. In the meantime, would it be helpful to see a really simple use?

                       

                      using System;

                      ...

                       

                      namespace CSRestClient

                      {

                          class Program

                          {

                              private const string hostname = "192.168.21.55";

                              private const string username = "apitest";

                              private const string password = "<removed>";

                       

                              static void Main(string[] args)

                              {

                                  try

                                  {

                                      const string query = @"SELECT COUNT(1) as TotalNodes FROM Orion.Nodes";

                       

                                      var result = Query(query).Result;

                       

                                      Console.WriteLine("Raw results...");

                                      Console.WriteLine(result);

                       

                                      Console.WriteLine("Just the portion that contains the answer...");

                                      Console.WriteLine(result["results"][0]["TotalNodes"].ToString());

                       

                                      if (Debugger.IsAttached)

                                      {

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

                                          Console.ReadKey();

                                      }

                       

                                  }

                                  catch (Exception exception)

                                  {

                                      Console.WriteLine("There was an issue: {0}", exception.Message);

                                      throw;

                                  }

                              }


                              private static Task<JToken> Query(string query, object parameters = null)

                      ...

                        • Re: Modern Examples for .NET 4.5
                          ade

                          Hi Steven,

                           

                          Thanks for your response

                           

                          I understand your point of simplifying the part of retrieving the data but it does not reach that part of code since there is a connection error before.

                           

                          Anyway as per my readings the username & passwords are not the server authentication data but any username used to access our solarwinds NMS website (same are used in SWQL successfully).  I don't have problem in credentials

                           

                          I am afraid that I need to enable something in the server itself which means I cant use the SDK unless being the server admin. This is breaking the goal of SDK.

                  • Re: Modern Examples for .NET 4.5
                    juniordev

                    I agree that suggestion. I work on SWIS (Orion SDK) using VS 2010 and C# (.Net FW4). Maybe these below threads is helpful for you.

                     

                    Add node (or something) to NCM - NPM

                    Add Pollers & Node Details

                    NCM Node Details

                    Create container / subcontainer via SWIS

                    Add WMI Node with cred. via SWIS

                    Add Volume via SDK