137 lines
3.8 KiB
Ruby
137 lines
3.8 KiB
Ruby
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.9/nagios-4.4.9.tar.gz"
|
|
sha256 "0e793f3f3654f10961db34950a0c129240cc80222119175552d7e322a9ba4334"
|
|
license "GPL-2.0-only"
|
|
revision 1
|
|
|
|
livecheck do
|
|
url :stable
|
|
regex(%r{url=.*?/nagios[._-]v?(\d+(?:\.\d+)+)\.t}i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 arm64_ventura: "7db0695bbae427961a1822dc5304b4402d904da918c0b098972844ba124ce220"
|
|
sha256 arm64_monterey: "c2bcde07a56fb7115522c01e901137e570829879e2d3dbc248f35348ac7e05d1"
|
|
sha256 arm64_big_sur: "fd35798f4d1300888264d7946ef2007c050c562122d6ee83e04f355455a5d6ee"
|
|
sha256 ventura: "112abc2955c0d88b27d249f08cb6bc1d998815f16389d88c0786f4c20eb1172e"
|
|
sha256 monterey: "ebdd3e0f05804ee1c0b014bfe4da8137926e7c87f560f2adfe11c7a397ebdad4"
|
|
sha256 big_sur: "bb335ee0d104300f3f998a738e7d4ff8c8525df42a7beb3ad6e855a6372e1b49"
|
|
sha256 x86_64_linux: "0ebd2f195770a874487bb13a52be1b8fe18d909ef3cc7e881e0debe267a3ed1a"
|
|
end
|
|
|
|
depends_on "gd"
|
|
depends_on "libpng"
|
|
depends_on "nagios-plugins"
|
|
depends_on "openssl@3"
|
|
|
|
uses_from_macos "unzip"
|
|
|
|
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.safe_popen_read("id", "-un").chomp
|
|
end
|
|
|
|
def group
|
|
Utils.safe_popen_read("id", "-gn").chomp
|
|
end
|
|
|
|
def install
|
|
args = [
|
|
"--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-httpd-conf=#{share}",
|
|
"--with-ssl=#{Formula["openssl@3"].opt_prefix}",
|
|
"--disable-libtool",
|
|
]
|
|
args << "--with-command-group=_www" if OS.mac?
|
|
|
|
system "./configure", *std_configure_args, *args
|
|
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 config.exist?
|
|
return if config.read.include?("nagios_user=#{ENV["USER"]}")
|
|
|
|
inreplace config, /^nagios_user=.*/, "nagios_user=#{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 built-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
|
|
|
|
service do
|
|
run [opt_bin/"nagios", etc/"nagios/nagios.cfg"]
|
|
keep_alive true
|
|
require_root true
|
|
log_path "/dev/null"
|
|
error_log_path "/dev/null"
|
|
end
|
|
|
|
test do
|
|
assert_match version.to_s, shell_output("#{bin}/nagios --version")
|
|
end
|
|
end
|