Пример #1
0
        public void Send_Should_CommunicateCorrectlyOverTcp()
        {
            // Arrange
            var expected = @"\<\d+\>\S{3}\s\d+\s\d+\:\d+\:\d+\s\S+\s\S+\[\d+\]\:\s.*";
            var port     = random.Next(49152, 65535);
            var client   = new SyslogClient()
            {
                Port = port
            }.UseTcp();

            var message = new Message("Unit Test Are Awesome!");

            var server = new MockTcpServer(port);

            // Act
            client.Send(message);

            while (!server.Done)
            {
                Thread.Sleep(100); // Multi-threaded programming will bite you!
            }

            // Assert
            Assert.Matches(expected, server.MessageRecieved);
        }
Пример #2
0
        public void Send_Should_CommunicateCorrectly_When_NotIncludingProcessInfo()
        {
            // Arrange
            var expected = @"\<\d+\>\S{3}\s\d+\s\d+\:\d+\:\d+\s\S+\s[^\[]+$";
            var port     = random.Next(49152, 65535);
            var client   = new SyslogClient()
            {
                Port = port,
                IncludeProcessInfo = false
            };

            var message = new Message("Unit Test Are Awesome!");

            var server = new MockUdpServer(port);

            // Act
            client.Send(message);
            while (!server.Done)
            {
                Thread.Sleep(100); // Multi-threaded programming will bite you!
            }

            // Assert
            Assert.Matches(expected, server.MessageRecieved);
        }
Пример #3
0
        public void _Debug(string message)
        {
            if (EnableDebug)
            {
                messageMutex.WaitOne();
                ConsoleMessage cm = new ConsoleMessage(ConsoleMessagePriority.DEBUG, message);
                if (LogConsole)
                {
                    ConsoleColor oldColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.WriteLine(cm);
                    Console.ForegroundColor = oldColor;
                }

                if (syslog != null)
                {
                    try {
                        SyslogClient.Send(new Message(ConfigurationManager.Get(SYSLOGFACILITYDBKEY, "LOG_USER"), Level.Debug, cm.Message));
                    } catch (SocketException) {
                        // Syslog not configured, ignore.
                    }
                }
                messageMutex.ReleaseMutex();
                MessageAvailable?.Invoke(cm);
            }
        }
Пример #4
0
        public void Server_Should_ThrowArgumentException_When_AttemptingToSetToEmptyString()
        {
            // Arrange
            var client = new SyslogClient();

            // Act & Assert
            Assert.Throws <ArgumentException>(() => client.Server = string.Empty);
        }
Пример #5
0
        public void Port_Should_HaveProvidedValue()
        {
            // Arrange & Act
            var client = new SyslogClient("syslog.contoso.com", 8514);

            // Assert
            Assert.Equal(8514, client.Port);
        }
Пример #6
0
        public void Port_Should_HaveDefaultValue()
        {
            // Arrange & Act
            var client = new SyslogClient();

            // Assert
            Assert.Equal(514, client.Port);
        }
Пример #7
0
        public void Server_Should_HaveProvidedValue()
        {
            // Arrange
            var client = new SyslogClient("syslogserver.contoso.com");

            // Act & Assert
            Assert.Equal("syslogserver.contoso.com", client.Server);
        }
Пример #8
0
        public void Port_Should_ThrowArgumentOutOfRangeException_When_AttemptingToSetToNegative()
        {
            // Arrange
            var client = new SyslogClient();

            // Act & Assert
            Assert.Throws <ArgumentOutOfRangeException>(() => client.Port = -1);
        }
Пример #9
0
        public void Server_Should_HaveDefaultValue()
        {
            // Arrange
            var client = new SyslogClient();

            // Act & Assert
            Assert.Equal("127.0.0.1", client.Server);
        }
Пример #10
0
        public void IncludeProcessInfo_Should_HaveDefaultValue()
        {
            // Arrange & Act
            var client = new SyslogClient();

            // Assert
            Assert.True(client.IncludeProcessInfo);
        }
Пример #11
0
        public void Server_Should_ThrowArgumentNullException_When_AttemptingToSetToNull()
        {
            // Arrange
            var client = new SyslogClient();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => client.Server = null);
        }
