如何检测Metricbeat或Filebeat插入了USB磁盘?

问题描述

我需要检测USB磁盘是否已插入Metricbeat或Filebeat才能将其报告给Elasticsearch服务器。

对于Windows和Linux,我都需要它。 有什么想法吗?

解决方法

使用Filebeat,就像为USB磁盘卷的路径指定log输入一样简单:

- type: log

  # Change to true to enable this input configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
   # On Mac
   - /Volumes/MY_USB_DISK/*.*
   # On Linux
   - /mnt/usb/*.*
   # On Windows (pick the right drive letter on which the USB disk is mounted)
   - F:\*.*

  fields:
    source: usb

然后,您可以启动Filebeat,一旦插入USB磁盘,Filebeat就会开始尾随所有与上述路径匹配的文件,并将它们发送到ES。