Hi, looking at the sample code on GitHub there is a method call "GetOneAlert". We are trying to do something real similar, but we want to get all alerts that are currently not acknowledged so that we can then run the ClearAlert verb against them. We have modified the SWQL query already to now pull back all non-acknowledged Alerts, but we aren't sure how to convert the sample code to pass a properly formatted set of objects to the "ClearAlert" verb.
If you look at the little snippet of code I pasted below from the sample, you can see that we tried removing the [0] from the var alertObjectId line, however I'm pretty confident that we need to do more.
I know in PowerShell I would simply do something like this to get the array of AlertObjectId's that I could then pass to the ClearAlert Verb. Basically I need to know what the equivalent to doing that in CSharp is so that we can pass a properly formatted object to ClearAlert.
$alertObjectIds = ($QueryResult.Results) | Select-Object -ExpandProperty AlertObjectId
That would then give me a variable array called $alertObjectIds that I could then pass to the verb. How do we need to modify the C# code below to get something similar? (I added tons of comments in the code below so you could see what the original code was before we changed it.):
private static int GetAllAlerts(ISwisClient swisClient) { const string query = @"SELECT AlertObjectID FROM Orion.AlertActive WHERE ISNULL(Acknowledged,0)!=1 ORDER BY TriggeredDateTime DESC"; JToken queryResult = swisClient.QueryAsync(query).Result; Console.WriteLine(queryResult); // THE BELOW CODE USES A [0] TO ONLY PULL THE FIRST ITEM FROM THE RESULTS, SO WE REMOVED THAT PART FROM THE CODE // var alertObjectId = (int)queryResult["results"][0]["AlertObjectID"]; // BY REMOVING THE [0] WE FIGURED THAT THE alertObjectId VARIABLE WOULD NOW CONTAIN ALL OF THE AlertObjectIDs RETURNED BY THE QUERY var alertObjectId = (int)queryResult["results"]["AlertObjectID"]; return alertObjectId; } // WE CHANGED THE METHOD CODE BELOW TO MAKE IT MORE APPROPRIATE FOR THE ClearAlert VERB // private static JToken AcknowledgeAlert(ISwisClient swisClient, int alertObjectId, string note) // THIS IS HOW THE METHOD IS NOW DECLARED: private static JToken ClearAlerts(ISwisClient swisClient, int alertObjectId) { // THE ORIGINAL CODE BELOW WAS CREATED TO INVOKE THE Acknowledge VERB FOR ONE ALERT. //JToken invokeResult = swisClient.InvokeAsync("Orion.AlertActive", "Acknowledge", new[] {alertObjectId}, note).Result; // WE CHANGED IT TO PASS THE ClearAlert VERB FOR (hopefully) HOW EVER MANY ALERTS CAME BACK AS A RESULT OF OUR QUERY // HOWEVER, WHEN IT GETS HERE WE GET AN ERROR ABOUT THE "alertObjectId" NOT BEING THE RIGHT TYPE OF OBJECT JToken invokeResult = swisClient.InvokeAsync("Orion.AlertActive", "ClearAlert", new[] {alertObjectId}).Result; return invokeResult; }
Thanks so much for any help you can give.