103 lines
3.7 KiB
C#
103 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Net.Mail;
|
|
|
|
namespace SafeNetLib
|
|
{
|
|
public class AlertHandler
|
|
{
|
|
private DBhandle DB;
|
|
private Thread handleThread;
|
|
private string serverIP;
|
|
private string port;
|
|
private string logName;
|
|
private string pass;
|
|
private bool ssl;
|
|
|
|
private string sourceADR;
|
|
|
|
public AlertHandler(DBhandle _DB, string _serverIP, string _port, string _logName, string _pass, bool _ssl)
|
|
{
|
|
Utils.ConsWrite(DebugMSG_Type.ALERTS, "Alertt constructor !!");
|
|
DB = _DB;
|
|
|
|
serverIP = _serverIP;
|
|
port = _port;
|
|
logName = _logName;
|
|
pass = _pass;
|
|
ssl = _ssl;
|
|
|
|
|
|
handleThread = new Thread(new ThreadStart(HandleMethod));
|
|
handleThread.IsBackground = true;
|
|
handleThread.Start();
|
|
}
|
|
|
|
private void HandleMethod()
|
|
{
|
|
|
|
Utils.ConsWrite(DebugMSG_Type.ALERTS, "Alertt handle thread...");
|
|
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
|
|
Alert alert = SN_Queues.alertQueue.GetItem(100);
|
|
|
|
if (alert != null)
|
|
{
|
|
Utils.ConsWrite(DebugMSG_Type.ALERTS, "Unit SUID: " + alert.UnitIMEI + " generated an DI alert for mask: " + alert.DImask1);
|
|
DB.Insert_Alert_Event(alert);
|
|
|
|
//TODO: send emails if needed!!!
|
|
//DB.Get_Alert_Notification(alert);
|
|
//if (alert.Notification_email.Count > 0)
|
|
//{
|
|
// // if (alert.Notification_email == "")//I dont need to send an email
|
|
// // break;
|
|
// for (int i = 0; i < alert.Notification_email.Count; i++)
|
|
// {
|
|
// MailMessage message = new MailMessage();
|
|
// message.From = new MailAddress(logName);
|
|
// message.To.Add((string)alert.Notification_email[i]);
|
|
// message.Subject = alert.Alert_name + " on " + alert.UnitName;
|
|
// message.Body = alert.Alert_name +
|
|
// " on " + alert.UnitName +
|
|
// //" at " + DateTime.Now.ToUniversalTime().ToString("yyyy:MM:dd HH:mm:ss") +
|
|
// //" alert_id=" + alert.AlertDbID + "\n" +
|
|
// " Alert description: " + alert.Alert_description;
|
|
// message.IsBodyHtml = true;
|
|
|
|
// EmailServerSSL.sendEmail(serverIP, port, logName, pass, message, true);
|
|
// Utils.ConsWrite(DebugMSG_Type.ALERTS, "$$$$$ EMAIL sent to:" + alert.Notification_email[i]);
|
|
// }
|
|
//}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utils.ConsWrite(DebugMSG_Type.always, ex.ToString());
|
|
DB.DBconnected = false;
|
|
}
|
|
} // end while (true)
|
|
}
|
|
|
|
|
|
public void TestSendEmail(string dest_address, string msg)
|
|
{
|
|
MailMessage message = new MailMessage();
|
|
message.From = new MailAddress(logName);
|
|
message.To.Add(dest_address);
|
|
message.Subject = "test email";
|
|
message.Body = msg;
|
|
message.IsBodyHtml = true;
|
|
|
|
EmailServerSSL.sendEmail(serverIP, port, logName, pass, message, ssl);
|
|
}
|
|
}
|
|
}
|