89 lines
2.6 KiB
Ruby
89 lines
2.6 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.3.0.tar.gz"
|
|
sha256 "311030e33ec6f5f335ddf9e0b8eb3a1cd9e378dbc7c0937658a02099457c5895"
|
|
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "74c791c4ddc49f94732d146e40ed299f2707fab7496e3e3f272ad63e4840e5d6" => :sierra
|
|
sha256 "ae49ce64140d420d4f551654aa9f8b23b655ecd03c2065aec5ae0c9e9b04d9a1" => :el_capitan
|
|
sha256 "f4b2dc6c43db3f259df30d9627aa4ffc846105d0aafebc46d985705ac52a0ed6" => :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
|
|
|
|
prefix.install_metafiles gopath/"src/github.com/elastic/beats"
|
|
|
|
(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
|