119 lines
3.7 KiB
Ruby
119 lines
3.7 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.10.0",
|
|
revision: "1428d58cf2ed945441fb2ed03961cafa9e4ad3eb"
|
|
license "Apache-2.0"
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "b813874bd01480464805e9f5f33e862ff7f3c177cf0109c2fc909d70ae0fb630" => :big_sur
|
|
sha256 "6d3024005b78edf808ca58c5eb3c5d8e1ac3c4c5511e2b4fe337f5222bb5458b" => :catalina
|
|
sha256 "2149137945717856ca8c393f287c397d4109719d100b3c41a7c751f18eec6e22" => :mojave
|
|
sha256 "5107cd9fd07f2a995ac43bc31416fa87c0585c52588d2b6c90c340fcfbf92e62" => :high_sierra
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "python@3.8" => :build
|
|
|
|
resource "virtualenv" do
|
|
url "https://files.pythonhosted.org/packages/b1/72/2d70c5a1de409ceb3a27ff2ec007ecdd5cc52239e7c74990e32af57affe9/virtualenv-15.2.0.tar.gz"
|
|
sha256 "1d7e241b431e7afce47e77f8843a276f652699d1fa4f93b9d8ce0076fd7b0b54"
|
|
end
|
|
|
|
def install
|
|
# remove non open source files
|
|
rm_rf "x-pack"
|
|
|
|
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 Formula["python@3.8"].opt_bin/"python3", *Language::Python.setup_install_args(buildpath/"vendor")
|
|
end
|
|
|
|
ENV.prepend_path "PATH", buildpath/"vendor/bin" # for virtualenv
|
|
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
|