Exemplo n.º 1
0
 /// <summary>
 /// Complex constructor for filter thread
 /// </summary>
 /// <param name="logName">EventLog name</param>
 /// <param name="syslog">Syslog server, protocol and port definition</param>
 /// <param name="rulesList">Rules for find eventLog</param>
 /// <param name="debug">Permit to write debug lines</param>
 /// <param name="lastExecTime">Min time search</param>
 /// <param name="maxExecTime">Mas time search</param>
 /// <param name="doneEvent">ManualResetEvent object to know if process if complit</param>
 public ThreadFilter(String logName, ref SyslogServer syslogServer, ArrayList iFilters, ArrayList eFilters, ref Debug debug,
     DateTime lastExecTime, DateTime maxExecTime, ManualResetEvent doneEvent)
 {
     _LogName = logName;
     _SyslogServer = syslogServer;
     _Debug = debug;
     _LastExecTime = lastExecTime;
     _MaxExecTime = maxExecTime;
     _iFilters = iFilters;
     _eFilters = eFilters;
     _DoneEvent = doneEvent;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Load Syslog server parameters
        /// </summary>
        /// <param name="node">specific XML including Syslog server parameters</param>
        static void LoadSyslogConfiguration(XmlNode node)
        {
            // TODO : Load Syslog server parameters
            foreach (XmlNode childnode in node.ChildNodes)
            {
                if (childnode.Name.CompareTo("server") == 0)
                {
                    String address = null;
                    String protocol = null;
                    int port = 514;
                    int memory_buffer = 200;

                    foreach (XmlNode paramNode in childnode.ChildNodes)
                    {
                        if (paramNode.Name.CompareTo("address") == 0)
                        {
                            String validIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]{2,5}$";
                            String validHostnameRegex = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9]):[0-9]{2,5}$";
                            String validIpAddressRegexWithoutPort = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
                            String validHostnameRegexWithoutPort = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])$";

                            Regex re = new Regex(validIpAddressRegex);
                            Regex re2 = new Regex(validHostnameRegex);
                            Regex re3 = new Regex(validIpAddressRegexWithoutPort);
                            Regex re4 = new Regex(validHostnameRegexWithoutPort);

                            if (re.IsMatch(paramNode.InnerText, 0) || re2.IsMatch(paramNode.InnerText, 0))
                            {
                                String[] temp = paramNode.InnerText.ToString().Split(':');
                                address = temp[0];

                                try
                                {
                                    port = Convert.ToInt32(temp[1]);
                                    deb.Write("Load syslog configuration", "Set port " + port, DateTime.Now, 2);
                                }
                                catch (SystemException se)
                                {
                                    deb.Write("Load Syslog Server Configuration", "Set port = 514 because: " + se.Message, DateTime.Now, 1);
                                    port = 514;
                                }
                            }
                            else if (re3.IsMatch(paramNode.InnerText, 0) || re4.IsMatch(paramNode.InnerText, 0))
                            {
                                address = paramNode.InnerText;
                                deb.Write("Load syslog configuration", "Set address " + address, DateTime.Now, 2);
                            }
                        }
                        else if (paramNode.Name.CompareTo("port") == 0)
                        {
                            try
                            {
                                port = Convert.ToInt32(paramNode.InnerText);
                                deb.Write("Load syslog configuration", "Set port " + port, DateTime.Now, 2);
                            }
                            catch (SystemException se)
                            {
                                deb.Write("Load Syslog Server Configuration", "Set port = 514 because: " + se.Message, DateTime.Now, 2);
                                port = 514;
                            }
                        }
                        else if (paramNode.Name.CompareTo("protocole") == 0)
                        {
                            protocol = paramNode.InnerText;
                            deb.Write("Load syslog configuration", "Set protocole " + protocol, DateTime.Now, 2);
                        }
                        else if (paramNode.Name.CompareTo("memory_buffer") == 0)
                        {
                            try
                            {
                                memory_buffer = Convert.ToInt32(paramNode.InnerText);
                                deb.Write("Load syslog configuration", "Set memory buffer " + memory_buffer, DateTime.Now, 2);
                            }
                            catch (SystemException se)
                            {
                                deb.Write("Load Syslog Server Configuration", "Set memory_buffer = 200 because: " + se.Message, DateTime.Now, 1);
                                memory_buffer = 200;
                            }
                        }
                    }

                    try
                    {
                        if (syslogServer == null)
                        {
                            syslogServer = new SyslogServer(address, protocol, port, memory_buffer, ref deb);
                        }
                        else
                        {
                            syslogServer.SetSyslogServer(address, port);
                        }
                    }
                    catch (Exception e)
                    {
                        deb.Write("Load Syslog Server Configuration", "Configuration of syslog server is not correct: " + e.Message, DateTime.Now, 1);
                        deb.Write("Load Syslog Server Configuration", "Program abort", DateTime.Now, 1);
                        System.Environment.Exit(-1);
                    }
                }
            }
        }