I want to be able to execute a script to send alarms to a WebEx chat via webhooks as a one-way notification via a specific correlation rule. I know I can add a script to a correlation rule and was thinking this might be the way to send those alarms. I also know can send notifications to this WebEx space via a curl command that looks like this:
curl -X POST -H "Content-Type: application/json" -d '{"markdown" : "This is a formatted message from a Webex incoming webhook."}' "https://webexapis.com/v1/webhooks/incoming/{insert my unique key here}"
My very novice thought was to create an Automation Script that does the same thing in C# with test data, and then add the alarm information as parameters to the script in the correlation rule (somehow) but first create any Automation Script that POSTs anything to some URL, like:
using System;
using System.Net.Http;
using System.IO;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net;
using Skyline.DataMiner.Net.Exceptions;
using Skyline.DataMiner.Net.Messages;
using Skyline.DataMiner.Net.AutomationUI;
public class Script {
public static void Run(Engine engine) {
engine.GenerateInformation("Hello");
/* */
using (var httpClient = new HttpClient()) {
var jsonContent = "...";
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
httpClient.PostAsync(@"http:\\www.example.com", content);
}
/* */
}
}
The problem here seems to be is that while I can "using System.Net.Http;" with no errors, when I uncomment the section that uses HttpClient() like above, I get the validation error that "The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?)"
It is highly likely that this is completely pilot error, and I've seen other questions that suggest that this is possible with HttpClient(), but hoping that the community can help point me in the correct direction.
Thank you,
Jake
Hi Jake,
Can you try to add System.Net.Http.dll in the DLL references under the advanced section in the automation script and try again?
Regards,
Adding the DLL reference was the answer as was correctly escaping the quotes in the jsonContent
This example worked as a test Automation Script sending test messages to a WebEx chat group:
using System;
using System.Net.Http;
using System.Text;
using System.IO;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net;
using Skyline.DataMiner.Net.Exceptions;
using Skyline.DataMiner.Net.Messages;
using Skyline.DataMiner.Net.AutomationUI;
public class Script {
public static void Run(Engine engine) {
engine.GenerateInformation("Hello");
/* */
using (var httpClient = new HttpClient()) {
var message = "This is a **formatted message** from a Webex incoming webhook at _" + DateTime.Now.ToString("h:mm:ss tt") + "_.";
var jsonContent = "{"markdown" : "" + message + ""}";
var content = new StringContent(jsonContent.ToString(), Encoding.UTF8, "application/json");
var url = "https://webexapis.com/v1/webhooks/incoming/{insert webhook token here}";
var response = httpClient.PostAsync(url,content).GetAwaiter().GetResult();
engine.GenerateInformation("Response: |" + response + "|");
}
/* */
}
}
Next steps, parameterize the script so that we can put in placeholder data from the correlation rule.