126 lines
3.9 KiB
Ruby
126 lines
3.9 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.8.0",
|
|
:revision => "f79387d32717d79f689d94fda1ec80b2cf285d30"
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "5235b8f234400aaceb43e59792f9712001246f4680659a0d9842415a0cdfd6e2" => :catalina
|
|
sha256 "e05e913f45fa9e4815ca5bb4ae7e61175dbf28ec521dc95f1f287ac022a22f16" => :mojave
|
|
sha256 "a60293f9c34d58e05f5be00b223c40eeba80b93582575f4c7d6594b4653c25ba" => :high_sierra
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "python@3.8" => :build
|
|
|
|
resource "virtualenv" do
|
|
url "https://files.pythonhosted.org/packages/b1/72/2d70c5a1de409ceb3a27ff2ec007ecdd5cc52239e7c74990e32af57affe9/virtualenv-15.2.0.tar.gz"
|
|
sha256 "1d7e241b431e7afce47e77f8843a276f652699d1fa4f93b9d8ce0076fd7b0b54"
|
|
end
|
|
|
|
def install
|
|
# remove non open source files
|
|
rm_rf "x-pack"
|
|
|
|
ENV["GOPATH"] = buildpath
|
|
(buildpath/"src/github.com/elastic/beats").install Dir["{*,.git,.gitignore}"]
|
|
|
|
xy = Language::Python.major_minor_version "python3"
|
|
ENV.prepend_create_path "PYTHONPATH", buildpath/"vendor/lib/python#{xy}/site-packages"
|
|
|
|
resource("virtualenv").stage do
|
|
system Formula["python@3.8"].opt_bin/"python3", *Language::Python.setup_install_args(buildpath/"vendor")
|
|
end
|
|
|
|
ENV.prepend_path "PATH", buildpath/"vendor/bin" # for virtualenv
|
|
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_COMMANDS=--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
|