homebrew-core/Formula/collectd.rb

96 lines
2.6 KiB
Ruby

class Collectd < Formula
desc "Statistics collection and monitoring daemon"
homepage "https://collectd.org/"
url "https://collectd.org/files/collectd-5.11.0.tar.bz2"
sha256 "37b10a806e34aa8570c1cafa6006c604796fae13cc2e1b3e630d33dcba9e5db2"
license "MIT"
bottle do
sha256 "6b1fc316e7cab7aa33cfb8034a4e7485798ef2ceb477ceee88c212af480a1d3d" => :catalina
sha256 "0a3e17f5f67372dfb30d24f1a3253f53d20d22304f061d90d48a4f7cdd38bbb2" => :mojave
sha256 "380302d441ea46e334793feb602e788fe93fdaf13356bf8acc4ef8914d8005bb" => :high_sierra
end
head do
url "https://github.com/collectd/collectd.git"
depends_on "autoconf" => :build
depends_on "automake" => :build
end
depends_on "pkg-config" => :build
depends_on "libgcrypt"
depends_on "libtool"
depends_on "net-snmp"
depends_on "riemann-client"
uses_from_macos "bison"
uses_from_macos "flex"
uses_from_macos "perl"
def install
args = %W[
--disable-debug
--disable-dependency-tracking
--prefix=#{prefix}
--localstatedir=#{var}
--disable-java
--enable-write_riemann
]
system "./build.sh" if build.head?
system "./configure", *args
system "make", "install"
end
plist_options manual: "#{HOMEBREW_PREFIX}/sbin/collectd -f -C #{HOMEBREW_PREFIX}/etc/collectd.conf"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{sbin}/collectd</string>
<string>-f</string>
<string>-C</string>
<string>#{etc}/collectd.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>#{var}/log/collectd.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/collectd.log</string>
</dict>
</plist>
EOS
end
test do
log = testpath/"collectd.log"
(testpath/"collectd.conf").write <<~EOS
LoadPlugin logfile
<Plugin logfile>
File "#{log}"
</Plugin>
LoadPlugin memory
EOS
begin
pid = fork { exec sbin/"collectd", "-f", "-C", "collectd.conf" }
sleep 1
assert_predicate log, :exist?, "Failed to create log file"
assert_match "plugin \"memory\" successfully loaded.", log.read
ensure
Process.kill("SIGINT", pid)
Process.wait(pid)
end
end
end