Ejemplo n.º 1
0
        public string EmailBody(string Ip, double Cpu, SysValues PhysMem, SysValues VirMem, List <SysValues> Disk)
        {
            string        strTraceToLog = null;
            StringBuilder sbTrace       = new StringBuilder();

            //var Ip= _SysData.GetIpAddress();
            //var Cpu=_SysData.GetProcessorData();
            //var PhysMem=_SysData.GetPhysicalMemory();
            //var VirMem = _SysData.GetVirtualMemory();
            //var Disk=_SysData.GetDiskSpaces();
            sbTrace.Append("<p><span >Dear Sir/Mom,</span><br /></p>");
            sbTrace.Append("<p> &nbsp; </p>");
            sbTrace.Append("<p>-----------------------------------------------------</p>");
            sbTrace.Append("<p>" + GeneralCommon.ConvertDateToString(DateTime.Now) + "</p>");
            sbTrace.Append("<p> Checking Ip Address : </p>");
            sbTrace.Append("<p>" + Ip);
            sbTrace.Append("<p>----------  Checking System -----------</p>");
            sbTrace.Append("<p> CPU Used " + Cpu.ToString("F") + " % " + "</p>");
            sbTrace.Append("<p>" + LogSysValueWithUsage(PhysMem) + "</p>");
            sbTrace.Append("<p>" + LogSysValueWithUsage(VirMem) + "</p>");
            sbTrace.Append("<p> Disk Drive :</p>");
            foreach (SysValues v in Disk)
            {
                sbTrace.Append("<p> " + LogSysValueWithUsage(v) + "</p>");
            }
            sbTrace.Append("<p>&nbsp;</p>");
            sbTrace.Append("<p>&nbsp;</p>");
            sbTrace.Append("<p>Regards,</p>");
            sbTrace.Append("<p>&nbsp;</p>");
            sbTrace.Append("<p>Harigajian.com</p>");
            strTraceToLog = sbTrace.ToString();
            return(strTraceToLog);
        }
Ejemplo n.º 2
0
        public string RunningAction(string Ip, double Cpu, SysValues PhysMem, SysValues VirMem, List <SysValues> Disk)
        {
            string        strTraceToLog = null;
            StringBuilder sbTrace       = new StringBuilder();

            //var Ip= _SysData.GetIpAddress();
            //var Cpu=_SysData.GetProcessorData();
            //var PhysMem=_SysData.GetPhysicalMemory();
            //var VirMem = _SysData.GetVirtualMemory();
            //var Disk=_SysData.GetDiskSpaces();

            sbTrace.Append("\r\n-----------------------------------------------------");
            sbTrace.Append("\r\n" + GeneralCommon.ConvertDateToString(DateTime.Now));
            sbTrace.Append("\r\n Checking Ip Address :");
            sbTrace.Append("\r\n" + Ip);
            sbTrace.Append("\r\n----------  Checking System -----------");
            sbTrace.Append("\r\n CPU Used " + Cpu.ToString("F") + " % ");
            sbTrace.Append("\r\n" + LogSysValueWithUsage(PhysMem));
            sbTrace.Append("\r\n" + LogSysValueWithUsage(VirMem));
            foreach (SysValues v in Disk)
            {
                sbTrace.Append("\r\n" + LogSysValueWithUsage(v));
            }
            sbTrace.Append("\r\n");
            strTraceToLog = sbTrace.ToString();
            return(strTraceToLog);
        }
Ejemplo n.º 3
0
        public static int?SendNotificationGlobal(string EmailTo, string Subject, string MessageContent, string ParamConfig)
        {
            int?status = 1;

            try
            {
                //var dbMAILCONFIG = Common.getSysParam(ParamConfig);
                string[] config   = ParamConfig.Split(new char[] { '|' });
                int      port     = Convert.ToInt16(config[1]);
                string   Security = config[5];
                if (!string.IsNullOrEmpty(EmailTo))
                {
                    var mymessage = new MimeMailMessage();
                    mymessage.From = new MimeMailAddress(config[2]);
                    mymessage.To.Add(EmailTo);
                    mymessage.Subject  = Subject;
                    mymessage.Body     = MessageContent;
                    mymessage.Priority = System.Net.Mail.MailPriority.High;
                    var mailer = new MimeMailer(config[0], port);
                    mailer.User     = config[3];
                    mailer.Password = GeneralCommon.Decrypt(config[4]);
                    if (Security == "TLS")
                    {
                        mailer.SslType = SslMode.Tls;
                    }
                    else if (Security == "SSL")
                    {
                        mailer.SslType = SslMode.Ssl;
                    }
                    else if (Security == "NONE")
                    {
                        mailer.SslType = SslMode.Ssl;
                    }
                    else
                    {
                        mailer.SslType = SslMode.Auto;
                    }

                    if (mailer.SslType == SslMode.None)
                    {
                        mailer.AuthenticationMode = AuthenticationType.PlainText;
                    }
                    else
                    {
                        mailer.AuthenticationMode = AuthenticationType.Base64;
                    }
                    mailer.SendCompleted += compEvent;
                    mailer.SendMail(mymessage);
                    status = 0;
                }
            }
            catch (Exception ex)
            {
                status = -1;
                //UIException.LogException(ex, "public static long SendNotification(string EmailTo,string Subject,string MessageContent)");
            }
            return(status);
        }
