homebrew-core/Formula/heartbeat.rb

99 lines
3.3 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: "v8.4.3",
revision: "c2f2aba479653563dbaabefe0f86f5579708ec94"
license "Apache-2.0"
head "https://github.com/elastic/beats.git", branch: "master"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "2324a07996219ab1803497f469ffa3cc228ee1aaf3f1a7dfffb6c1a6bec51f6b"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "8eb375766911634e2a96b06f39ff27ab9038c361b05ddd7a74a52b075df494b6"
sha256 cellar: :any_skip_relocation, monterey: "d448f84757b7a721548084eed16b89a935d6aa0a624503e10e03ee32fde5785d"
sha256 cellar: :any_skip_relocation, big_sur: "3d59239064f9a992b70f933af701075cf4c630811f153488560906a349aefedd"
sha256 cellar: :any_skip_relocation, catalina: "82366c45ff1112e709e774dcb44a0fe3aa0f156c031cc21d63e8340d49dfd4b6"
sha256 cellar: :any_skip_relocation, x86_64_linux: "0050f11e40e96df6e5c5e0e1efbbae6c8c8b05da54ea45f16b373bd3e19e6f31"
end
depends_on "go" => :build
depends_on "mage" => :build
depends_on "python@3.10" => :build
uses_from_macos "netcat" => :test
def install
# remove non open source files
rm_rf "x-pack"
cd "heartbeat" do
# 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
(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
chmod 0555, bin/"heartbeat" # generate_completions_from_executable fails otherwise
generate_completions_from_executable(bin/"heartbeat", "completion", shells: [:bash, :zsh])
end
def post_install
(var/"lib/heartbeat").mkpath
(var/"log/heartbeat").mkpath
end
service do
run opt_bin/"heartbeat"
end
test do
# FIXME: This keeps stalling CI when tested as a dependent. See, for example,
# https://github.com/Homebrew/homebrew-core/pull/91712
return if OS.linux? && ENV["HOMEBREW_GITHUB_ACTIONS"].present?
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
output = JSON.parse((testpath/"data/meta.json").read)
assert_includes output, "first_start"
(testpath/"data").glob("heartbeat-*.ndjson") do |file|
s = JSON.parse(file.read)
assert_match "up", s["status"]
end
end
end