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.

Acknowledging Alerts with SWIS in C#

Hello

I am trying to acknowledge alerts using the invoke method. The only example I have is in java. I need to do this in C#. I thought I converted the code but the code I have is not acknowledging the alert. Do you have a code sample of how to acknowledge alerts in C#.

Thanks

  • As it happens, I do have that sample. The plan is to add it to the next SDK release, but I can post it here.

    CSClient.zip
  • Thank for the upload. Here is the problem I’m having. I am receiving the alert as a custom Alert type (I can’t change this). The Alert type has alertDefID, objectType, and activeObject all as strings. How do I receive the Alert object and convert it so that I can use the invoke method?

    Thanks so much

  • What do you mean when you say "I am receiving the alert as a custom Alert type"? What does that look like in the code? Where does it come from?

  • Hello

    Here is the Alert class.

    public class StringAlert

    {

    public Guid alertID;

    public string alertDefID;

    public string objectType;

    public DateTime triggerTimeStamp;

    public string objectName;

    public string activeObject;

    public string info;

    public DateTime acknowledgedTime;

    public string acknowledgedBy;

    public byte acknowledged;

    public string wsoc;

    public string remote;

    public string satellite;

    public string subsystem;

    public string terminalBand;

    }

    I send a query to swis. I get a DataTable as a result. Then I convert the result into the variables you see in the StringAlert class. This is the object I will receive when I need to acknowledge an alert.

    Thanks again

  • Ok, that should be easy to deal with. For each one of your StringAlert objects, create one of the AlertInfo objects (see the sample code for the definition) and populate it like this:

    • StringAlert.alertDefID -> AlertInfo.DefinitionId
    • StringAlert.objectType -> AlertInfo.ObjectType
    • StringAlert.activeObject -> AlertInfo.ObjectId

    Then you have a collection of AlertInfo objects that you can pass to Orion.AlertStatus.Acknowledge.

  • So one more question. How do I acknowledge alerts through code. Isn’t it

    Invoke(“Orion.AlertStatus”, “Acknowledge”, parameters);

    What are the parameters. My impression is that the parameters are an XmlElement array.

  • The "parameters" argument to Invoke is indeed an array of XmlElements. These should be the serialized representation of what the verb expects. In this case, the verb expects one parameter: an array of AlertInfo objects. You can use code like this to convert an arbitrary set of stuff you want to pass to the verb to XmlElements:

    private static XmlElement[] PrepareInvokeArguments(params object[] args)

            {

                var elements = new List<XmlElement>(args.Length);

                foreach (var arg in args)

                {

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

                    var doc = new XmlDocument();

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

                    {

                        dcs.WriteObject(writer, arg);

                    }

                    elements.Add(doc.DocumentElement);

                }

                return elements.ToArray();

            }

  • I hate to keep bothering you. Here is the code that I am running. I just tested it, and it’s not acknowledging the alert. Maybe I’m missing something.

    public class Acknowledge

        {

            public void AcknowledgeAlert(StringAlert stringAlert)

            {

                AlertInfo alertInfo = new AlertInfo();

                alertInfo.DefinitionId = stringAlert.alertDefID;

                alertInfo.ObjectType = stringAlert.objectType;

                alertInfo.ObjectId = stringAlert.activeObject;

                InfoServiceProxy swis = SolarWindsInformationService.GetSWISProxy();

                swis.Invoke("Orion.AlertStatus", "Acknowledge", PrepareInvokeArguments(alertInfo));

            }

            private static XmlElement[] PrepareInvokeArguments(params object[] args)

            {

                var elements = new List(args.Length);

                foreach (var arg in args)

                {

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

                    var doc = new XmlDocument();

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

                    {

                        dcs.WriteObject(writer, arg);

                    }

                    elements.Add(doc.DocumentElement);

                }

                return elements.ToArray();

            }

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

            public class AlertInfo

            {

                https://thwack.yoursite.com/DataMember(Order = 1)

                public string DefinitionId;

                https://thwack.yoursite.com/DataMember(Order = 2)

                public string ObjectType;

                https://thwack.yoursite.com/DataMember(Order = 3)

                public string ObjectId;

            }

  • I think you are pretty close. The Acknowledge verb expects an array of AlertInfo objects. This line should do the trick:

    swis.Invoke("Orion.AlertStatus", "Acknowledge", PrepareInvokeArguments(new[] { alertInfo }));

  • Well,

    I wish I knew what was going on. After the change, the alert still was not acknowledged.

    Thanks