using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Diagnostics;
|
using System.Runtime.InteropServices;
|
using System.Threading;
|
using System.Diagnostics;
|
|
namespace MonitorAlarm
|
{
|
class Program
|
{
|
public static string userid = System.Configuration.ConfigurationManager.AppSettings["userid"];
|
public static string account = System.Configuration.ConfigurationManager.AppSettings["account"];
|
public static string password = System.Configuration.ConfigurationManager.AppSettings["password"];
|
public static string Mobiles = System.Configuration.ConfigurationManager.AppSettings["Mobiles"];
|
|
static void Main(string[] args)
|
{
|
//设置控制台前景/背景色
|
Console.ForegroundColor = ConsoleColor.White;
|
Console.BackgroundColor = ConsoleColor.DarkBlue;
|
Console.Title = "系统异常监控";
|
Console.SetBufferSize(1000, 300);
|
|
Thread th = new Thread(new ThreadStart(_Run));
|
th.Start();
|
//
|
|
Console.Read();
|
}
|
|
|
protected static void _Run()
|
{
|
Console.WriteLine("异常监控服务启动...");
|
ZjunNewSMSNHandler sms = new ZjunNewSMSNHandler();
|
|
int SendCount = 0;
|
while (true)
|
{
|
Console.WriteLine("开始检查..."+DateTime.Now.ToString());
|
|
try
|
{
|
int count = Int32.Parse(DataHander.Instance.GetCount());
|
if (count >= 100 && SendCount<3)
|
{
|
SendCount++;
|
|
Console.BackgroundColor = ConsoleColor.Red;
|
Console.WriteLine($"半个小时前的未发送数据总数:{count}");
|
Console.WriteLine("发送短信告警...");
|
|
string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
|
string sign = gmd5(account + password + timestamp);
|
string content = "【中微】[非常紧急]客户端提交异常,请马上处理!";
|
string result = sms.SendSMS(userid, timestamp, sign, Mobiles, content, "", "");
|
Console.WriteLine($"提交结果:{result}");
|
}
|
else
|
{
|
if(count==0) { SendCount = 0; }
|
Console.BackgroundColor = ConsoleColor.DarkGreen;
|
Console.WriteLine($"半个小时前的未发送数据总数:{count}");
|
}
|
}
|
catch (Exception ex)
|
{
|
Console.BackgroundColor = ConsoleColor.Red;
|
Console.WriteLine($"异常:{ex.Message}");
|
}
|
|
Console.BackgroundColor = ConsoleColor.DarkBlue;
|
Console.WriteLine("检查结束..." + DateTime.Now.ToString());
|
Thread.Sleep(60000);
|
}
|
}
|
|
public static String gmd5(string s)
|
{
|
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
|
bytes = md5.ComputeHash(bytes);
|
md5.Clear();
|
string ret = "";
|
for (int i = 0; i < bytes.Length; i++)
|
{
|
ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
|
//ret += Convert.ToString(bytes[i],16).PadLeft(2,'0').ToUpper();//转换为大写
|
}
|
return ret.PadLeft(32, '0');
|
}
|
}
|
|
}
|