118 lines
3.5 KiB
Ruby
118 lines
3.5 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.2.4.tar.gz"
|
|
sha256 "87d863cf55863329ca80e76c3d813af2960492f4834d4fea919f1d4b49aaf699"
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "e4b90c3ab163e7ed9373b93745d06fa4833acebd084c97424b237a5ad062c074" => :high_sierra
|
|
sha256 "0e91314114812dab5c6779a4c7b24c613f6b7ac8b7bbfc4624e0aedd826c73c5" => :sierra
|
|
sha256 "d244b789c7163290579b3a526d3f07d6495c2de9dadacf4e77147464d93f5ff0" => :el_capitan
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "python@2" => :build
|
|
|
|
resource "virtualenv" do
|
|
url "https://files.pythonhosted.org/packages/b1/72/2d70c5a1de409ceb3a27ff2ec007ecdd5cc52239e7c74990e32af57affe9/virtualenv-15.2.0.tar.gz"
|
|
sha256 "1d7e241b431e7afce47e77f8843a276f652699d1fa4f93b9d8ce0076fd7b0b54"
|
|
end
|
|
|
|
def install
|
|
ENV["GOPATH"] = buildpath
|
|
(buildpath/"src/github.com/elastic/beats").install buildpath.children
|
|
|
|
ENV.prepend_create_path "PYTHONPATH", buildpath/"vendor/lib/python2.7/site-packages"
|
|
|
|
resource("virtualenv").stage do
|
|
system "python", *Language::Python.setup_install_args(buildpath/"vendor")
|
|
end
|
|
|
|
ENV.prepend_path "PATH", buildpath/"vendor/bin"
|
|
|
|
cd "src/github.com/elastic/beats/heartbeat" do
|
|
system "make"
|
|
# prevent downloading binary wheels during python setup
|
|
system "make", "PIP_INSTALL_COMMANDS=--no-binary :all", "python-env"
|
|
system "make", "DEV_OS=darwin", "update"
|
|
|
|
(etc/"heartbeat").install Dir["heartbeat.*", "fields.yml"]
|
|
(libexec/"bin").install "heartbeat"
|
|
prefix.install "_meta/kibana"
|
|
end
|
|
|
|
prefix.install_metafiles buildpath/"src/github.com/elastic/beats"
|
|
|
|
(bin/"heartbeat").write <<~EOS
|
|
#!/bin/sh
|
|
exec #{libexec}/bin/heartbeat \
|
|
--path.config #{etc}/heartbeat \
|
|
--path.data #{var}/lib/heartbeat \
|
|
--path.home #{prefix} \
|
|
--path.logs #{var}/log/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
|