using System;
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace RestartService.Alarm
|
{
|
public class AlarmHp
|
{
|
/// <summary>
|
/// 发送业务异常报警
|
/// </summary>
|
/// <param name="serviceName"></param>
|
/// <param name="alarmType"></param>
|
/// <param name="content"></param>
|
/// <param name="ip"></param>
|
public static void ApplicationAlarm(string serviceName, string alarmType, string content, string ip, string title)
|
{
|
//var dto = new
|
//{
|
// alarmType = alarmType,
|
// content = content,
|
// serviceIp = ip,
|
// serviceName = serviceName
|
//};
|
|
//var data = HttpHp.GetSignRequestJson(dto);
|
|
//var result = HttpHp.Post<ResponseData<object>>(ConfigurationManager.AppSettings["ApplicationAlarm"].ToString(), data);
|
//if (result != null && result.code == 0)
|
{
|
WechatAlarm(serviceName, "CUSTOM_ALARM", content, ip, "HIGH", title);
|
}
|
}
|
|
public static void ServiceAlarm(string serviceName, string content, string ip, string title)
|
{
|
//var dto = new
|
//{
|
// alarmType = "SPRING_BOOT_ADMIN",
|
// content = content,
|
// server = ip,
|
// application = serviceName,
|
// subType = "OFFLINE"
|
//};
|
|
//var data = HttpHp.GetSignRequestJson(dto);
|
|
//var result = HttpHp.Post<ResponseData<object>>(ConfigurationManager.AppSettings["ServiceAlarm"].ToString(), data);
|
//if (result != null && result.code == 0)
|
{
|
WechatAlarm(serviceName, "SPRING_BOOT_ADMIN", content, ip, "HIGH", title);
|
}
|
}
|
|
public static void WechatAlarm(string serviceName, string alarmType, string content, string ip, string alarmLevel, string subType)
|
{
|
var wechatDto = new
|
{
|
alarmType = alarmType,
|
alarmLevel = alarmLevel,
|
server = ip,
|
application = serviceName,
|
subType = subType,
|
time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
trace = Guid.NewGuid().ToString().Replace("-", string.Empty),
|
content = content
|
};
|
|
var wechatResult = HttpHp.Post<ResponseData<object>>(ConfigurationManager.AppSettings["WechatAlarm"], Newtonsoft.Json.JsonConvert.SerializeObject(wechatDto));
|
if (wechatResult != null && wechatResult.code == 0)
|
{
|
//发送成功
|
}
|
}
|
}
|
}
|