homebrew-core/Formula/filebeat.rb

101 lines
3.4 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: "v8.4.3",
revision: "c2f2aba479653563dbaabefe0f86f5579708ec94"
# 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", branch: "master"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "7ff77bf4367171152397a554e4c182caf293e3babc7f5d8aeb3fafda5935f739"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "770b5d6e4867234c7c802e7bb51bd9f8c929ace0da026290196d88a1b32c9b9b"
sha256 cellar: :any_skip_relocation, monterey: "cc9a2240ef1a914e91b0dfa23da026b51a5c205fc44c2395b40be0e6fca3fdff"
sha256 cellar: :any_skip_relocation, big_sur: "413d3ec39d02f5b197bbf575e5a0e19f858915818dd4014542aa2027ea0810c8"
sha256 cellar: :any_skip_relocation, catalina: "fd001fbc4111e2fc54c6ac56d368ac16cbeb9b08401e1c9ddcf75920a524e6e6"
sha256 cellar: :any_skip_relocation, x86_64_linux: "636d4ed98978b91843955b055ef5190fbb0a09f1e6dd85ce6bcf8a7c546efbbb"
end
depends_on "go" => :build
depends_on "mage" => :build
depends_on "python@3.10" => :build
uses_from_macos "rsync" => :build
def install
# remove non open source files
rm_rf "x-pack"
cd "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,"
# 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
(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
chmod 0555, bin/"filebeat" # generate_completions_from_executable fails otherwise
generate_completions_from_executable(bin/"filebeat", "completion", shells: [:bash, :zsh])
end
service do
run opt_bin/"filebeat"
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/"meta.json", :exist?
assert_predicate testpath/"registry/filebeat", :exist?
end
end