Exemplo n.º 1
0
 public LogMailer(ILogParser logParser, ILogReader logReader, IMailSender mailSender, ILogger logger)
 {
     _logParser  = logParser;
     _logReader  = logReader;
     _mailSender = mailSender;
     _logger     = logger;
 }
Exemplo n.º 2
0
        public void Init()
        {
            Metric.Config.WithHttpEndpoint("http://localhost:2581/").WithSystemCounters();

            //XXX use config to get this info
            var registryFactory = LogRegistryFactory.Create();

            var parserFactory = LogParserFactory.GetParserForFileExtension("xml");

            IPrinterFactory printerFactory;

            if (config.ExtraConfigs != null && config.ExtraConfigs.ContainsKey("printToFile") && !string.IsNullOrWhiteSpace(config.ExtraConfigs["printToFile"]))
            {
                // Note: this just sets a default. Configs can change the file
                printerFactory = PrinterFactory.CrateFileFactory(config.ExtraConfigs["printToFile"]);
            }
            else
            {
                printerFactory = PrinterFactory.CrateConsoleFactory();
            }

            registry = registryFactory.Create();

            logFileParser = parserFactory.Create(registry, config);
            printer       = printerFactory.Create(registry, config);
        }
Exemplo n.º 3
0
 public App(string logLocation, ILogParser parser, Notifier notifier, IEnumerable <string> recipients)
 {
     this.parser      = parser;
     this.notifier    = notifier;
     this.recipients  = recipients;
     this.logLocation = logLocation;
 }
Exemplo n.º 4
0
 public HomeController(ILogParser logParser, IMapper mapper, IRepository repository, IUnitOfWork uow)
 {
     this.uow        = uow;
     this.repository = repository;
     this.mapper     = mapper;
     this.logParser  = logParser;
 }
        public void ReadLogFile_WhenJsonDataExists_ReturnsTrue()
        {
            _logParser = new LogParser();

            var result = _logParser.GetJsonDataFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _configuration[Common.Constants.LogFile]));

            Assert.True(result.Count > 0);
        }
        public void GetSaveableData_WhenDataExists_ReturnsTrue()
        {
            _logParser = new LogParser();
            var jsonData = _logParser.GetJsonDataFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _configuration[Common.Constants.LogFile]));
            var result   = _logParser.GetSaveableData(jsonData);

            Assert.True(result.Count > 0);
            Assert.Greater(jsonData.Count, result.Count);
        }
Exemplo n.º 7
0
 public LogFile(string path, IParserSelector parserSelector, IModuleClassifier moduleClassifier)
 {
     _path        = path;
     _entries     = new List <LogEntry>();
     FileName     = System.IO.Path.GetFileNameWithoutExtension(_path);
     Module       = moduleClassifier.GetModuleForFile(System.IO.Path.GetFileName(_path));
     IsErrorsFile = FileName.EndsWith(".Errors");
     _logParser   = parserSelector.GetParser(this);
 }
Exemplo n.º 8
0
 public LayoutService(
     ILogParser logParser,
     IGameDataRepository gameDataRepository,
     IImageDataRepository imageDataRepository)
 {
     _logParser           = logParser;
     _gameDataRepository  = gameDataRepository;
     _imageDataRepository = imageDataRepository;
     _history             = new History();
 }
