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.4.0.tar.gz" sha256 "d236f9433d48b69cc2f0bf3617f17d5f2eec261acee96cc28d8b72be84afc0a7" head "https://github.com/elastic/beats.git" bottle do cellar :any_skip_relocation sha256 "4ce1253bd8994cd5650d2b47a2ac66e5d19ec081f805084e82ee8cce69021fc7" => :sierra sha256 "2371f9799852a9dda0db3e0a6a801c83780cac721c916c3ce92bee792b55ea2d" => :el_capitan sha256 "d9c1be0518ec2ac0093e7c504306ac0c1b3714bbaac56d0a7168446101a74313" => :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 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