101 lines
2.7 KiB
Ruby
101 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.1.tar.gz"
|
|
sha256 "c69f0047644be919e42a1d8fa3383c894ca8e054d5b6f727f161ed4ce497ca84"
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "c344e2fa814be534baf003f6f2b2fee29e45fc31999430cda9d7864907d1cae1" => :high_sierra
|
|
sha256 "d6daf015e5cc5d534c89b6d51f98264d24060059025d2eb1ce90d9a60f9e947b" => :sierra
|
|
sha256 "56bf3e311206fd5002974ddb67340b7bb5a13621347f8fbb48f88430c4a24381" => :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
|