Quantcast
Channel: THWACK: All Content - All Communities
Viewing all articles
Browse latest Browse all 20205

How to create array of arguments for Unmanage/Remanage? (C#)

$
0
0

I am trying to write a method for Unmanaging and Remanaging nodes in Orion, in C#. Using the CSClient example, I've been able to write a query Orion for a NodeID based on sysname. However, when I want to Invoke("Orion.Nodes", "Unmanage", args) I don't know how to correctly create the ArrayOfXMLElement that the method seems to want. I tried modifying the code used for the alert example, but it gives me "FaultException`1" when I try it. I created the data object to store the arguments based on the column names in the Nodes table. I am using VS2010, .net 4.0, Orion 2012.2.0, and SDK 1.6. I am very new at this so please be gentle :-) The portion of the code that gets the NodeID based on sysname works fine.

 

This is what my code looks like:

 

using System;

using System.Net;

using System.Runtime.Serialization;

using System.Xml;

using System.Linq;

using System.Xml.Linq;

using System.Xml.XPath;

using CSClient.SWIS;

 

namespace CSClient

{

    class Program

    {

        static void Main()

        {

            const string hostname = "myorionserver";

            const string username = @"myuser";

            const string password = "mypassword";

           

            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 nodeIDInfo = client.QueryXml("SELECT TOP 1 NodeID from Orion.Nodes WHERE sysname like 'targetserver' RETURN XML AUTO", null);

            nodeIDInfo.Save(@"c:\temp\orionoutput.xml");

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

            Console.WriteLine("Node ID is " + nodeID.ToString());

 

            string unmanageFrom = DateTime.Now.ToString();

            string unmanageUntil = DateTime.Now.AddHours(6).ToString();

 

            var unmanageInfo = new UnmanageInfo

            {

                NodeID = nodeID,

                UnManageFrom = unmanageFrom,

                UnManageUntil = unmanageUntil

            };

            var unmanaged = new[] { unmanageInfo };

 

            var dcs = new DataContractSerializer(unmanaged.GetType());

            var doc = new XmlDocument();

            using (var writer = doc.CreateNavigator().AppendChild())

            {

                dcs.WriteObject(writer, unmanaged);

            }

 

            var arguments = new ArrayOfXmlElement { XDocument.Load(new XmlNodeReader(doc)).Root };

            var result2 = client.Invoke("Orion.Nodes", "Unmanage", arguments);

            Console.Write(result2);

            Console.Read();

        }

 

        [DataContract(Name = "UnmanageInfo", Namespace = "http://schemas.solarwinds.com/2008/Orion")]

        public class UnmanageInfo

        {

            [DataMember(Order = 1)]

            public string NodeID;

 

            [DataMember(Order = 2)]

            public string UnManageFrom;

 

            [DataMember(Order = 3)]

            public string UnManageUntil;

 

        }

 

    }

}


Viewing all articles
Browse latest Browse all 20205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>