117 lines
3.7 KiB
Ruby
117 lines
3.7 KiB
Ruby
class Filebeat < Formula
|
|
desc "File harvester to ship log files to Elasticsearch or Logstash"
|
|
homepage "https://www.elastic.co/products/beats/filebeat"
|
|
url "https://github.com/elastic/beats.git",
|
|
tag: "v7.11.1",
|
|
revision: "9b2fecb327a29fe8d0477074d8a2e42a3fabbc4b"
|
|
# Outside of the "x-pack" folder, source code in a given file is licensed
|
|
# under the Apache License Version 2.0
|
|
license "Apache-2.0"
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "7d12f1ce91899083cde755fd701a1fc82efc0c80a4e0c1cbb0b9806d7fc5346f"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "7377ca46006bc3935675090510c588c367c5e6266ab0548fc81c357281764660"
|
|
sha256 cellar: :any_skip_relocation, catalina: "5585c58d130f824cd2670cac74d590b68c7c692ff5be3bdd97ecd4676ac5f1e4"
|
|
sha256 cellar: :any_skip_relocation, mojave: "37a8ad747d5c3b1799ab6ca24e9a36cfeb8dfbed4b8deceb83a64a759c18a80d"
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "python@3.9" => :build
|
|
|
|
uses_from_macos "rsync" => :build
|
|
|
|
def install
|
|
# remove non open source files
|
|
rm_rf "x-pack"
|
|
|
|
ENV["GOPATH"] = buildpath
|
|
(buildpath/"src/github.com/elastic/beats").install Dir["{*,.git,.gitignore}"]
|
|
ENV.prepend_path "PATH", buildpath/"bin" # for mage (build tool)
|
|
|
|
cd "src/github.com/elastic/beats/filebeat" do
|
|
# don't build docs because it would fail creating the combined OSS/x-pack
|
|
# docs and we aren't installing them anyway
|
|
inreplace "magefile.go", "mg.SerialDeps(Fields, Dashboards, Config, includeList, fieldDocs,",
|
|
"mg.SerialDeps(Fields, Dashboards, Config, includeList,"
|
|
|
|
system "make", "mage"
|
|
# prevent downloading binary wheels during python setup
|
|
system "make", "PIP_INSTALL_PARAMS=--no-binary :all", "python-env"
|
|
system "mage", "-v", "build"
|
|
system "mage", "-v", "update"
|
|
|
|
(etc/"filebeat").install Dir["filebeat.*", "fields.yml", "modules.d"]
|
|
(etc/"filebeat"/"module").install Dir["build/package/modules/*"]
|
|
(libexec/"bin").install "filebeat"
|
|
prefix.install "build/kibana"
|
|
end
|
|
|
|
prefix.install_metafiles buildpath/"src/github.com/elastic/beats"
|
|
|
|
(bin/"filebeat").write <<~EOS
|
|
#!/bin/sh
|
|
exec #{libexec}/bin/filebeat \
|
|
--path.config #{etc}/filebeat \
|
|
--path.data #{var}/lib/filebeat \
|
|
--path.home #{prefix} \
|
|
--path.logs #{var}/log/filebeat \
|
|
"$@"
|
|
EOS
|
|
end
|
|
|
|
plist_options manual: "filebeat"
|
|
|
|
def plist
|
|
<<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
|
|
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>Program</key>
|
|
<string>#{opt_bin}/filebeat</string>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
log_file = testpath/"test.log"
|
|
touch log_file
|
|
|
|
(testpath/"filebeat.yml").write <<~EOS
|
|
filebeat:
|
|
inputs:
|
|
-
|
|
paths:
|
|
- #{log_file}
|
|
scan_frequency: 0.1s
|
|
output:
|
|
file:
|
|
path: #{testpath}
|
|
EOS
|
|
|
|
(testpath/"log").mkpath
|
|
(testpath/"data").mkpath
|
|
|
|
fork do
|
|
exec "#{bin}/filebeat", "-c", "#{testpath}/filebeat.yml",
|
|
"-path.config", "#{testpath}/filebeat",
|
|
"-path.home=#{testpath}",
|
|
"-path.logs", "#{testpath}/log",
|
|
"-path.data", testpath
|
|
end
|
|
|
|
sleep 1
|
|
log_file.append_lines "foo bar baz"
|
|
sleep 5
|
|
|
|
assert_predicate testpath/"filebeat", :exist?
|
|
end
|
|
end
|