homebrew-core/Formula/auditbeat.rb

121 lines
4.0 KiB
Ruby

class Auditbeat < Formula
desc "Lightweight Shipper for Audit Data"
homepage "https://www.elastic.co/products/beats/auditbeat"
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 "66c5191b6c503fd23bf7de893e6ee9132050e2cad0a0fb9ecc9d083ae1244616" => :big_sur
sha256 "37f6788d570528b132f06ff533d02234e7f2c760a314a8bb1888cf203d577d8d" => :catalina
sha256 "8ee7e1494305368f8f70c275d28318031296037ec2ef230e25382a6548d82ea0" => :mojave
sha256 "b795b5ae0bdef35f4deb0ffcd787781cf4bbbcbc04e7a364c5e94cd35e09fcdc" => :high_sierra
end
depends_on "go" => :build
depends_on "python@3.8" => :build
resource "virtualenv" do
url "https://files.pythonhosted.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz"
sha256 "02f8102c2436bb03b3ee6dede1919d1dac8a427541652e5ec95171ec8adbc93a"
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/auditbeat" do
# don't build docs because it would fail creating the combined OSS/x-pack
# docs and we aren't installing them anyway
inreplace "magefile.go", "devtools.GenerateModuleIncludeListGo, Docs)",
"devtools.GenerateModuleIncludeListGo)"
system "make", "mage"
# prevent downloading binary wheels during python setup
system "make", "PIP_INSTALL_PARAMS=--no-binary :all", "python-env"
system "mage", "-v", "build"
system "mage", "-v", "update"
(etc/"auditbeat").install Dir["auditbeat.*", "fields.yml"]
(libexec/"bin").install "auditbeat"
prefix.install "build/kibana"
end
prefix.install_metafiles buildpath/"src/github.com/elastic/beats"
(bin/"auditbeat").write <<~EOS
#!/bin/sh
exec #{libexec}/bin/auditbeat \
--path.config #{etc}/auditbeat \
--path.data #{var}/lib/auditbeat \
--path.home #{prefix} \
--path.logs #{var}/log/auditbeat \
"$@"
EOS
end
def post_install
(var/"lib/auditbeat").mkpath
(var/"log/auditbeat").mkpath
end
plist_options manual: "auditbeat"
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}/auditbeat</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOS
end
test do
(testpath/"files").mkpath
(testpath/"config/auditbeat.yml").write <<~EOS
auditbeat.modules:
- module: file_integrity
paths:
- #{testpath}/files
output.file:
path: "#{testpath}/auditbeat"
filename: auditbeat
EOS
fork do
exec "#{bin}/auditbeat", "-path.config", testpath/"config", "-path.data", testpath/"data"
end
sleep 5
touch testpath/"files/touch"
sleep 30
s = IO.readlines(testpath/"auditbeat/auditbeat").last(1)[0]
assert_match /"action":\["(initial_scan|created)"\]/, s
realdirpath = File.realdirpath(testpath)
assert_match "\"path\":\"#{realdirpath}/files/touch\"", s
end
end