Пример #12
0
        void SetConfigVars()
        {
            UIConsole.Log("Setting Configuration");
            FileHandler.SkipEMWIN       = !ProgConfig.EnableEMWIN;
            FileHandler.SkipDCS         = !ProgConfig.EnableDCS;
            FileHandler.SkipWeatherData = !ProgConfig.EnableWeatherData;

            if (ProgConfig.TemporaryFileFolder != null)
            {
                if (!LLTools.TestFolderAccess(ProgConfig.TemporaryFileFolder))
                {
                    UIConsole.Error($"Cannot write file to Temporary Folder {ProgConfig.TemporaryFileFolder}");
                    throw new ApplicationException($"Cannot write file to Temporary Folder {ProgConfig.TemporaryFileFolder}");
                }
                FileHandler.TemporaryFileFolder = ProgConfig.TemporaryFileFolder;
            }

            if (ProgConfig.FinalFileFolder != null)
            {
                if (!LLTools.TestFolderAccess(ProgConfig.FinalFileFolder))
                {
                    UIConsole.Error($"Cannot write file to Final Folder {ProgConfig.FinalFileFolder}");
                    throw new ApplicationException($"Cannot write file to Final Folder {ProgConfig.FinalFileFolder}");
                }
                FileHandler.FinalFileFolder = ProgConfig.FinalFileFolder;
            }

            ImageManager.EraseFiles             = ProgConfig.EraseFilesAfterGeneratingFalseColor;
            ImageManager.GenerateInfrared       = ProgConfig.GenerateInfraredImages;
            ImageManager.GenerateVisible        = ProgConfig.GenerateVisibleImages;
            ImageManager.GenerateWaterVapour    = ProgConfig.GenerateWaterVapourImages;
            ImageManager.MaxRetryCount          = ProgConfig.MaxGenerateRetry;
            ImageManager.UseNOAAFileFormat      = ProgConfig.UseNOAAFormat;
            ImageManager.GenerateLabels         = ProgConfig.GenerateLabels;
            ImageManager.GenerateLatLonOverlays = ProgConfig.GenerateLatLonOverlays;
            ImageManager.GenerateMapOverlays    = ProgConfig.GenerateMapOverlays;
            ImageManager.GenerateLatLonLabel    = ProgConfig.GenerateLatLonLabel;

            Connector.ChannelDataServerName   = ProgConfig.ChannelDataServerName;
            Connector.StatisticsServerName    = ProgConfig.StatisticsServerName;
            Connector.ConstellationServerName = ProgConfig.ConstellationServerName;

            Connector.ChannelDataServerPort   = ProgConfig.ChannelDataServerPort;
            Connector.StatisticsServerPort    = ProgConfig.StatisticsServerPort;
            Connector.ConstellationServerPort = ProgConfig.ConstellationServerPort;

            if (LLTools.IsLinux)
            {
                SyslogClient.SysLogServerIp = ProgConfig.SysLogServer;
                try {
                    SyslogClient.Send(ProgConfig.SysLogFacility, Level.Information, "Your syslog connection is working! OpenSatelliteProject is enabled to send logs.");
                } catch (SocketException) {
                    UIConsole.Warn("Your syslog is not enabled to receive UDP request. Please refer to https://opensatelliteproject.github.io/OpenSatelliteProject/");
                }
            }
        }
Пример #13
0
        public void Port_Should_AcceptProperPortNumbers()
        {
            // Arrange
            var client = new SyslogClient();

            // Act
            client.Port = 8514;

            // Assert
            Assert.Equal(8514, client.Port);
        }
Пример #14
0
        public void IncludeProcessInfo_Should_AcceptSettingToFalse()
        {
            // Arrange
            var client = new SyslogClient();

            // Act
            client.IncludeProcessInfo = false;

            // Assert
            Assert.False(client.IncludeProcessInfo);
        }
Пример #15
0
        public void Server_Should_AcceptProperServerName()
        {
            // Arrange
            var client = new SyslogClient();

            // Act
            client.Server = "syslogserver.contoso.com";

            // Assert
            Assert.Equal("syslogserver.contoso.com", client.Server);
        }
Пример #16
0
        static void SyslogDataSender()
        {
            //var localIp = GetLocalIp(_listenerAdapterName);
            var localIp = IPAddress.Parse("127.0.0.1");
            var _sender = new SyslogClient(localIp.ToString());

            foreach (var message in SyslogMessageGenerator.CreateTestSyslogStream(500))
            {
                _sender.Send(message);
            }
        }
Пример #17
0
        public void TruncateTagIfNeeded_Should_TruncateWhenProcessNameTooLong()
        {
            // Arrange
            const string expected = "12345678901234567890123456[5434]: ";
            const string tag      = "12345678901234567890123456789012345";
            const string id       = "[5434]";

            // Act
            var actual = SyslogClient.TruncateTagIfNeeded(tag, id);

            // Assert
            Assert.Equal(expected, actual);
        }
Пример #18
0
 public SyslogClientLogRoute(SyslogClient client, string appName, string kind, LogPriority minimalPriority) : base(kind, minimalPriority)
 {
     this.AppName = appName._NullCheck();
     this.Client  = client;
 }
