34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using System;
|
|
using System.Net;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Types.Enums;
|
|
using Telegram.Bot.Types.ReplyMarkups;
|
|
|
|
namespace Monithor.api.Alerting {
|
|
public class MattermostWebhookTarget : ITarget {
|
|
public MattermostWebhookTarget(string url, IMonitor monitor, string displayName, string username = "monithor-alerting", string channel = "") {
|
|
_url = url;
|
|
_channel = channel;
|
|
_username = username;
|
|
Monitor = monitor;
|
|
_displayName = displayName;
|
|
}
|
|
|
|
private readonly string _url;
|
|
private readonly string _channel;
|
|
private readonly string _username;
|
|
public IMonitor Monitor { get; set; }
|
|
private readonly string _displayName;
|
|
|
|
public void SendMessage() {
|
|
var message = General.GetMessage(Monitor, _displayName);
|
|
var json = $"{{ \"channel\": \"{_channel}\", \"username\": \"{_username}\", \"text\": \"{message}\" }}".Replace("\n", "\\n");;
|
|
try {
|
|
new WebClient().UploadString(_url, json);
|
|
}
|
|
catch (Exception e) {
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
}
|
|
} |