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.5.2.tar.gz" sha256 "39e792324a35fe84ef9a63cd5324252bc71d1c665188e8d597e12ca170cfde7a" head "https://github.com/elastic/beats.git" bottle do cellar :any_skip_relocation sha256 "603e76313ba678dbeb5a43a13f282a7d2bb5c75fdb471ea20f73e6a6596e6886" => :sierra sha256 "80285bc2a6e4a668a47ba4f758f8fcafb5454936fc0825b05612bcf2e2b6340e" => :el_capitan sha256 "dc525bc8b3d6a51c2a842f81c22ea1b53f5659dee880c4ab4068997c9602cf33" => :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" system "make", "modules" libexec.install "filebeat" (prefix/"module").install Dir["_meta/module.generated/*"] (etc/"filebeat").install Dir["filebeat.*"] 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 Label #{plist_name} Program #{opt_bin}/filebeat RunAtLoad 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