Пример #19
0
 /// <summary>
 /// Creates a new instance of destination that sends messages to .nix SYSLOG
 /// </summary>
 public SyslogSink() : base(null)
 {
     m_Client = new SyslogClient();
 }
Пример #20
0
 public void Send(SyslogClient.Message message)
 {
     if (!udpClient.isActive) {
         IPAddress ip = IPAddress.Parse(_sysLogServerIp);
         IPEndPoint ipEndPoint = new IPEndPoint(ip, _port);
         udpClient.Connect(ipEndPoint); 
     }
     if (udpClient.isActive)
     {
         int priority = message.Facility * 8 + message.Level;
         string msg = System.String.Format("<{0}>{1}",
                                           priority,
                                           message.Text);
         byte[] bytes = System.Text.Encoding.ASCII.GetBytes(msg);
         udpClient.Send(bytes, bytes.Length);
     }
     else throw new Exception("Syslog Client Socket is not connected. Please check the Syslog Server IP property.");
 }
Пример #21
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Configuration config = new Configuration();

                var syslogHost = config.SyslogHost;
                var syslogPort = config.SyslogPort;
                var logPath    = config.LogPath;

                if (syslogHost == null || syslogHost == "")
                {
                    throw new ArgumentException("Syslog server is not configured");
                }
                if (syslogPort == 0)
                {
                    throw new ArgumentException("Syslog server port is not configured");
                }
                if (logPath == null || logPath == "")
                {
                    throw new ArgumentException("Monitored log path is not configured");
                }

                DirectoryInfo directoryInfo = new DirectoryInfo(logPath);

                if (!directoryInfo.Exists)
                {
                    throw new ArgumentException("Monitored log path does not exist");
                }

                _client         = new SyslogClient(syslogHost, 5140, "UDP", false, null);
                _client.AppName = "IISFailedRequest";
                _client.PrependMessageLength = false;
                _client.DiagnosticsEventLog  = eventLog;

                // Create a new FileSystemWatcher and set its properties.
                FileSystemWatcher watcher = new FileSystemWatcher();
                watcher.Path = directoryInfo.FullName;

                //watcher.NotifyFilter = NotifyFilters.LastWrite;

                watcher.Filter = IIS_TRACING_PATTERN;

                // Add event handlers.
                watcher.Created += new FileSystemEventHandler(OnChanged);

                // Begin watching.
                watcher.EnableRaisingEvents = true;

                _watcher = watcher;

                _client.Activate();

                eventLog.WriteEntry("Service started. Monitoring " + logPath);
            }
            catch (ArgumentException ae)
            {
                eventLog.WriteEntry("An error occured during the service startup: " + ae.Message, EventLogEntryType.Error);

                if (System.Environment.UserInteractive)
                {
                    throw ae;
                }

                base.ExitCode = 87; // ERROR_INVALID_PARAMETER
                base.Stop();
            } catch (Exception e)
            {
                eventLog.WriteEntry("An error occured during the service startup: " + e.ToString(), EventLogEntryType.Error);

                if (System.Environment.UserInteractive)
                {
                    throw e;
                }

                base.ExitCode = 352; // ERROR_FAIL_RESTART
                base.Stop();
            }
        }
