-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignl4_alert.cs
68 lines (53 loc) · 1.82 KB
/
signl4_alert.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.IO;
using System.Net;
using System.Text;
// Send SIGNL4 alert from C#
// Your SIGNL4 team secret
string teamSecret = "team-secret";
// Alert data
string json = @"{
'Title': 'Alert',
'Message': 'SIGNL4 alert from C#'
}";
sendSIGNL4Alert(teamSecret, json);
public static void sendSIGNL4Alert(string strTeamSecret, string strData)
{
string url = "https://connect.signl4.com/webhook/" + strTeamSecret;
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(strData);
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;
// Send the request
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
using (dataStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine("Status Code: {0}", (int)response.StatusCode);
Console.WriteLine(responseFromServer);
if ((int)response.StatusCode == 201) {
// Success
Console.WriteLine("Success");
}
else {
// Error
Console.WriteLine("Error");
}
}
response.Close();
}
catch (Exception e)
{
// Error
Console.WriteLine("Error: " + e.ToString());
}
}