https://www.elastic.co/guide/en/beats/filebeat/current/processor-script.html

    1. ###################### Filebeat Configuration Example #########################
    2. # This file is an example configuration file highlighting only the most common
    3. # options. The filebeat.reference.yml file from the same directory contains all the
    4. # supported options with more comments. You can use it as a reference.
    5. #
    6. # You can find the full configuration reference here:
    7. # https://www.elastic.co/guide/en/beats/filebeat/index.html
    8. # For more available modules and options, please see the filebeat.reference.yml sample
    9. # configuration file.
    10. #=========================== Filebeat inputs =============================
    11. filebeat.inputs:
    12. # Each - is an input. Most options can be set at the input level, so
    13. # you can use different inputs for various configurations.
    14. # Below are the input specific configurations.
    15. - type: log
    16. # Change to true to enable this input configuration.
    17. enabled: false
    18. # Paths that should be crawled and fetched. Glob based paths.
    19. paths:
    20. - /var/log/*.log
    21. #- c:\programdata\elasticsearch\logs\*
    22. # Exclude lines. A list of regular expressions to match. It drops the lines that are
    23. # matching any regular expression from the list.
    24. #exclude_lines: ['^DBG']
    25. # Include lines. A list of regular expressions to match. It exports the lines that are
    26. # matching any regular expression from the list.
    27. #include_lines: ['^ERR', '^WARN']
    28. # Exclude files. A list of regular expressions to match. Filebeat drops the files that
    29. # are matching any regular expression from the list. By default, no files are dropped.
    30. #exclude_files: ['.gz$']
    31. # Optional additional fields. These fields can be freely picked
    32. # to add additional information to the crawled log files for filtering
    33. #fields:
    34. # level: debug
    35. # review: 1
    36. ### Multiline options
    37. # Multiline can be used for log messages spanning multiple lines. This is common
    38. # for Java Stack Traces or C-Line Continuation
    39. # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
    40. #multiline.pattern: ^\[
    41. # Defines if the pattern set under pattern should be negated or not. Default is false.
    42. #multiline.negate: false
    43. # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern
    44. # that was (not) matched before or after or as long as a pattern is not matched based on negate.
    45. # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash
    46. #multiline.match: after
    47. #多行
    48. - type: log
    49. enabled: true
    50. paths:
    51. - /logs/cave2/cave2_all_*/*.log
    52. multiline.pattern: '^\[[0-9][0-9]'
    53. multiline.negate: true
    54. multiline.max_lines: 20000
    55. multiline.match: after
    56. multiline.timeout: 300s
    57. fields:
    58. AvalonIndexKey: co-ap-server
    59. #============================= Filebeat modules ===============================
    60. filebeat.config.modules:
    61. # Glob pattern for configuration loading
    62. path: ${path.config}/modules.d/*.yml
    63. # Set to true to enable config reloading
    64. reload.enabled: false
    65. # Period on which files under path should be checked for changes
    66. #reload.period: 10s
    67. #==================== Elasticsearch template setting ==========================
    68. setup.template.settings:
    69. index.number_of_shards: 1
    70. #index.codec: best_compression
    71. #_source.enabled: false
    72. #================================ General =====================================
    73. # The name of the shipper that publishes the network data. It can be used to group
    74. # all the transactions sent by a single shipper in the web interface.
    75. #name:
    76. # The tags of the shipper are included in their own field with each
    77. # transaction published.
    78. #tags: ["service-X", "web-tier"]
    79. # Optional fields that you can specify to add additional information to the
    80. # output.
    81. #fields:
    82. # env: staging
    83. #============================== Dashboards =====================================
    84. # These settings control loading the sample dashboards to the Kibana index. Loading
    85. # the dashboards is disabled by default and can be enabled either by setting the
    86. # options here or by using the `setup` command.
    87. #setup.dashboards.enabled: false
    88. # The URL from where to download the dashboards archive. By default this URL
    89. # has a value which is computed based on the Beat name and version. For released
    90. # versions, this URL points to the dashboard archive on the artifacts.elastic.co
    91. # website.
    92. #setup.dashboards.url:
    93. #============================== Kibana =====================================
    94. # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
    95. # This requires a Kibana endpoint configuration.
    96. setup.kibana:
    97. # Kibana Host
    98. # Scheme and port can be left out and will be set to the default (http and 5601)
    99. # In case you specify and additional path, the scheme is required: http://localhost:5601/path
    100. # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
    101. #host: "localhost:5601"
    102. # Kibana Space ID
    103. # ID of the Kibana Space into which the dashboards should be loaded. By default,
    104. # the Default Space will be used.
    105. #space.id:
    106. #============================= Elastic Cloud ==================================
    107. # These settings simplify using Filebeat with the Elastic Cloud (https://cloud.elastic.co/).
    108. # The cloud.id setting overwrites the `output.elasticsearch.hosts` and
    109. # `setup.kibana.host` options.
    110. # You can find the `cloud.id` in the Elastic Cloud web UI.
    111. #cloud.id:
    112. # The cloud.auth setting overwrites the `output.elasticsearch.username` and
    113. # `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
    114. #cloud.auth:
    115. #================================ Outputs =====================================
    116. # Configure what output to use when sending the data collected by the beat.
    117. #-------------------------- Elasticsearch output ------------------------------
    118. #output.elasticsearch:
    119. # Array of hosts to connect to.
    120. # hosts: ["localhost:9200"]
    121. # Optional protocol and basic auth credentials.
    122. #protocol: "https"
    123. #username: "elastic"
    124. #password: "changeme"
    125. #----------------------------- Logstash output --------------------------------
    126. #output.logstash:
    127. # The Logstash hosts
    128. #hosts: ["localhost:5044"]
    129. # Optional SSL. By default is off.
    130. # List of root certificates for HTTPS server verifications
    131. #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
    132. # Certificate for SSL client authentication
    133. #ssl.certificate: "/etc/pki/client/cert.pem"
    134. # Client Certificate Key
    135. #ssl.key: "/etc/pki/client/cert.key"
    136. #------------------------------- Redis output ----------------------------------
    137. output.redis:
    138. hosts: ["172.16.0.61:6379"]
    139. #password: ""
    140. db: 1
    141. timeout: 10
    142. key: "%{[fields.AvalonIndexKey]}"
    143. #================================ Processors =====================================
    144. # Configure processors to enhance or manipulate events generated by the beat.
    145. processors:
    146. - script:
    147. lang: javascript
    148. id: my_filter
    149. tag: enable
    150. # 切割message字段 获取start_time
    151. source: >
    152. function process(event) {
    153. var str= event.Get("message");
    154. var time =str.split(" ").slice(0,2).join(" ").replace('[','').replace(']','');
    155. event.Put("start_time",time);
    156. }
    157. - timestamp:
    158. # 格式化时间值 给 时间戳
    159. field: start_time
    160. layouts:
    161. - '01-02 15:04:05'
    162. - '01-02 15:04:05.999'
    163. test:
    164. - '06-22 16:33:51'
    165. #- add_host_metadata: ~
    166. #- add_cloud_metadata: ~
    167. #- add_docker_metadata: ~
    168. #- add_kubernetes_metadata: ~
    169. - drop_fields:
    170. fields: ["agent", "cloud","ecs","host.os","log.offset","tags"]
    171. #================================ Logging =====================================
    172. # Sets log level. The default log level is info.
    173. # Available log levels are: error, warning, info, debug
    174. #logging.level: debug
    175. # At debug level, you can selectively enable logging only for some components.
    176. # To enable all selectors use ["*"]. Examples of other selectors are "beat",
    177. # "publish", "service".
    178. #logging.selectors: ["*"]
    179. #============================== X-Pack Monitoring ===============================
    180. # filebeat can export internal metrics to a central Elasticsearch monitoring
    181. # cluster. This requires xpack monitoring to be enabled in Elasticsearch. The
    182. # reporting is disabled by default.
    183. # Set to true to enable the monitoring reporter.
    184. #monitoring.enabled: false
    185. # Sets the UUID of the Elasticsearch cluster under which monitoring data for this
    186. # Filebeat instance will appear in the Stack Monitoring UI. If output.elasticsearch
    187. # is enabled, the UUID is derived from the Elasticsearch cluster referenced by output.elasticsearch.
    188. #monitoring.cluster_uuid:
    189. # Uncomment to send the metrics to Elasticsearch. Most settings from the
    190. # Elasticsearch output are accepted here as well.
    191. # Note that the settings should point to your Elasticsearch *monitoring* cluster.
    192. # Any setting that is not set is automatically inherited from the Elasticsearch
    193. # output configuration, so if you have the Elasticsearch output configured such
    194. # that it is pointing to your Elasticsearch monitoring cluster, you can simply
    195. # uncomment the following line.
    196. #monitoring.elasticsearch:
    197. #================================= Migration ==================================
    198. # This allows to enable 6.7 migration aliases
    199. #migration.6_to_7.enabled: true