Windows服务,线上的监控程序,监控指定的服务
1
高胜
2023-05-23 cf31c5a262ad9f8fe66e884c4ca82d6c060422ff
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using HDLMonitorService.Entity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace HDLMonitorService.Helper
{
    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,
                trace = Guid.NewGuid().ToString().Replace("-", string.Empty),
                alarmLevel = "HIGH"
            };
 
            var data = HttpHp.GetSignRequestJson(dto);
 
            var result = HttpHp.Post<ResponseData>(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 = "OFFLINE",
                content = content,
                serviceIp = ip,
                serviceName = serviceName,
                trace = Guid.NewGuid().ToString().Replace("-", string.Empty),
                alarmLevel = "HIGH"
            };
 
            var data = HttpHp.GetSignRequestJson(dto);
 
            var result = HttpHp.Post<ResponseData>(ConfigurationManager.AppSettings["ApplicationAlarm"].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>(ConfigurationManager.AppSettings["WechatAlarm"], Newtonsoft.Json.JsonConvert.SerializeObject(wechatDto));
        //    if (wechatResult != null && wechatResult.code == 0)
        //    {
        //        //发送成功
        //    }
        //}
    }
}