31 Replies Latest reply on Feb 16, 2017 3:57 PM by derhally

    Acknowledging Alerts with SWIS in C#

    tcwatkins

      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

        • Re: Acknowledging Alerts with SWIS in C#
          tdanner

          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.

            • Re: Acknowledging Alerts with SWIS in C#
              tcwatkins

              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

                • Re: Acknowledging Alerts with SWIS in C#
                  tdanner

                  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?

                    • Re: Acknowledging Alerts with SWIS in C#
                      tcwatkins

                      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

                        • Re: Acknowledging Alerts with SWIS in C#
                          tdanner

                          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.

                            • Re: Acknowledging Alerts with SWIS in C#
                              tcwatkins

                              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.

                                • Re: Acknowledging Alerts with SWIS in C#
                                  tdanner

                                  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();

                                          }

                                    • Re: Acknowledging Alerts with SWIS in C#
                                      tcwatkins

                                      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.solarwinds.com/2008/Orion")]

                                              public class AlertInfo

                                              {

                                                 

                                                  public string DefinitionId;

                                       

                                                 

                                                  public string ObjectType;

                                       

                                                 

                                                  public string ObjectId;

                                              }

                          • Re: Re: Acknowledging Alerts with SWIS in C#
                            scottfraley

                            Yo T, (or anyone who can answer this!) 

                             

                            I am also writing C# code to acknowledge alerts but plan on using the REST API. I've got the following two Uri's as possibles, but according to the documentation, Orion.AlertStatus has TWO Ack verbs.

                             

                            //"https://{0}:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.AlertStatus/Acknowledge

                            //"https://{0}:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.AlertStatus/AcknowledgeAlert

                             

                            So, I'm wondering what the difference is between the two (Acknowledge and AcknowledgeAlert), and which one should I use?

                             

                             

                            Thanks,

                            Scott F.

                              • Re: Re: Re: Acknowledging Alerts with SWIS in C#
                                tdanner

                                The one you want is Acknowledge. The other one, AcknowledgeAlert has some special sauce for integrating with Alert Central. The JSON payload you should send looks like this:

                                 

                                [
                                  [
                                    {
                                      "DefinitionId": "4918cfb4-b614-4db4-ba96-0de439f80c51",
                                      "ObjectType": "APM: Application",
                                      "ObjectId": "6",
                                      "Notes": "Don't worry - I've got this."
                                    }
                                  ]
                                ]
                                

                                 

                                The outer array is there because you always pass an array of arguments to an Invoke call. The inner array is there because the parameter to Orion.AlertStatus.Acknowledge is an array of AlertInfo objects. In this case I am just passing one, but you can ack multiple alerts in one call if you want. Note that the "acknowledged by" field will be set according to the credentials used to make this API call.

                                  • Re: Re: Re: Re: Acknowledging Alerts with SWIS in C#
                                    scottfraley

                                    Hey TD,

                                     

                                    The boss and I are both a little thrown off by the fact that none of those identifiers are unique, and so we're wondering how does Acknowledging an Alert work if a given device has an alert that has the same values (AlertDefID, ObjectType and ActiveObject) as another?

                                     

                                    Also, is there any documentation that explains the difference(s) between Events and Alerts?

                                     

                                    We're trying to integrate alerts (and/or events) with a ticketing system over here and want to make sure we're A) using the correct table(s), and B) have the ability to "Close" an alert/event. In fact, is acknowledgement of an alert the way it is 'closed'? or would you say that the concepts of an open or closed alert more appropriately belong within the 'Ticketing System' .. arena?

                                     

                                     

                                    Thanks,

                                    Scott

                              • Re: Acknowledging Alerts with SWIS in C#
                                murphypaj

                                Greeting all,

                                 

                                I want to acknowledge an alert using the Rest api on a pre v12 instance of Solarwinds. What's been causing me issues is that I am unable to ascertain what the objectId is when acknowledging an alert.

                                 

                                So I post to the below URL with the below Body for example. What I need to know is what is the variable for the objectId in this instance?

                                 

                                My intention is to have event triggered when the alert is triggered and I would like to pass these variables in a email for example using the alert manager.

                                 

                                URL:

                                https://solarwinds.mydomain.com/SolarWinds/InformationService/v3/Json/Invoke/Orion.AlertStatus/Acknowledge

                                 

                                BODY:

                                1. [   
                                2.   [   
                                3.     {   
                                4.       "DefinitionId": "F70CAB60-D451-4DBB-97D1-C84649DFC81E",   
                                5.       "ObjectId": "19",   
                                6.       "ObjectType": "Interface"   
                                7.     }   
                                8.   ]