public MerakMailRecorder()
     : base()
 {
     LogName = "MerakMailRecorder";
     usingKeywords = false;
     lineLimit = 50;
     data = new Data();
 }
Esempio n. 2
0
		public void WriteFile(String dir, Data data)
        private bool Send_Rec_Data(Data data)
        {
            CustomBase.Rec rec = new CustomBase.Rec();
            try
            {
                rec.ComputerName = data.computername;
                rec.Datetime = data.datetime;
                rec.Description = data.description;
                rec.EventType = data.eventtype;
                rec.LogName = data.logname;
                rec.CustomStr1 = data.str1;
                rec.CustomStr2 = data.str2;
                rec.CustomStr3 = data.str3;
                rec.CustomStr4 = data.str4;
                rec.CustomStr6 = data.str6;
                rec.CustomStr7 = data.str7;
                rec.CustomStr8 = data.str8;

                SetRecordData(rec);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public override bool ParseSpecific(String line, bool dontSend)
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseSpecific() | Parsing Specific line. Line : " + line);
                if (string.IsNullOrEmpty(line))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseSpecific() | Line is Null Or Empty. ");
                    return true;
                }

                if (line.Length < 850)
                    data.description = line;
                else
                    data.description = line.Substring(0, 850);

                data.logname = LogName;

                if (!dontSend)
                {
                    string[] parts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    //10.6.3.155      [0838] 09:33:03 Connected, local IP=10.6.21.17
                    //10.6.21.6       [15C0] 00:02:10 >>> 220 mail.kosgeb.gov.tr ESMTP IceWarp 10.3.1; Mon, 16 May 2011 00:02:10 +0300
                    //10.6.21.6       [15C0] 00:02:10 <<< EHLO sbg.kosgeb.gov.tr
                    //10.6.21.6       [15C0] 00:02:10 >>> 250-mail.kosgeb.gov.tr Hello sbg.kosgeb.gov.tr [10.6.21.6], pleased to meet you.
                    //10.6.21.6       [15C0] 00:02:10 <<< MAIL FROM:<*****@*****.**>
                    //10.6.21.6       [15C0] 00:02:10 >>> 250 2.1.0 <*****@*****.**>... Sender ok
                    //10.6.21.6       [15C0] 00:02:10 <<< RCPT TO:<*****@*****.**>
                    //10.6.21.6       [15C0] 00:02:10 >>> 250 2.1.5 <*****@*****.**>... Recipient ok
                    //10.6.21.6       [15C0] 00:02:10 <<< DATA
                    //10.6.21.6       [15C0] 00:02:10 >>> 354 Enter mail, end with "." on a line by itself
                    //10.6.21.6       [15C0] 00:02:10 <<< 2809 bytes (overall data transfer speed=325115741 B/s)
                    //10.6.21.6       [15C0] 00:02:10 Start of mail processing
                    //10.6.21.6       [15C0] 00:02:12 *** <*****@*****.**> <*****@*****.**> 1 2804 00:00:01 OK YAR93710
                    //10.6.21.6       [15C0] 00:02:12 >>> 250 2.6.0 2804 bytes received in 00:00:01; Message id YAR93710 accepted for delivery
                    //10.6.21.6       [15C0] 00:02:17 <<< QUIT

                    if (parts.Length > 3)
                    {
                        data.computername = parts[0];
                        string tarih = lastFile.Split(new char[] { '\\', '/' })[lastFile.Split(new char[] { '\\', '/' }).Length - 1].Substring(1, 8);
                        string yil = tarih.Substring(0, 4);
                        string ay = tarih.Substring(4, 2);
                        string gun = tarih.Substring(6, 2);

                        string saat = parts[2];
                        data.datetime = Convert.ToDateTime(yil + "/" + ay + "/" + gun + " " + saat).ToString("yyyy-MM-dd HH:mm:ss");

                        if (line.Contains("Connected"))
                        {
                            bool result = false;
                            if (!string.IsNullOrEmpty(data.datetime))
                            {
                                result = Send_Rec_Data(data);
                            }

                            if (result)
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseSpecific() | Data is send successfully. ");
                            else
                                Log.Log(LogType.FILE, LogLevel.ERROR, " ParseSpecific() | Data could not send. ");

                            data = new Data();
                        }

                        if (line.Contains("bytes (overall"))
                        {
                            data.str6 = "";
                            for (int i = 4; i < parts.Length; i++)
                            {
                                data.str6 += parts[i] + " ";
                            }
                            data.str6 = data.str6.Trim();
                        }

                        if (line.Contains("***"))
                        {
                            //10.6.21.6       [1644] 09:33:31 *** <*****@*****.**> <*****@*****.**> 1 135081 00:00:00 OK ZLX67131

                            data.str3 = parts[4].TrimStart('<').TrimEnd('>');
                            data.str4 = parts[5].TrimStart('<').TrimEnd('>');
                            data.str8 = parts[parts.Length - 1];
                        }

                        // Message id
                        if (line.Contains("Message id"))
                        {
                            for (int i = 5; i < parts.Length; i++)
                            {
                                if (parts[i] == "Message")
                                {
                                    data.eventtype = "";
                                    for (int j = i + 3; j < parts.Length; j++)
                                    {
                                        data.eventtype += parts[j] + " ";
                                    }
                                    data.eventtype = data.eventtype.Trim();

                                    break;
                                }
                            }
                        }

                        if (line.Contains("Sender ok"))
                        {
                            data.str1 = "Sender ok";
                        }
                        if (line.Contains("Recipient ok"))
                        {
                            data.str2 = "Recipient ok";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, " ParseSpecific() | " + ex.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, " ParseSpecific() | " + ex.StackTrace);
                Log.Log(LogType.FILE, LogLevel.ERROR, " ParseSpecific() | Line : " + line);
                return true;
            }

            return true;
        }