Если вы видите что-то необычное, просто сообщите мне. Skip to main content

Как отличать различные типы логов в Logstash

Зачем вообще ризлчать логи?

IfЕсли youвы areсобираете collectingдва twoнабора setsлогов ofиспользуя logsодин usingи theтот sameже источник, вы возможно захотите разделить их таким образом, чтобы обработать каждый по отдельности.

Для примера, вы можете захотеть изменить имя индекса одного типа логов чтобы понимать, что это за лог.

Как разделить логи на два типа?

Деление между типами логов в Logstash может быть получено разыми путями. Если вы используете источники Elastic beat source you may want to separate them so that you can perform certain actions on them if they meet certain conditions.

For example, you may want to change the index name of one log type to help make it more identifiable.

How do I separate my logs into different log types?

Differentiating between different log types in Logstash can be achieved in various ways. If you are using an Elastic Beat source such asBeat: Auditbeat, Filebeat or Metricbeat youу canвас haveможет multipleбыть inputsмного sectionsразделов inв yourвашем configurationконфигурациионном fileфайле, toдля distinguishтого, betweenчтобы differentпонять typesчто ofза logsтип byлога editingперед theвами Beatпросто configurationизменив fileконфигурационный andфайл settingи theнастроив typeтип toс beпомощью namedразличного differently.именования.

ForДля theпримера, example,ниже belowмы we are editing theредактируем Filebeat configurationконфигурационный fileфайл toдля separateразделения ourнаших logsлогов intoна differentразличные types.типы.

filebeat.inputs:

- type: logType1
  enabled: true
  paths:
    - /var/folder_of_logs/*.log

- type: logType2
  enabled: true
  paths:
    - /var/another_folder_of_logs/*.log
  fields_under_root: true

InВ theпримере aboveвыше exampleу weнас haveесть twoдве foldersпапки thatкоторые containсодержат logs.лог.

  • /var/folder_of_logs/
  • /var/another_folder_of_logs/

InЧтоб orderрассказать toо tellразнице theмежду differenceлогами betweenкоторые theполучаются logsиз thatэтих areдвух comingпапко, fromнам theseнужно folders,добавить welogType1 haveдля addedодного logType1лога toи onelogType2 setдля ofдругого logsнабора andлогов. logType2Отсюда toмы theможем other set of logs. From here we can then useиспользовать Logstash toдля furtherдальнейшего differentiateразличения betweenмежду theseэтих logтипов types.логов.

UsingИспользование Logstash toдля furtherразделения differentiateлогов betweenна log typesтипы

ToДля furtherдальнейшего differentiateразделения betweenмежду theтипов logлогов, types,нам weнужно needиспользовать toфильтр makeLogstash. useВы ofможете theиметь доступ к фильтрам Logstash Filter.из Youдашборка canдля accessлюбой your Logstash filters from the dashboard for any of yourвашего Logit Stacks byвыбирая choosing View Stack Settings > Logstash Pipelines.Pipelines.

YouВы canможете useиспользовать Logstash toдля queryотбора logтипа typesлога inв yourвашем Logstash filterфильтре andи thenзатем performпроизведем actionsдействия basedоснованные uponна thatэтом condition.условии. ForДля example,примера, weмы mayможем wantзахотеть toизменить changeимя theпоявлюящееся indexпод nameElasticSearch the logs appear under in Elasticsearch andв Kibana.

if [type] == "logType1" {
   mutate {      
      add_field => { "[@metadata][beat]" => "YOURINDEXNAME" }
   } 
} 
else if [type] == "logType2" {
   mutate {
       add_field => { "[@metadata][beat]" => "YOURINDEXNAMETWO" }
   } 
}

Использование полей для пояснения типа логов.

UsingВы logтак fieldsже toможете distinguishвыбирать logполя typesвашего Youлога canдля alsoпроверки queryтипа yourлога logесли fieldsвы toсоздали checkполе theв logвашем typeлоге. ifДля youпримера, haveвы createdможете theсоздать field in your log. For example, you could create the mylog.type fieldполе andи thenзатем transformпреобразовать thatэто fieldполе toв iis.logs.logs.

if [mylog][type] == "my-iis-logs" {
   mutate {
       rename => { "[mylog][type]" => "[iis][logs]" }
}