public async Task <ActionResult <ParsingRulesViewModel> > GetForComponent(int componentId)
        {
            try
            {
                var result = await _parsingRulesService.GetComponentsParsingRules(componentId);

                return(Ok(await _presenter.Present(result)));
            }
            catch (ArgumentOutOfRangeException)
            {
                return(NotFound());
            }
            catch (Exception debug)
            {
                return(BadRequest($"Couldn't fetch parsing rules for component with id {componentId}"));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <bool> > LogForComponent(int componentId, [FromBody] string[] lines)
        {
            try
            {
                var parsingRules = await _parsingRulesService.GetComponentsParsingRules(componentId);

                var logs = new List <NormalizedLog>();
                foreach (var line in lines)
                {
                    var workingLine = line.Trim();
                    if (string.IsNullOrWhiteSpace(workingLine))
                    {
                        continue;
                    }

                    try
                    {
                        var raw = new RawLog {
                            Id = 0, ParentComponentId = componentId, Message = workingLine
                        };
                        var rawSaved = await _rawLogService.Create(raw);

                        var normalized = _parseService.ParseAll(rawSaved, parsingRules);
                        logs.Add(await _normalizedLogService.Create(normalized));
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }

                var alerts = await _alertValueService.GenerateAlerts(logs);
            }
            catch (Exception debug)
            {
                Console.WriteLine(debug);
                throw;
            }

            return(Ok(true));
        }
Ejemplo n.º 3
0
        public async Task <Component> Request(ComponentViewModel viewModel)
        {
            ParsingRules rules = null;

            try
            {
                rules = await _parsingRulesService.GetComponentsParsingRules(viewModel.Id);
            }
            catch
            {
            }

            int?systemId = viewModel.SystemId;

            if (systemId.Value == 0)
            {
                systemId = null;
            }

            return(new Component(viewModel.Id, viewModel.Name, rules?.Id, systemId, viewModel.Description));
        }
    public async Task<NormalizedLogViewModel> Present(NormalizedLog model)
    {
      var severityRule = (await _parsingRulesService.GetComponentsParsingRules(model.ComponentId)).SeverityParsingRule
        .ToDomainModel();
      var customValues = new List<CustomAttributeValueViewModel>();
      if (model.CustomAttributeValues != null && model.CustomAttributeValues.Any())
      {
        var ruleNames = await GetNameOfCustomAttributeRulesByTheirIds(model.CustomAttributeValues);
        customValues = model.CustomAttributeValues
          .Select(elem => new CustomAttributeValueViewModel(elem.Id, elem.Value, elem.CustomAttributeRuleId,
            ruleNames[elem.CustomAttributeRuleId])).ToList();
      }

      return new NormalizedLogViewModel(model.Id,
        model.ComponentId,
        model.DateTime,
        model.Message,
        new SeverityLevelViewModel(model.Severity, SeverityToString(model.Severity)),
        customValues,
        model.RawLogId
      );
    }