homebrew-core/Formula/nrpe.rb

92 lines
2.8 KiB
Ruby

class Nrpe < Formula
desc "Nagios remote plugin executor"
homepage "https://www.nagios.org/"
url "https://downloads.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.2.1.tar.gz"
sha256 "8ad2d1846ab9011fdd2942b8fc0c99dfad9a97e57f4a3e6e394a4ead99c0f1f0"
bottle do
cellar :any
sha256 "98eb09fe948052448134155aad5cc16892f9cffeba075cfc9afeb38219047806" => :high_sierra
sha256 "d589496fa3b62e1425f93ebf928234bcfec81cf342837e7b741c9def56ea3e28" => :sierra
sha256 "50cafb3e1545d93f0ad248a2696b83b90fa3fbb6e5afc731d72779ddab0bf6a0" => :el_capitan
end
depends_on "nagios-plugins"
depends_on "openssl"
def install
user = `id -un`.chomp
group = `id -gn`.chomp
system "./configure", "--prefix=#{prefix}",
"--libexecdir=#{HOMEBREW_PREFIX}/sbin",
"--with-piddir=#{var}/run",
"--sysconfdir=#{etc}",
"--with-nrpe-user=#{user}",
"--with-nrpe-group=#{group}",
"--with-nagios-user=#{user}",
"--with-nagios-group=#{group}",
"--with-ssl=#{Formula["openssl"].opt_prefix}",
# Set both or it still looks for /usr/lib
"--with-ssl-lib=#{Formula["openssl"].opt_lib}",
"--enable-ssl",
"--enable-command-args"
inreplace "src/Makefile" do |s|
s.gsub! "$(LIBEXECDIR)", "$(SBINDIR)"
s.gsub! "$(DESTDIR)/usr/local/sbin", "$(SBINDIR)"
end
system "make", "all"
system "make", "install", "install-config"
end
def post_install
(var/"run").mkpath
end
plist_options :manual => "nrpe -n -c #{HOMEBREW_PREFIX}/etc/nrpe.cfg -d"
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>org.nrpe.agent</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/nrpe</string>
<string>-c</string>
<string>#{etc}/nrpe.cfg</string>
<string>-d</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceDescription</key>
<string>Homebrew NRPE Agent</string>
<key>Debug</key>
<true/>
</dict>
</plist>
EOS
end
test do
pid = fork do
exec "#{bin}/nrpe", "-n", "-c", "#{etc}/nrpe.cfg", "-d"
end
sleep 2
begin
output = shell_output("netstat -an")
assert_match /.*\*\.5666.*LISTEN/, output, "nrpe did not start"
pid_nrpe = shell_output("pgrep nrpe").to_i
ensure
Process.kill("SIGINT", pid_nrpe)
Process.kill("SIGINT", pid)
Process.wait(pid)
end
end
end