Exemplo n.º 9
0
        public MainWindow()
        {
            InitializeComponent();
            logParser        = new LogParser();
            reportAggregator = new ExcelReportAggregator();

            endDate.SelectedDate = DateTime.Now;
            endTime.Text         = DateTime.Now.ToString("HH:mm:ss");
            DataContext          = new AnalyzerVersion();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Parse a log file.
        /// </summary>
        /// <param name="parser">The parser to use.</param>
        /// <param name="logFile">Path to a log file.</param>
        /// <returns>Task representing the parse operation.</returns>
        public static Task ParseAsync(this ILogParser parser, string logFile)
        {
            parseCounter.Increment();

            var fr = new FileStream(logFile, FileMode.Open);

            parseFileSizeHistogram.Update(fr.Length, logFile);

            return(parser.ParseAsync(fr).ContinueWith(_ => fr.Dispose(), TaskContinuationOptions.ExecuteSynchronously));
        }
Exemplo n.º 11
0
 public MainWindowVm(ILogExtractionService logService, IModalHandler modalHandler, ILogParser parser, ILogStructureVm logStructure, IModuleClassifier moduleClassifier)
 {
     _logService      = logService;
     _modalHandler    = modalHandler;
     _parser          = parser;
     ModuleClassifier = moduleClassifier;
     LogPath          = string.Empty;
     LogStructure     = logStructure;
     ResetPages();
 }
 public LogLoader(
     ILogFinder logFinder,
     ILogParser logParser,
     ILogTrimmer logTrimmer,
     ILogger <LogLoader> logger)
 {
     _logFinder  = logFinder;
     _logParser  = logParser;
     _logTrimmer = logTrimmer;
     _logger     = logger;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Apply additional context to the parser, using a specific config to modify parsing.
        /// </summary>
        /// <param name="parser">The parser to apply context to.</param>
        /// <param name="configName">The specific config to apply.</param>
        /// <param name="configValue">The value associated with the specified config.</param>
        /// <param name="context">The context that the modified parser will execute in. If the scope of this parser is exited, as in the Action delegate finishes execution, then the modified parser becomes invalid and won't run.</param>
        public static void ApplyContextConfig(this ILogParser parser, ContextConfigs configName, object configValue, Action <ILogParser> context)
        {
            applyContextCounter.Increment(configName.ToString());

            var config = new Dictionary <ContextConfigs, object>
            {
                { configName, configValue }
            };

            parser.ApplyContextConfig(config, context);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Parse a log file.
        /// </summary>
        /// <param name="parser">The parser to use.</param>
        /// <param name="logFile">Path to a log file.</param>
        public static void Parse(this ILogParser parser, string logFile)
        {
            parseCounter.Increment();

            using (var fr = new FileStream(logFile, FileMode.Open))
            {
                parseFileSizeHistogram.Update(fr.Length, logFile);

                parser.Parse(fr);
            }
        }
Exemplo n.º 15
0
        public void Input(string input, string result)
        {
            // Arrange
            var inputData  = File.ReadAllText(Directory.GetCurrentDirectory() + "/TestInputs/" + input);
            var resultData = File.ReadAllText(Directory.GetCurrentDirectory() + "/TestInputs/" + result);

            // Act
            var parsed = ILogParser.EvaluateLogFile(inputData);

            //Assert
            parsed.Should().BeEquivalentTo(resultData);
        }
Exemplo n.º 16
0
        public AllEntriesPageVm(INavigator navigator, ILogParser parser, IReadOnlyList <IColumnDescriptionVm> columns, IModuleClassifier moduleClassifier)
            : base(navigator, columns)
        {
            SortDirection    = UserSettings.Default.DateSortDirection;
            IsLoading        = true;
            _navigator       = navigator;
            _parser          = parser;
            ModuleClassifier = moduleClassifier;

            HighlightSearches = BuildHighlights();

            Customization = new ViewCustomization();
        }
Exemplo n.º 17
0
        public async Task <IActionResult> UploadLog(IFormFile logFile, string siteDomain)
        {
            int logId;

            logParser = new LogParser(siteDomain);
            if (logFile != null && siteDomain != null)
            {
                var logs = logParser.ConvertToList(logFile);
                logId = await logParser.SaveLogsToDataBaseAsync(logs);

                return(RedirectToAction("LogFile", new { id = logId }));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 18
0
        public void EvaluateLogFile_ShouldReturnDefault_WhenNoRecordForSensor(SensorType sensor)
        {
            // Arrange
            var sb = new StringBuilder();

            sb.AppendFormat(Common.ReferenceFormat, 3);
            sb.AppendFormat(Common.SensorFormat, sensor, "s1");
            var expected = Common.FormatResult("s1", Result.NoData);
            // Act
            var res = ILogParser.EvaluateLogFile(sb.ToString());

            // Assert
            res.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 19
0
        public LogService(
            ILogParser <ParsedLogEntry> parser,
            WebHelper webHelper,
            IValidator <ParsedLogEntry> logValidator,
            IRepositoryFactory repositoryFactory,
            IOptions <PageSettings> pageOptions)
        {
            this.parser            = parser;
            this.webHelper         = webHelper;
            this.logValidator      = logValidator;
            this.repositoryFactory = repositoryFactory;

            this.pageSettings = pageOptions.Value;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Parse a log file.
        /// </summary>
        /// <param name="parser">The parser to use.</param>
        /// <param name="logFile">Path to a log file.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        /// <returns>Task representing the parse operation.</returns>
        public static Task ParseAsync(this ILogParser parser, string logFile, CancellationToken cancellationToken)
        {
            parseCounter.Increment();

            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled(cancellationToken));
            }

            var fr = new FileStream(logFile, FileMode.Open);

            parseFileSizeHistogram.Update(fr.Length, logFile);

            return(parser.ParseAsync(fr, cancellationToken).ContinueWith(_ => fr.Dispose(), TaskContinuationOptions.ExecuteSynchronously));
        }
        private static ISource CreateDirectorySource <TData, TContext>(string id, string path,
                                                                       ILogParser <TData, TContext> recordParser, DirectorySourceOptions options, IPlugInContext context)
            where TContext : LogContext, new()
        {
            var directorySourceType        = typeof(AsyncDirectorySource <,>);
            var genericDirectorySourceType = directorySourceType.MakeGenericType(typeof(TData), typeof(TContext));
            var source = (ISource)Activator.CreateInstance(genericDirectorySourceType,
                                                           id,
                                                           path,
                                                           recordParser,
                                                           context.BookmarkManager,
                                                           options,
                                                           context);

            return(source);
        }
Exemplo n.º 22
0
        public void EvaluateLogFile_ShouldReturnEmpty_WhenRecordIsInvalid(string record)
        {
            // Arrange
            var sb = new StringBuilder();

            sb.AppendFormat(Common.ReferenceFormat, 3);
            sb.AppendFormat(Common.SensorFormat, SensorType.Monoxide, "m1");
            sb.AppendFormat(record);
            string expected = Common.FormatResult("m1", Result.NoData);

            // Act
            var res = ILogParser.EvaluateLogFile(sb.ToString());

            // Assert
            res.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 23
0
        public void EvaluateLogFile_ShouldReturnEmpty_WhenSensorIsInvalid(string sensorName)
        {
            // Arrange
            var sb = new StringBuilder();

            sb.AppendFormat(Common.ReferenceFormat, 3);
            sb.AppendFormat(sensorName);
            sb.AppendLine();
            sb.AppendFormat(Common.RecordFormat, "2");
            const string expected = "{}"; //"invalid sensor name format";

            // Act
            var res = ILogParser.EvaluateLogFile(sb.ToString());

            // Assert
            res.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 24
0
        public void EvaluateLogFile_ShouldReadMonoxideData_WhenTheLogfileIsValid(double reference, double value,
                                                                                 string name, Result result)
        {
            // Arrange
            var sb = new StringBuilder();

            sb.AppendFormat(Common.ReferenceFormat, reference);
            sb.AppendFormat(Common.SensorFormat, SensorType.Monoxide, name);
            sb.AppendFormat(Common.RecordFormat, value);
            var expected = Common.FormatResult(name, result);

            // Act
            var res = ILogParser.EvaluateLogFile(sb.ToString());

            // Assert
            res.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 25
0
        public void EvaluateLogFile_ShouldReturnEmpty_WhenTheReferenceIsInvalid(string reference)
        {
            // Arrange
            var sb = new StringBuilder();

            sb.AppendFormat(reference);
            sb.AppendLine();
            sb.AppendFormat(Common.SensorFormat, SensorType.Monoxide, "m1");
            sb.AppendFormat(Common.RecordFormat, "2");
            const string expected = "{}"; //"invalid reference format";

            // Act
            var res = ILogParser.EvaluateLogFile(sb.ToString());

            // Assert
            res.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 26
0
        private void OnTimerTick(object sender, ElapsedEventArgs args)
        {
            var lastLogFile = logFileFinder.LastLogFile;

            if (lastLogFile != prevLastLogFile)
            {
                if (currentParser != null)
                {
                    currentParser.Dispose();
                }

                prevLastLogFile = lastLogFile;
                var stream = logStreamProvider.GetLogStream(lastLogFile);
                stream.Seek(0, SeekOrigin.End);
                currentParser = logParserProvider.Invoke(stream);
            }
            currentParser?.Parse();
        }
Exemplo n.º 27
0
        /// <summary>
        /// Parse LOG4JXml from string and return default LogMessage on exception
        /// </summary>

        public static LogMessage TryParseLogEvent(this ILogParser logParser, string logEvent, string defaultLogger)
        {
            try
            {
                return(logParser.ParseLogEvent(logEvent));
            }
            catch (Exception e)
            {
                return(new LogMessage
                {
                    // Create a simple log message with some default values
                    LoggerName = defaultLogger,
                    ThreadName = "NA",
                    Message = logEvent,
                    TimeStamp = DateTime.Now,
                    LogLevel = LogLevel.Info,
                    ExceptionString = e.Message
                });
            }
        }
Exemplo n.º 28
0
        private static void Test(ILogParser parser)
        {
            var expectedResult = new Dictionary <string, int>
            {
                { "46.17.203.253", 25060434 },
                { "213.24.62.119", 23502468 },
                { "91.208.121.254", 20443768 },
                { "46.17.201.50", 15585076 },
                { "46.17.201.58", 12967906 },
                { "195.234.190.100", 12378304 },
                { "195.43.90.253", 10469620 },
                { "195.130.216.202", 9731071 },
                { "194.186.187.146", 7748171 },
                { "194.190.140.73", 7322802 }
            };
            const string logPath = "Files/ips.txt";
            var          result  = parser.GetTop10Users(logPath);

            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemplo n.º 29
0
        private static void Test(ILogParser parser)
        {
            var expectedResult = new Dictionary <string, int>
            {
                { "213.24.62.119", 40475776 },
                { "91.208.121.254", 38198276 },
                { "46.17.201.50", 27744726 },
                { "46.17.203.253", 27313932 },
                { "46.17.201.58", 24282986 },
                { "195.234.190.100", 22713210 },
                { "195.43.90.253", 18936533 },
                { "195.130.216.202", 18237678 },
                { "92.50.171.106", 15146850 },
                { "194.190.140.73", 14623515 }
            };
            const string logPath = "Files/ips.txt";
            var          result  = parser.GetTop10Users(logPath);

            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            // Setup Dependencies
            IUnityContainer container = new UnityContainer();

            container.RegisterType <ILogParser, FileLogParser>();
            container.RegisterType <IBodyBuilder, BodyBuilder>();
            container.RegisterType <Notifier, EmailNotifier>();
            ILogParser parser   = container.Resolve <ILogParser>();
            Notifier   notifier = container.Resolve <Notifier>(
                new ParameterOverride("from", "*****@*****.**"),
                new ParameterOverride("title", "Errors in your console"));

            string location = "errors.txt";
            var    logs     = parser.Parse(location);

            List <string> recipients = GetRecipients();

            notifier.Send(logs, recipients);

            Console.WriteLine("Sent!");
            Console.ReadLine();
        }
 public AzureLogReader(ILogParser logParser, IAuditParser auditParser, IErrorParser errorParser, IHealthMonitorParser healthMonitorParser) : base(logParser, auditParser, errorParser, healthMonitorParser)
 {
     this.logParser = logParser;
 }