homebrew-core/Formula/heartbeat.rb
2019-10-16 08:23:11 +02:00

123 lines
3.8 KiB
Ruby

class Heartbeat < Formula
desc "Lightweight Shipper for Uptime Monitoring"
homepage "https://www.elastic.co/products/beats/heartbeat"
# Pinned at 6.2.x because of a licencing issue
# See: https://github.com/Homebrew/homebrew-core/pull/28995
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
rebuild 1
sha256 "14c0b07ea98e6e200ba4669b11a7bba371356c31748fcc90b8033001c84b9310" => :catalina
sha256 "41bc5429f96531dee4d989d5b5bf59c5183c3be8bf2218f3231d4b3e6b0e9a13" => :mojave
sha256 "ad880a8fb097c0e9a3b61de9cd53b2cfefb6d19effdda945e4f2f3bde9daba50" => :high_sierra
sha256 "b6c3d3d20c0154a66847ed9837247964c874eb559b5ad8bc451ba6b660cd0256" => :sierra
end
depends_on "go" => :build
depends_on "python" => :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
xy = Language::Python.major_minor_version "python3"
ENV.prepend_create_path "PYTHONPATH", buildpath/"vendor/lib/python#{xy}/site-packages"
resource("virtualenv").stage do
system "python3", *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