class Nrpe < Formula desc "Nagios remote plugin executor" homepage "https://www.nagios.org/" url "https://downloads.sourceforge.net/project/nagios/nrpe-4.x/nrpe-4.0.0.tar.gz" sha256 "a3d0a7ac5385421dfcc29afce7eeade13ca10d8d9115ca5c2962b72946c88a1e" bottle do cellar :any sha256 "eb75e8cbf609bf4a2d514fc03341bb33144d7cde87fcc174abc160ccd15f8683" => :catalina sha256 "34c54f47ac9a79e2e698df0cf693e3b99e3aedbfb193ab626febb8eb21a1e30f" => :mojave sha256 "169a4d77296cd0abd2b048faa223eab53fd3cbd44911c3a394dc28103d1ab71a" => :high_sierra end depends_on "nagios-plugins" depends_on "openssl@1.1" 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@1.1"].opt_prefix}", # Set both or it still looks for /usr/lib "--with-ssl-lib=#{Formula["openssl@1.1"].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 Label org.nrpe.agent ProgramArguments #{opt_bin}/nrpe -c #{etc}/nrpe.cfg -d RunAtLoad ServiceDescription Homebrew NRPE Agent Debug 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