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.

try to add interface on a node with C#

Hi All,

Iam trying to AddInterfacesOnNode using C#:

this is interface data:

<d1p1:DiscoveredLiteInterface z:Id="183" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:d1p1="http://schemas.solarwinds.com/2008/NPM">

  <d1p1:ifIndex>579</d1p1:ifIndex>

  <d1p1:Caption z:Id="184">xe-1/0/5.20 · test orion</d1p1:Caption>

  <d1p1:ifType>135</d1p1:ifType>

  <d1p1:ifSubType>0</d1p1:ifSubType>

  <d1p1:InterfaceID>0</d1p1:InterfaceID>

  <d1p1:Manageable>true</d1p1:Manageable>

  <d1p1:ifSpeed>0</d1p1:ifSpeed>

  <d1p1:ifAdminStatus>0</d1p1:ifAdminStatus>

  <d1p1:ifOperStatus>4</d1p1:ifOperStatus>

</d1p1:DiscoveredLiteInterface>

And when i invoke this method --> var result3 = client.Invoke("Orion.NPM.Interfaces", "AddInterfacesOnNode", arguments2); with correct nodeid and the above discovered interface data ; i receive the below response:

<Return z:Id="1" xmlns="http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract" xmlns:d1p1="http://schemas.solarwinds.com/2008/NPM" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">

  <d1p1:DiscoveredInterfaces z:Id="2" z:Size="0" />

  <d1p1:Result>Succeed</d1p1:Result>

</Return>

however when i check Orion web console i don't see this interface in managed interfaces and still show unchecked in list of resources view (snapshot is attached)

so can anyone tell me what is wrong here and why the interface is not added?

Thanks

  • Can you show more of your code? How is "arguments2" constructed?

    Also, it looks like you are using XML, which implies that you are using the SOAP endpoint from C#. You might find it easier to work with the JSON endpoint.

  • Hi tdanner,

    I used 2 ways to be able to add the interface on a node :

    1st one is:

                ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

                var client = new InformationServiceClient("BasicHttpBinding_InformationService", string.Format("https://{0}:17778/SolarWinds/InformationService/v3/OrionBasic", hostname));

                client.ClientCredentials.UserName.UserName = username;

                client.ClientCredentials.UserName.Password = password;

                client.Open();

                var result = client.QueryXml("SELECT TOP 1 NodeID from Orion.Nodes WHERE sysname like 'bcgx7815' RETURN XML AUTO", null);

                var nodeID = result.XPathSelectElement("//*[local-name()='NodeID']").Value;

                var arguments = PrepareArguments(nodeID);

                XElement result2 = client.Invoke("Orion.NPM.Interfaces", "DiscoverInterfacesOnNode", arguments);

                foreach (XElement x1 in result2.XPathSelectElements("//*[local-name()='DiscoveredLiteInterface']"))

                {

                    foreach(XElement xe1 in x1.Elements())

                    {

                        if (xe1.Value.StartsWith("xe-1/0/5.20"))

                        {

                            //Console.Write(x1);

                            var arguments2 = PrepareArguments(nodeID, x1, "AddDefaultPollers");

                            var result3 = client.Invoke("Orion.NPM.Interfaces", "AddInterfacesOnNode", arguments2);

                            //Console.Write(result3);

                            break;

                        }

                    }

                }

    and variable x1 values is:

    <d1p1:DiscoveredLiteInterface z:Id="183" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:d1p1="http://schemas.solarwinds.com/2008/NPM">

      <d1p1:ifIndex>579</d1p1:ifIndex>

      <d1p1:Caption z:Id="184">xe-1/0/5.20 · test orion</d1p1:Caption>

      <d1p1:ifType>135</d1p1:ifType>

      <d1p1:ifSubType>0</d1p1:ifSubType>

      <d1p1:InterfaceID>0</d1p1:InterfaceID>

      <d1p1:Manageable>true</d1p1:Manageable>

      <d1p1:ifSpeed>0</d1p1:ifSpeed>

      <d1p1:ifAdminStatus>0</d1p1:ifAdminStatus>

      <d1p1:ifOperStatus>4</d1p1:ifOperStatus>

    </d1p1:DiscoveredLiteInterface>

    and i receive success but nothing is happening.

    2nd one is:

                 DiscoveredLiteInterface dis = new DiscoveredLiteInterface();

                 dis.Caption = "xe-1/0/5.20";

                 dis.ifIndex = 0;

                 dis.InterfaceID = 0;

                 dis.ifSubType = 0;

                 dis.Manageable = "true";

                 dis.ifType = 135;

                 dis.ifSpeed = 0;

                 dis.ifOperStatus = 0;

                 dis.ifAdminStatus = 0;

                 var arguments2 = PrepareArguments(nodeID, dis, "AddDefaultPollers");

                 var result3 = client.Invoke("Orion.NPM.Interfaces", "AddInterfacesOnNode", arguments2

    It succeeded too and i got same response with is success but nothin is happened

    Thanks

  • The second parameter for AddInterfacesOnNode is an array of interface objects. You are sending a bare interface object. SWIS is behaving like it parsed an empty array of interface objects.

    Try keeping the original return value from DiscoverInterfacesOnNode and just removing the DiscoveredLiteInterface elements that you don't want.

    Or switch to the json format, which I find easier to work with. There's a C# sample at OrionSDK/Samples/CSharp at master · solarwinds/OrionSDK · GitHub that you can use as a starting point, though it doesn't use these Discover/Add Interfaces verbs.

  • Do you have a smaple code to add interface on node with JSON endpoint?

    Thanks for help

  • I did it with JSON endpoint.

    Thanks alot

  • I'm glad you got it working!