100 lines
2.7 KiB
Ruby
100 lines
2.7 KiB
Ruby
class Heartbeat < Formula
|
|
desc "Lightweight Shipper for Uptime Monitoring"
|
|
homepage "https://www.elastic.co/products/beats/heartbeat"
|
|
url "https://github.com/elastic/beats/archive/v6.1.3.tar.gz"
|
|
sha256 "5a21ce1eca7eab2b8214b54a7f4690cd557cd05073119f861025330e1b4006a3"
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "077ed3d0c3b9646660dc5a525a12d3d21dbcf17dcd968608dafdca1ba28ffb4e" => :high_sierra
|
|
sha256 "050f3b644f70afb6481ded41d1db9160b1dea8cc8262a4c143cee2e159bfc58c" => :sierra
|
|
sha256 "050551dd49c069625f685363b07780cc336bdaa06517e6affb75b4252396102c" => :el_capitan
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
|
|
def install
|
|
ENV["GOPATH"] = buildpath
|
|
(buildpath/"src/github.com/elastic/beats").install buildpath.children
|
|
|
|
cd "src/github.com/elastic/beats/heartbeat" do
|
|
system "make"
|
|
(libexec/"bin").install "heartbeat"
|
|
libexec.install "_meta/kibana"
|
|
|
|
(etc/"heartbeat").install Dir["heartbeat*.{json,yml}"]
|
|
prefix.install_metafiles
|
|
end
|
|
|
|
(bin/"heartbeat").write <<~EOS
|
|
#!/bin/sh
|
|
exec #{libexec}/bin/heartbeat \
|
|
-path.config #{etc}/heartbeat \
|
|
-path.home #{libexec} \
|
|
-path.logs #{var}/log/heartbeat \
|
|
-path.data #{var}/lib/heartbeat \
|
|
"$@"
|
|
EOS
|
|
end
|
|
|
|
def post_install
|
|
(var/"lib/heartbeat").mkpath
|
|
(var/"log/heartbeat").mkpath
|
|
end
|
|
|
|
plist_options :manual => "heartbeat"
|
|
|
|
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}/heartbeat</string>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
require "socket"
|
|
|
|
server = TCPServer.new(0)
|
|
port = server.addr[1]
|
|
server.close
|
|
|
|
(testpath/"config/heartbeat.yml").write <<~EOS
|
|
heartbeat.monitors:
|
|
- type: tcp
|
|
schedule: '@every 5s'
|
|
hosts: ["localhost:#{port}"]
|
|
check.send: "hello\\n"
|
|
check.receive: "goodbye\\n"
|
|
output.file:
|
|
path: "#{testpath}/heartbeat"
|
|
filename: heartbeat
|
|
codec.format:
|
|
string: '%{[monitor]}'
|
|
EOS
|
|
pid = fork do
|
|
exec bin/"heartbeat", "-path.config", testpath/"config", "-path.data",
|
|
testpath/"data"
|
|
end
|
|
sleep 5
|
|
|
|
begin
|
|
assert_match "hello", pipe_output("nc -c -l #{port}", "goodbye\n", 0)
|
|
sleep 5
|
|
assert_match "\"status\":\"up\"", (testpath/"heartbeat/heartbeat").read
|
|
ensure
|
|
Process.kill "SIGINT", pid
|
|
Process.wait pid
|
|
end
|
|
end
|
|
end
|