Exemple #1
0
        public void StartTest()
        {
            WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);

            if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
            {
                Assert.Fail("You must be running this test as an Administrator");
            }

            LogbusServerConfiguration config = new LogbusServerConfiguration();

            using (ILogBus service = new LogbusService(config))
            {
                service.Start();
                int httpPort = 8065; // TODO: Eseguire l'inizializzazione a un valore appropriato
                using (WebServiceActivator webService = new WebServiceActivator(service, httpPort))
                {
                    webService.Start();
                    Thread.Sleep(10000);
                    webService.Stop();
                }
                service.Stop();
            }
        }
        public void FFDATest()
        {
            FilterBase ffda_filter =
                new FacilityEqualsFilter()
            {
                facility = SyslogFacility.Local0
            } &
            new PropertyFilter()
            {
                comparison = ComparisonOperator.eq, propertyName = Property.MessageID, value = "FFDA"
            };

            StringBuilder markup = new StringBuilder();

            new XmlSerializer(typeof(FilterBase)).Serialize(XmlTextWriter.Create(markup, new XmlWriterSettings()
            {
                Indent = true
            }), ffda_filter, ffda_filter.xmlns);

            TestContext.WriteLine("{0}", markup.ToString());

            const int SEND_PORT = 5427;

            //Init Logbus
            LogbusServerConfiguration core_config = new LogbusServerConfiguration();

            core_config.corefilter = ffda_filter;
            InboundChannelDefinition in_ch = new InboundChannelDefinition();

            in_ch.type  = "SyslogUdpReceiver";
            in_ch.param = new KeyValuePair[]
            {
                new KeyValuePair()
                {
                    name  = "port",
                    value = SEND_PORT.ToString()
                }
            };
            core_config.inchannels = new InboundChannelDefinition[] { in_ch };

            using (ILogBus logbus = new LogbusService(core_config))
            {
                logbus.MessageReceived += new EventHandler <SyslogMessageEventArgs>(logbus_MessageReceived);
                logbus.Start();

                //Init FFDA
                LogbusLoggerConfiguration source_config = new LogbusLoggerConfiguration();
                LoggerDefinition          udp_def       = new LoggerDefinition()
                {
                    type  = "SyslogUdpCollector",
                    param = new KeyValuePair[] { new KeyValuePair()
                                                 {
                                                     name = "port", value = SEND_PORT.ToString()
                                                 }, new KeyValuePair()
                                                 {
                                                     name = "ip", value = "127.0.0.1"
                                                 } }
                };
                source_config.logger       = new LoggerDefinition[] { udp_def };
                LoggerHelper.Configuration = source_config;

                //Send what we want: 2 FFDA messages
                IFieldFailureDataLogger logger = FieldFailureDataHelper.CreateFailureDataLogger("ffda");
                logger.LogSST();
                logger.LogSEN();

                //Send junk
                ILog junk_log = LoggerHelper.GetLogger();
                junk_log.Debug("Hello");
                junk_log.Error("Junk error");

                Thread.Sleep(1000);
                logbus.Stop();
            }

            Assert.AreEqual(2, messages);
        }