Ejemplo n.º 4
0
        public string  StartAction()
        {
            string        strTraceToLog = null;
            StringBuilder sbTrace       = new StringBuilder();

            sbTrace.Append("=========================================================");
            sbTrace.Append("\r\n" + GeneralCommon.ConvertDateToString(DateTime.Now));
            sbTrace.Append("\r\n Start Checking System Notification");
            sbTrace.Append("\r\n");
            strTraceToLog = sbTrace.ToString();
            return(strTraceToLog);
        }
Ejemplo n.º 5
0
        public string ErrorAction(string strSource, string strEx)
        {
            string        strTraceToLog = null;
            StringBuilder sbTrace       = new StringBuilder();

            sbTrace.Append("\r\n-------------------  Exception  ---------------------");
            sbTrace.Append("\r\n" + GeneralCommon.ConvertDateToString(DateTime.Now));
            sbTrace.Append("\r\n" + strSource);
            sbTrace.Append("\r\n" + strEx);
            sbTrace.Append("\r\n");
            strTraceToLog = sbTrace.ToString();
            return(strTraceToLog);
        }
Ejemplo n.º 6
0
        public string tempUnsplit(double Cpu, SysValues PhysMem, SysValues VirMem, List <SysValues> Disk, bool strBolean)
        {
            string strTraceToLog = null;
            string tempDisk      = "";

            var tempCpu  = Math.Round(Cpu, 2).ToString();
            var tempPhys = GeneralCommon.ConvertToPercent(PhysMem).ToString();
            var tempVir  = GeneralCommon.ConvertToPercent(VirMem).ToString();

            foreach (var item in Disk)
            {
                tempDisk = tempDisk + GeneralCommon.ConvertToPercent(item).ToString() + "#";
            }
            tempDisk      = tempDisk.Remove(tempDisk.Length - 1);
            strTraceToLog = tempCpu + "|" + tempPhys + "|" + tempVir + "|" + tempDisk + "|" + strBolean;
            return(strTraceToLog);
        }