Пример #22
0
        public Main()
        {
            #region Create Config File
            config.RecordIntermediateFile  = config.RecordIntermediateFile;
            config.ChannelDataServerName   = config.ChannelDataServerName;
            config.ChannelDataServerPort   = config.ChannelDataServerPort;
            config.ConstellationServerName = config.ConstellationServerName;
            config.ConstellationServerPort = config.ConstellationServerPort;
            config.StatisticsServerName    = config.StatisticsServerName;
            config.StatisticsServerPort    = config.StatisticsServerPort;
            config.EnableDCS   = config.EnableDCS;
            config.EnableEMWIN = config.EnableEMWIN;
            config.EraseFilesAfterGeneratingFalseColor = config.EraseFilesAfterGeneratingFalseColor;
            config.GenerateFDFalseColor      = config.GenerateFDFalseColor;
            config.GenerateNHFalseColor      = config.GenerateNHFalseColor;
            config.GenerateSHFalseColor      = config.GenerateSHFalseColor;
            config.GenerateUSFalseColor      = config.GenerateUSFalseColor;
            config.GenerateXXFalseColor      = config.GenerateXXFalseColor;
            config.HTTPPort                  = config.HTTPPort;
            config.GenerateInfraredImages    = config.GenerateInfraredImages;
            config.GenerateVisibleImages     = config.GenerateVisibleImages;
            config.GenerateWaterVapourImages = config.GenerateWaterVapourImages;
            config.MaxGenerateRetry          = config.MaxGenerateRetry;
            config.SysLogServer              = config.SysLogServer;
            config.SysLogFacility            = config.SysLogFacility;
            config.UseNOAAFormat             = config.UseNOAAFormat;
            config.EnableWeatherData         = config.EnableWeatherData;
            config.TemporaryFileFolder       = config.TemporaryFileFolder;
            config.FinalFileFolder           = config.FinalFileFolder;
            config.Save();
            #endregion

            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            cfd = null;
            graphics.PreferredBackBufferWidth  = 1280;
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferMultiSampling       = true;

            this.Exiting += (object sender, EventArgs e) => {
                //cn.Stop();
            };

            FileHandler.SkipEMWIN       = !config.EnableEMWIN;
            FileHandler.SkipDCS         = !config.EnableDCS;
            FileHandler.SkipWeatherData = !config.EnableWeatherData;

            if (config.TemporaryFileFolder != null)
            {
                if (!LLTools.TestFolderAccess(config.TemporaryFileFolder))
                {
                    UIConsole.GlobalConsole.Error($"Cannot write file to Temporary Folder {config.TemporaryFileFolder}");
                    throw new ApplicationException($"Cannot write file to Temporary Folder {config.TemporaryFileFolder}");
                }
                FileHandler.TemporaryFileFolder = config.TemporaryFileFolder;
            }

            if (config.FinalFileFolder != null)
            {
                if (!LLTools.TestFolderAccess(config.FinalFileFolder))
                {
                    UIConsole.GlobalConsole.Error($"Cannot write file to Final Folder {config.FinalFileFolder}");
                    throw new ApplicationException($"Cannot write file to Final Folder {config.FinalFileFolder}");
                }
                FileHandler.FinalFileFolder = config.FinalFileFolder;
            }

            ImageManager.EraseFiles          = config.EraseFilesAfterGeneratingFalseColor;
            ImageManager.GenerateInfrared    = config.GenerateInfraredImages;
            ImageManager.GenerateVisible     = config.GenerateVisibleImages;
            ImageManager.GenerateWaterVapour = config.GenerateWaterVapourImages;
            ImageManager.MaxRetryCount       = config.MaxGenerateRetry;
            ImageManager.UseNOAAFileFormat   = config.UseNOAAFormat;

            Connector.ChannelDataServerName   = config.ChannelDataServerName;
            Connector.StatisticsServerName    = config.StatisticsServerName;
            Connector.ConstellationServerName = config.ConstellationServerName;

            Connector.ChannelDataServerPort   = config.ChannelDataServerPort;
            Connector.StatisticsServerPort    = config.StatisticsServerPort;
            Connector.ConstellationServerPort = config.ConstellationServerPort;

            if (LLTools.IsLinux)
            {
                SyslogClient.SysLogServerIp = config.SysLogServer;
                try {
                    SyslogClient.Send(new Message(config.SysLogFacility, Level.Information, "Your syslog connection is working! OpenSatelliteProject is enabled to send logs."));
                } catch (SocketException) {
                    UIConsole.GlobalConsole.Warn("Your syslog is not enabled to receive UDP request. Please refer to https://opensatelliteproject.github.io/OpenSatelliteProject/");
                }
            }

            string fdFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_FULLDISK);
            string xxFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_AREA_OF_INTEREST);
            string nhFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_NORTHERN);
            string shFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_SOUTHERN);
            string usFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_UNITEDSTATES);
            string fmFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES16_ABI, (int)ScannerSubProduct.NONE);

            FDImageManager = new ImageManager(fdFolder);
            XXImageManager = new ImageManager(xxFolder);
            NHImageManager = new ImageManager(nhFolder);
            SHImageManager = new ImageManager(shFolder);
            USImageManager = new ImageManager(usFolder);
            FMImageManager = new ImageManager(fmFolder);
        }
Пример #23
0
 /// <summary>
 /// Creates a new instance of destination that sends messages to .nix SYSLOG
 /// </summary>
 public SyslogSink(string name, string host, int port) : base(name)
 {
     m_Client = new SyslogClient(host, port);
 }
Пример #24
0
 /// <summary>
 /// Creates a new instance of destination that sends messages to .nix SYSLOG
 /// </summary>
 public SyslogDestination(string name, string host, int port) : base(name)
 {
     m_Client = new SyslogClient(host, port);
 }
Пример #25
0
 public SyslogSink(ISinkOwner owner, string name, int order) : base(owner, name, order)
 {
     m_Client = new SyslogClient();
 }
Пример #26
0
 /// <summary>
 /// Creates a new instance of destination that sends messages to .nix SYSLOG
 /// </summary>
 public SyslogDestination() : base(null)
 {
     m_Client = new SyslogClient();
 }