homebrew-core/Formula/heartbeat.rb

104 lines
3.2 KiB
Ruby

class Heartbeat < Formula
desc "Lightweight Shipper for Uptime Monitoring"
homepage "https://www.elastic.co/beats/heartbeat"
url "https://github.com/elastic/beats.git",
tag: "v7.11.1",
revision: "9b2fecb327a29fe8d0477074d8a2e42a3fabbc4b"
license "Apache-2.0"
head "https://github.com/elastic/beats.git"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "55d57eca6546a9ba730a2fedc4d4d185d4784636d655ce7f383c2550747fb9d6"
sha256 cellar: :any_skip_relocation, big_sur: "81b40e925a83d74512a8a73eb4cd6c9ca951396172d5fb9dac80c6bdf54bc1aa"
sha256 cellar: :any_skip_relocation, catalina: "5bb02b948c3af4012c1fb1ff2ab644964ae0cb49283a9dc3a63d20c95b8a2584"
sha256 cellar: :any_skip_relocation, mojave: "80a35b1215c4b8818e447ed3c02b491afdc0e06d83de2fbfdd38b06f43585816"
end
depends_on "go" => :build
depends_on "python@3.9" => :build
def install
# remove non open source files
rm_rf "x-pack"
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/elastic/beats").install buildpath.children
ENV.prepend_path "PATH", buildpath/"bin" # for mage (build tool)
cd "src/github.com/elastic/beats/heartbeat" do
system "make", "mage"
# prevent downloading binary wheels during python setup
system "make", "PIP_INSTALL_PARAMS=--no-binary :all", "python-env"
system "mage", "-v", "build"
ENV.deparallelize
system "mage", "-v", "update"
(etc/"heartbeat").install Dir["heartbeat.*", "fields.yml"]
(libexec/"bin").install "heartbeat"
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
port = free_port
(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
fork do
exec bin/"heartbeat", "-path.config", testpath/"config", "-path.data",
testpath/"data"
end
sleep 5
assert_match "hello", pipe_output("nc -l #{port}", "goodbye\n", 0)
sleep 5
assert_match "\"status\":\"up\"", (testpath/"heartbeat/heartbeat").read
end
end