87 lines
2.5 KiB
Ruby
87 lines
2.5 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/archive/v5.0.2.tar.gz"
|
|
sha256 "feef1e53b978c12b3b3c552534fd666839df5d7d3b974e16636360ca6c4ab7c0"
|
|
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "a4c5f859319dca46cd9d50f314167782f697260ef44272c37d4746f24d0a7fba" => :sierra
|
|
sha256 "6116be088a93f80fa97232c9d37a6c80944c65a37cf61c12260ed59b93b99ddb" => :el_capitan
|
|
sha256 "6e6dd964f937b59480109108815780cee80eac67f37825dc201766c095b96c45" => :yosemite
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
|
|
def install
|
|
gopath = buildpath/"gopath"
|
|
(gopath/"src/github.com/elastic/beats").install Dir["{*,.git,.gitignore}"]
|
|
|
|
ENV["GOPATH"] = gopath
|
|
|
|
cd gopath/"src/github.com/elastic/beats/filebeat" do
|
|
system "make"
|
|
libexec.install "filebeat"
|
|
|
|
(etc/"filebeat").install("filebeat.yml", "filebeat.template.json", "filebeat.template-es2x.json")
|
|
end
|
|
|
|
(bin/"filebeat").write <<-EOS.undent
|
|
#!/bin/sh
|
|
exec #{libexec}/filebeat -path.config #{etc}/filebeat -path.home #{prefix} -path.logs #{var}/log/filebeat -path.data #{var}/filebeat $@
|
|
EOS
|
|
end
|
|
|
|
plist_options :manual => "filebeat"
|
|
|
|
def plist; <<-EOS.undent
|
|
<?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.undent
|
|
filebeat:
|
|
prospectors:
|
|
-
|
|
paths:
|
|
- #{log_file}
|
|
scan_frequency: 0.1s
|
|
filebeat.idle_timeout: 0.1s
|
|
output:
|
|
file:
|
|
path: #{testpath}
|
|
EOS
|
|
|
|
(testpath/"log").mkpath
|
|
(testpath/"data").mkpath
|
|
|
|
filebeat_pid = fork { exec "#{bin}/filebeat -c #{testpath}/filebeat.yml -path.config #{testpath}/filebeat -path.home=#{testpath} -path.logs #{testpath}/log -path.data #{testpath}" }
|
|
begin
|
|
sleep 1
|
|
log_file.append_lines "foo bar baz"
|
|
sleep 5
|
|
|
|
assert File.exist? testpath/"filebeat"
|
|
ensure
|
|
Process.kill("TERM", filebeat_pid)
|
|
end
|
|
end
|
|
end
|