8 Replies Latest reply on May 31, 2016 2:49 PM by edondurguti

    Set NCM Credentials

    ed_gpc

      Hello all -

       

      I've managed to successfully create nodes using v3, and add that node to NCM with v2.  One thing I am not seeing though is  how to set the credentials for NCM?

       

      I used

       

      XmlDocument xdoc = new System.Xml.XmlDocument();

      XmlElement[] elem = new System.Xml.XmlElement[1];

      XmlElement xel = xdoc.CreateElement("coreNodeId");

      this._NodeID.ToString();

      client.invoke("Cirrus.Nodes", "AddNodeToNCM", elem);

       

      Is there part of the XML that would set the credentials?

        • Re: Set NCM Credentials
          Jan Pelousek

          Hello, I'm affraid it's not possible to do it by using the verb "AddNodeToNCM" since the only acceptable argument is "CoreNodeId".

          Setting of the credentials is possible via Update/Set operation. Honestly I'm not very familiar with the language you use, but to demonstrate the principle, please see bellow the part of the code written in PowerShell:


          $Target="10.140.2.180"

          $swis = Connect-Swis -host $Target -UserName admin -Password "123" -V2

          [System.Int32]$NodeIdToAddToNCM = 11    ##Specify the nodeId you need to add to NCM

          Invoke-SwisVerb $swis Cirrus.Nodes AddNodeToNcm($NodeIdToAddToNCM)    ## Add Node to NCM

          [System.String] $Uri = Get-SwisData $swis ("SELECT Uri FROM Cirrus.Nodes WHERE CoreNodeID = " + $NodeIdToAddToNCM)    ##Get the Uri of the updated object

          Set-SwisObject $swis $Uri @{UserName='user1'; Password='bla'}    ##Specify the property bag to update and perform the Update action

           

          I hope this helps at least a bit.

           

          Honza

            • Re: Set NCM Credentials
              ed_gpc

              Thanks Jan.  Doesn't the NCM employ connection profiles?  So, I guess I would want to set the profile name rather than the user / pass.

               

              Language is c#

                • Re: Set NCM Credentials
                  madhavan

                  Hello,

                   

                    To set the credentials for NCM,

                   

                  1. For adding credentials for already added node, use “UpdateSelectedNodeColumns verb and provide values for Username, Password, EnableLevel, EnablePassword,…
                  2. You can also create connection profile using “AddConnectionProfile” and update ConnectionProfile property in Nodes using “UpdateSelectedNodeColumns”.
                    Use Connection Profile in case of using the same credentials for multiple nodes.
                  3. The credentials can be either encrypted or plain.

                   

                  It would be better to encrypt the credentials. To encrypt, use the below mentioned steps

                    

                  1. Use the verb ”EncryptData” against “Cirrus.Settings” entity to encrypt data. To use this connect to V2 certificate swis service.
                  2. You can also decrypt the data using the verb “DecryptData”.  
                    • Re: Set NCM Credentials
                      ed_gpc

                      Do I need to pass it in XML or in propertyBags?

                       

                      An example would be much appreciated!

                        • Re: Re: Set NCM Credentials
                          madhavan

                          AddConnectionProfile verb accepts 1 argument.

                           

                          1. ConnectionProfile - ConnectionProfile object. Incase you are creating a new connection profile.

                           

                          I've provided the ConnectionProfile class and the code to fill in the necessary values and create ConnectionProfile. This sample uses dummy values and fill with real values and use it.

                           

                          UpdateSelectedNodeColumns verb accepts 2 arguments.

                           

                          1. NCMNode - Node object. You can use GetNode verb to get the node details which can be edited and sent back as input to UpdateSelectedNodeColumns verb.
                          2. String[] - Array of Column names which are updated.

                           

                          We need to provide these two objects as parameter (As ArrayOfXmlElement).

                           

                          Complete Code

                           

                          Use this code for creating a new connectionProfile and update a node with the created connection profile. If you have a connection profile already created, just update the node with the profileid.

                           


                          #region Creating Connection Profile
                                      var connectionProfile = new ConnectionProfile
                                      {
                                          Name = "DummyName",
                                          UserName = "DummyUserName",
                                          Password = "DummyPassword"
                                      };
                                      var connectionProfiles = new[] { connectionProfile };
                                      var dcs = new DataContractSerializer(connectionProfile.GetType());
                                      var doc = new XmlDocument();
                                      using (var writer = doc.CreateNavigator().AppendChild())
                                      {
                                          dcs.WriteObject(writer, connectionProfile);
                                      }
                                      var connectionProfileArguments = new ArrayOfXmlElement { XDocument.Load(new XmlNodeReader(doc)).Root };
                                      var cpResult = client.Invoke("Cirrus.Nodes", "AddConnectionProfile", connectionProfileArguments);
                                      var connectionProfileID = cpResult.Value;
                                      #endregion
                                      #region Code for getting a node
                                      //Getting the Node for given GUID
                                      var arguments = new ArrayOfXmlElement();
                                      arguments.Add(XElement.Parse("<Guid>8e1dd779-df78-4068-813c-0069e72bc6d3</Guid>"));
                                      var result = client.Invoke("Cirrus.Nodes", "GetNode", arguments);
                                      #endregion
                                      #region Code for Updating connection profile
                                      XmlDocument xDoc = new XmlDocument();
                                      xDoc.LoadXml(result.ToString());
                                      //Forming the NcmNode input
                                      XmlDocument xNewDoc = new XmlDocument();
                                      var rootNode = xNewDoc.CreateElement("NcnNode");
                                      rootNode.InnerXml = xDoc.FirstChild.InnerXml;
                                      xNewDoc.AppendChild(rootNode);
                                      xNewDoc.SelectSingleNode(@"/NcnNode/*[local-name() = 'ConnectionProfile']").InnerText = connectionProfileID;
                                      arguments = new ArrayOfXmlElement();
                                      arguments.Add(XElement.Parse(xNewDoc.OuterXml));
                                      arguments.Add(XElement.Parse("<ArrayOfstring xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><string>ConnectionProfile</string></ArrayOfstring>"));
                                      var result2 = client.Invoke("Cirrus.Nodes", "UpdateSelectedNodeColumns", arguments);
                                      #endregion
                          

                          ConnectionProfile Class


                          [DataContract(Name = "ConnectionProfile", Namespace = "http://schemas.solarwinds.com/2007/08/informationservice/propertybag")]
                                  public class ConnectionProfile
                                  {
                                      public ConnectionProfile()
                                      {
                                          Name = string.Empty;
                                          UserName = string.Empty;
                                          Password = string.Empty;
                                          EnableLevel = "<No Enable Login>";
                                          EnablePassword = string.Empty;
                                          ExecuteScriptProtocol = "TELNET";
                                          RequestConfigProtocol = "TELNET";
                                          TransferConfigProtocol = "TELNET";
                                          TelnetPort = 23;
                                          SSHPort = 22;
                                          UseForAutoDetect = false;
                                      }
                                      [DataMember(Name = "ID")]
                                      public int ID { get; set; }
                                      [DataMember(Name = "Name")]
                                      public string Name { get; set; }
                                      [DataMember(Name = "UserName")]
                                      public string UserName { get; set; }
                                      [DataMember(Name = "Password")]
                                      public string Password { get; set; }
                                      [DataMember(Name = "EnableLevel")]
                                      public string EnableLevel { get; set; }
                                      [DataMember(Name = "EnablePassword")]
                                      public string EnablePassword { get; set; }
                                      [DataMember(Name = "ExecuteScriptProtocol")]
                                      public string ExecuteScriptProtocol { get; set; }
                                      [DataMember(Name = "RequestConfigProtocol")]
                                      public string RequestConfigProtocol { get; set; }
                                      [DataMember(Name = "TransferConfigProtocol")]
                                      public string TransferConfigProtocol { get; set; }
                                      [DataMember(Name = "TelnetPort")]
                                      public int TelnetPort { get; set; }
                                      [DataMember(Name = "SSHPort")]
                                      public int SSHPort { get; set; }
                                      [DataMember(Name = "UseForAutoDetect")]
                                      public bool UseForAutoDetect { get; set; }
                                  }
                          
                        • Re: Set NCM Credentials
                          Steven Klassen

                          Thanks madhavan! Why do you have to use v2 to access that verb? Is it something that's on its way out possibly?