class Nagios < Formula desc "Network monitoring and management system" homepage "https://www.nagios.org/" url "https://downloads.sourceforge.net/project/nagios/nagios-4.x/nagios-4.4.3/nagios-4.4.3.tar.gz" sha256 "bba8f0e8dc8cf72f7a7ae4e8ce9c60f5bd315629421b9ec34818a28b8da49f67" bottle do sha256 "c43d0121dfd38b6ddb681b9246423bd1df13d613ef8127a12cf44b2658e22c4f" => :mojave sha256 "ede951f998ff5b872fe1f7c9ea82c316af1d2ccdd9dc60137c9d1019ded9c079" => :high_sierra sha256 "7ec696beb2bb347fffdb159ecc0ac46e9b71ead5ae560e9d09b9b8d391885150" => :sierra end depends_on "gd" depends_on "libpng" depends_on "nagios-plugins" def nagios_sbin prefix/"cgi-bin" end def nagios_etc etc/"nagios" end def nagios_var var/"lib/nagios" end def htdocs pkgshare/"htdocs" end def user Utils.popen_read("id -un").chomp end def group Utils.popen_read("id -gn").chomp end def install system "./configure", "--disable-debug", "--disable-dependency-tracking", "--prefix=#{prefix}", "--sbindir=#{nagios_sbin}", "--sysconfdir=#{nagios_etc}", "--localstatedir=#{nagios_var}", "--datadir=#{htdocs}", "--libexecdir=#{HOMEBREW_PREFIX}/sbin", # Plugin dir "--with-cgiurl=/nagios/cgi-bin", "--with-htmurl=/nagios", "--with-nagios-user=#{user}", "--with-nagios-group='#{group}'", "--with-command-user=#{user}", "--with-command-group=_www", "--with-httpd-conf=#{share}", "--disable-libtool" system "make", "all" system "make", "install" # Install config system "make", "install-config" system "make", "install-webconf" end def post_install (var/"lib/nagios/rw").mkpath config = etc/"nagios/nagios.cfg" return unless File.exist?(config) return if File.read(config).include?(ENV["USER"]) inreplace config, "brew", ENV["USER"] end def caveats; <<~EOS First we need to create a command dir using superhuman powers: mkdir -p #{nagios_var}/rw sudo chgrp _www #{nagios_var}/rw sudo chmod 2775 #{nagios_var}/rw Then install the Nagios web frontend into Apple's build-in Apache: 1) Turn on Personal Web Sharing. 2) Load the cgi and php modules by patching /etc/apache2/httpd.conf: -#LoadModule php5_module libexec/apache2/libphp5.so +LoadModule php5_module libexec/apache2/libphp5.so -#LoadModule cgi_module libexec/apache2/mod_cgi.so +LoadModule cgi_module libexec/apache2/mod_cgi.so 3) Symlink the sample config and create your web account: sudo ln -sf #{share}/nagios.conf /etc/apache2/other/ htpasswd -cs #{nagios_etc}/htpasswd.users nagiosadmin sudo apachectl restart Log in with your web account (and don't forget to RTFM :-) open http://localhost/nagios EOS end plist_options :startup => true, :manual => "nagios #{HOMEBREW_PREFIX}/etc/nagios/nagios.cfg" def plist; <<~EOS KeepAlive Label #{plist_name} ProgramArguments #{opt_bin}/nagios #{nagios_etc}/nagios.cfg RunAtLoad StandardErrorPath /dev/null StandardOutPath /dev/null EOS end test do assert_match version.to_s, shell_output("#{bin}/nagios --version") end end