Ejemplo n.º 7
0
        private void timer1_Elapsed(object sender, ElapsedEventArgs e, bool sendNotif)
        {
            BuilderString builder = new BuilderString();
            string        strTraceToLog = null;
            string        strEmailBody = null;
            double        pPhysMem = 0, pVirMem = 0, pCPU = 0;
            List <double> pDisk = new List <double>();
            double        textPhysMem = 0, textVirMem = 0, textCPU = 0;
            bool          textBolean;
            List <double> textDisk = new List <double>();
            string        strRead  = "";

            try
            {
                CheckingSystemLogger tempLogger = new CheckingSystemLogger(TEMP_PARAMETER);
                tempLogger.ReadTempAsynch(out strRead);

                var Ip      = _SysData.GetIpAddress();
                var Cpu     = _SysData.GetProcessorData();
                var PhysMem = _SysData.GetPhysicalMemory();
                var VirMem  = _SysData.GetVirtualMemory();
                var Disk    = _SysData.GetDiskSpaces();

                pCPU     = Math.Round(Cpu, 2);
                pPhysMem = GeneralCommon.ConvertToPercent(PhysMem);
                pVirMem  = GeneralCommon.ConvertToPercent(VirMem);
                foreach (var item in Disk)
                {
                    var tempItem = GeneralCommon.ConvertToPercent(item);
                    pDisk.Add(tempItem);
                }
                if (strRead == string.Empty)
                {
                    if (Cpu >= CPUAlert)
                    {
                        strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                        if (sendNotif)
                        {
                            var strEmail = EmailTo.Split('|');
                            strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                            foreach (var item in strEmail)
                            {
                                Notification.SendNotificationGlobal(item, Subject, strEmailBody, connectionString);
                            }
                            sendNotif = false;
                            var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, sendNotif);
                            tempLogger.WriteTempAsych(strTemp);
                        }
                    }

                    if (pPhysMem >= PhysicalMemoryAlert)
                    {
                        strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                        if (sendNotif)
                        {
                            var strEmail = EmailTo.Split('|');
                            strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                            foreach (var item in strEmail)
                            {
                                Notification.SendNotificationGlobal(item, Subject, strEmailBody, connectionString);
                            }
                            sendNotif = false;
                            var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, sendNotif);
                            tempLogger.WriteTempAsych(strTemp);
                        }
                    }

                    if (pVirMem >= VirtualMemoryAlert)
                    {
                        strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                        if (sendNotif)
                        {
                            var strEmail = EmailTo.Split('|');
                            strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                            foreach (var item in strEmail)
                            {
                                Notification.SendNotificationGlobal(item, Subject, strEmailBody, connectionString);
                            }
                            sendNotif = false;
                            var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, sendNotif);
                            tempLogger.WriteTempAsych(strTemp);
                        }
                    }

                    foreach (var item in Disk)
                    {
                        var tempPdisk = GeneralCommon.ConvertToPercent(item);
                        pDisk.Add(GeneralCommon.ConvertToPercent(item));
                        if (tempPdisk >= DiskSpaceAlert)
                        {
                            strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                            if (sendNotif)
                            {
                                var strEmail = EmailTo.Split('|');
                                strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                                foreach (var itemEmail in strEmail)
                                {
                                    Notification.SendNotificationGlobal(itemEmail, Subject, strEmailBody, connectionString);
                                }
                                sendNotif = false;
                                var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, sendNotif);
                                tempLogger.WriteTempAsych(strTemp);
                            }
                        }
                    }
                }
                else
                {
                    builder.tempSplit(strRead, out textCPU, out textPhysMem, out textVirMem, out textDisk, out textBolean);
                    SendNotif = textBolean;
                    if (pCPU >= CPUAlert)
                    {
                        if (pCPU >= textCPU + 10)
                        {
                            strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                            if (sendNotif)
                            {
                                var strEmail = EmailTo.Split('|');
                                strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                                foreach (var item in strEmail)
                                {
                                    Notification.SendNotificationGlobal(item, Subject, strEmailBody, connectionString);
                                }
                                sendNotif = false;
                                var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, SendNotif);
                                tempLogger.WriteTempAsych(strTemp);
                            }
                        }
                    }
                    else if (pPhysMem >= PhysicalMemoryAlert)
                    {
                        if (pPhysMem >= textPhysMem + 10)
                        {
                            strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                            if (sendNotif)
                            {
                                var strEmail = EmailTo.Split('|');
                                strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                                foreach (var item in strEmail)
                                {
                                    Notification.SendNotificationGlobal(item, Subject, strEmailBody, connectionString);
                                }
                                sendNotif = false;
                                var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, SendNotif);
                                tempLogger.WriteTempAsych(strTemp);
                            }
                        }
                    }
                    else if (pVirMem >= VirtualMemoryAlert)
                    {
                        if (pVirMem >= textVirMem + 10)
                        {
                            strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                            if (sendNotif)
                            {
                                var strEmail = EmailTo.Split('|');
                                strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                                foreach (var item in strEmail)
                                {
                                    Notification.SendNotificationGlobal(item, Subject, strEmailBody, connectionString);
                                }
                                sendNotif = false;
                                var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, SendNotif);
                                tempLogger.WriteTempAsych(strTemp);
                            }
                        }
                    }
                    else
                    {
                        SendNotif = true;
                        var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, SendNotif);
                        tempLogger.WriteTempAsych(strTemp);
                    }

                    for (int i = 0; i < pDisk.Count(); i++)
                    {
                        //var tempPdisk = GeneralCommon.ConvertToPercent(item);
                        //pDisk.Add(GeneralCommon.ConvertToPercent(item));
                        if (pDisk[i] >= DiskSpaceAlert)
                        {
                            if (pDisk[i] >= textDisk[i] + 10)
                            {
                                strTraceToLog = builder.RunningAction(Ip, Cpu, PhysMem, VirMem, Disk);
                                if (sendNotif)
                                {
                                    var strEmail = EmailTo.Split('|');
                                    strEmailBody = builder.EmailBody(Ip, Cpu, PhysMem, VirMem, Disk);
                                    foreach (var item in strEmail)
                                    {
                                        Notification.SendNotificationGlobal(item, Subject, strEmailBody, connectionString);
                                    }
                                    sendNotif = false;
                                    var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, sendNotif);
                                    tempLogger.WriteTempAsych(strTemp);
                                }
                            }
                        }
                        else
                        {
                            SendNotif = true;
                            var strTemp = builder.tempUnsplit(Cpu, PhysMem, VirMem, Disk, sendNotif);
                            tempLogger.WriteTempAsych(strTemp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                strTraceToLog = builder.ErrorAction(ex.Source.ToString(), ex.Message);
            }
            finally
            {
                if (strTraceToLog != null)
                {
                    CheckingSystemLogger oLogger = new CheckingSystemLogger(DEFAULT_PARAMETER);
                    oLogger.WriteAsych(strTraceToLog.ToString());
                }
            }
        }