--- _orig/net/nagios/Portfile	2013-08-15 09:30:15.000000000 -0400
+++ net/nagios/Portfile	2014-07-26 00:11:19.000000000 -0400
@@ -1,93 +1,105 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
 # $Id: Portfile 109427 2013-08-15 13:11:47Z ryandesign@macports.org $
 
-PortSystem	1.0
+PortSystem         1.0
 
-name			nagios
-version			3.5.0
-revision		2
-categories		net
-license			GPL-2
-maintainers		markd openmaintainer
-platforms		darwin
-
-description		Nagios is a host and service monitoring program
-
-long_description	A network service and host monitor that can notify you \
-			when servers go down by monitoring for external services \
-			such as HTTP, FTP, SMTP, SNMP, as well as internal host \
-			checks for things such as CPU and disk usage and many \
-			other things.
-
-homepage		http://nagios.org
-
-livecheck.regex		nagios-(\[0-9.\]+)${extract.suffix}
-
-master_sites		sourceforge:project/nagios/nagios-3.x/nagios-${version}
-checksums		rmd160 d75a764486fd3dc0462fb49924698754852d39be \
-			sha256 469381b2954392689c85d3db733e8da4bd43b806b3d661d1a7fbd52dacc084db
-
-worksrcdir              ${name}
-
-depends_build		port:gd2
-depends_lib             port:openssl \
-			port:nagios-plugins
-
-set sysconfdir		${prefix}/etc/${name}
-destroot.destdir        prefix=${prefix} DESTDIR=${destroot}
-
-destroot.target		install install-config install-commandmode install-init
-
-configure.args         	--with-cgiurl=/nagios/cgi-bin \
-			--with-htmurl=/nagios \
-			--with-nagios-user=nagios \
-			--with-nagios-grp=nagios \
-			--with-command-grp=nagios \
-			--with-gd-lib=${prefix}/lib \
-			--with-gd-inc=${prefix}/include \
-			--sbindir=${prefix}/sbin/nagios \
-			--libexecdir=${prefix}/libexec/nagios \
-			--datadir=${prefix}/share/nagios \
-			--with-lockfile=${prefix}/var/nagios/nagios.lock \
-			--with-init-dir=${prefix}/var/nagios \
-			--sysconfdir=${sysconfdir} \
-			--localstatedir=${prefix}/var/nagios \
-			--with-httpd-conf=/etc/apache2/httpd.conf
+name               nagios
+version            4.0.7
+categories         net
+license            GPL-2
+maintainers        markd openmaintainer
+platforms          darwin
+
+description         Nagios is a host and service monitoring program
+
+long_description    A network service and host monitor that can notify you \
+                    when servers go down by monitoring for external services \
+                    such as HTTP, FTP, SMTP, SNMP, as well as internal host \
+                    checks for things such as CPU and disk usage and many \
+                    other things.
+
+homepage            http://nagios.org
+master_sites        sourceforge:project/nagios/nagios-4.x/nagios-${version}
+checksums           rmd160  deb4278a478e8d58e38bc84a3691945a52bc89af \
+                    sha256  ef1de1d106f6572a88547f3ed37a744c5d4fa778859ce44fc9043da597c50799
+
+livecheck.regex     nagios-(\[0-9.\]+)${extract.suffix}
+
+depends_build       port:gd2
+depends_lib         port:openssl port:nagios-plugins
+
+set sysconfdir      ${prefix}/etc/${name}
+destroot.destdir    prefix=${prefix} DESTDIR=${destroot}
+
+destroot.target     install install-config install-commandmode install-init
+destroot.asroot     yes
+install.asroot      yes
+
+## iobroker: http://tracker.nagios.org/view.php?id=484
+#            --with-iobroker=select => not compiling (default: poll)
+configure.args      --with-cgiurl=/nagios/cgi-bin \
+                    --with-htmurl=/nagios \
+                    --with-nagios-user=nagios \
+                    --with-nagios-grp=nagios \
+                    --with-command-grp=nagios \
+                    --with-gd-lib=${prefix}/lib \
+                    --with-gd-inc=${prefix}/include \
+                    --sbindir=${prefix}/sbin/nagios \
+                    --libexecdir=${prefix}/libexec/nagios \
+                    --datadir=${prefix}/share/nagios \
+                    --with-lockfile=${prefix}/var/nagios/nagios.lock \
+                    --with-init-dir=${prefix}/var/nagios \
+                    --sysconfdir=${sysconfdir} \
+                    --localstatedir=${prefix}/var/nagios \
+                    --with-httpd-conf=/etc/apache2/httpd.conf
 
 platform darwin 8 {
-	configure.args-delete --with-httpd-conf=/etc/apache2/httpd.conf
-	configure.args-append --with-httpd-conf=/etc/httpd/httpd.conf
+    configure.args-delete --with-httpd-conf=/etc/apache2/httpd.conf
+    configure.args-append --with-httpd-conf=/etc/httpd/httpd.conf
 }
 
-startupitem.create      yes
-startupitem.start       "${prefix}/var/nagios/nagios.init start"
-startupitem.stop        "${prefix}/var/nagios/nagios.init stop"
+startupitem.create  yes
+## Note: why using a linux chkconfig file???
+#startupitem.start  "${prefix}/var/nagios/nagios.init start"
+#startupitem.stop   "${prefix}/var/nagios/nagios.init stop"
+startupitem.executable ${prefix}/bin/nagios ${prefix}/etc/nagios/nagios.cfg
+startupitem.pidfile ${prefix}/var/nagios/nagios.lock
 
 post-patch {
         reinplace "s|INIT_OPTS=-o root -g root|INIT_OPTS=-o nagios -g nagios|g" \
                 "${worksrcpath}/Makefile.in"
 
-	reinplace "s|daemon-init \$(DESTDIR)\$(INIT_DIR)/nagios|daemon-init \$(DESTDIR)\$(INIT_DIR)/nagios.init|g" \
-		"${worksrcpath}/Makefile.in"
+    reinplace "s|daemon-init \$(DESTDIR)\$(INIT_DIR)/nagios|daemon-init \$(DESTDIR)\$(INIT_DIR)/nagios.init|g" \
+        "${worksrcpath}/Makefile.in"
 
-	reinplace "s|NagiosLockDir=/var/lock/subsys|NagiosLockDir=${prefix}/var/nagios|g" \
-		${worksrcpath}/daemon-init.in
-	reinplace "s|su -|su -m|g" \
-		${worksrcpath}/daemon-init.in
+    reinplace "s|NagiosLockDir=/var/lock/subsys|NagiosLockDir=${prefix}/var/nagios|g" \
+        ${worksrcpath}/daemon-init.in
+    reinplace "s|su -|su -m|g" \
+        ${worksrcpath}/daemon-init.in
 }
 
 add_users nagios group=nagios
 
 post-destroot {
 # Keep the empty command file directory created by 'make install-commandmode'
-        destroot.keepdirs ${destroot}${prefix}/var/nagios/rw
+        destroot.keepdirs ${destroot}${prefix}/var/nagios/rw \
+            ${destroot}${prefix}/var/${name}/spool/checkresults
 
 # Nagios sample files no longer install with -sample suffixes, so do this manually for safety
-	foreach cfgfile [glob ${destroot}${sysconfdir}/*.cfg] {
-		file rename ${cfgfile} ${cfgfile}-sample
-	}
-	foreach cfgfile [glob ${destroot}${sysconfdir}/objects/*.cfg] {
-		file rename ${cfgfile} ${cfgfile}-sample
-	}
+    foreach cfgfile [glob ${destroot}${sysconfdir}/*.cfg] {
+        file rename ${cfgfile} ${cfgfile}-sample
+    }
+    foreach cfgfile [glob ${destroot}${sysconfdir}/objects/*.cfg] {
+        file rename ${cfgfile} ${cfgfile}-sample
+    }
+
+    xinstall -d ${destroot}${prefix}/share/examples/${name}/
+    copy ${filespath}/apache-nagios.conf ${destroot}${prefix}/share/examples/${name}/
+    copy ${filespath}/nginx-nagios.conf ${destroot}${prefix}/share/examples/${name}/
+    reinplace "s|%%PREFIX%%|${prefix}|g" \
+        ${destroot}${prefix}/share/examples/${name}/apache-nagios.conf \
+        ${destroot}${prefix}/share/examples/${name}/nginx-nagios.conf
+    xinstall -d ${destroot}${prefix}/var/${name}/spool/checkresults
 }
 
 
@@ -100,43 +112,24 @@
 ************************************************************
 
 IMPORTANT: A user and group called 'nagios' has been created and you must run\
-	   nagios as that user.
+       nagios as that user.
 
 
-
-1) Setup Apache's httpd.conf file for Nagios (restart Apache when done)
+1) Setup your webserver
+  a) Apache's httpd.conf file for Nagios (restart Apache when done)
+     Example configuration in ${prefix}/share/examples/${name}/apache-nagios.conf
 
    Insert the \"Nagios stuff\" text block somewhere *above* your Apache cgi-bin\
    ScriptAlias statement:
 
-	ScriptAlias /cgi-bin/ \"/Library/WebServer/CGI-Executables/\"
-
-#
-# Nagios stuff
-
-ScriptAlias /nagios/cgi-bin/ \"${prefix}/sbin/nagios/\"
-<Directory \"${prefix}/sbin/nagios\">
- AllowOverride None
-    Options ExecCGI
-    Order allow,deny
-    Allow from all
-    AuthName \"Nagios Access\"
-    AuthType Basic
-    AuthUserFile ${prefix}/etc/nagios/htpasswd.users
-    require valid-user
-</Directory>
-
-Alias /nagios \"${prefix}/share/nagios\"
-<Directory \"${prefix}/share/nagios\">
-    Options None
-    AllowOverride AuthConfig
-    Order allow,deny
-    Allow from all
-</Directory>
+    ScriptAlias /cgi-bin/ \"/Library/WebServer/CGI-Executables/\"
 
-# End Nagios stuff
-#
+   (is it only relevant to Apple Apache or also macports?)
 
+  b) Nginx w php*-fpm and fcgiwrap
+     Example configuration in ${prefix}/share/examples/${name}/nginx-nagios.conf
+     Configured for localhost:8081
+         http://localhost:8081/
 
 2) Configure the Nagios sample files in ${prefix}/etc/nagios.
 
@@ -152,7 +145,8 @@
    for i in *cfg-sample; do mv \$i `echo \$i | sed -e s/cfg-sample/cfg/`; done;
    exit
 
-c) Configure the default commands.cfg file to your requirements.  Then test\
+c) Configure at least the default commands.cfg and contacts.cfg  files to your \
+   requirements.  Then test\
    the Nagios configuration with this command until you get no errors:
 
    sudo nagios -v ${prefix}/etc/nagios/nagios.cfg
@@ -160,6 +154,7 @@
 
 3) Set user 'nagiosadmin' as a \"superuser\" to browse all hosts/services in
    ${prefix}/etc/nagios/cgi.cfg
+   (default configuration)
 
    authorized_for_system_information= nagiosadmin
    authorized_for_configuration_information= nagiosadmin
@@ -173,7 +168,7 @@
 4) Create a 'nagiosadmin' Apache user/password to correspond with the Nagios Apache\
    user created above
 
-	htpasswd -c ${prefix}/etc/nagios/htpasswd.users nagiosadmin
+    htpasswd -c ${prefix}/etc/nagios/htpasswd.users nagiosadmin
 
    Create other users as desired, omit '-c' since it creates the password file.  Make\
    additional users login names match Nagios contact names to restrict web viewing to your\
@@ -183,24 +178,59 @@
 5) Set Nagios to start at system boot, and start Nagios
 
    Run launchctl so Nagios will start at system boot
-	sudo launchctl load -w /Library/LaunchDaemons/org.macports.nagios.plist
+    sudo launchctl load -w /Library/LaunchDaemons/org.macports.nagios.plist
 
    You may now start Nagios manually with this command (or a reboot):
-	sudo ${prefix}/var/nagios/nagios.init start
+    sudo ${prefix}/var/nagios/nagios.init start
 
 
 6) You may now login as 'nagiosadmin' to the Nagios web interface at http://localhost/nagios
 
+7) You can monitor nagios itself with the following commands
+       # ${prefix}/libexec/nagios/check_nagios -t 20 -e 5 -F ${prefix}/var/nagios/nagios.log -C nagios    (NOK: Abort trap: 6)
+       # nagiostats
+   As input for mrtg
+       # nagiostats --mrtg
+   Non-official input to cacti
+       http://forums.cacti.net/viewtopic.php?f=12&t=33806&p=221089
+       http://forums.cacti.net/viewtopic.php?f=12&t=34834
+       http://forums.cacti.net/viewtopic.php?f=12&t=17729
+
 
 NOTE: The SMTP server Postfix is required to enable Nagios email notifications
 
 
 File Locations:
 
-	Configuration files: ${prefix}/etc/nagios
-	Nagios plugins: ${prefix}/libexec/nagios
-	Lock file:  ${prefix}/var/nagios/nagios.lock
- 	Init file:  ${prefix}/var/nagios/nagios.init
-	HTML URL:  http://localhost/nagios/
-	CGI URL:  http://localhost/nagios/cgi-bin/
+    Configuration files: ${prefix}/etc/nagios
+    Nagios plugins: ${prefix}/libexec/nagios
+    Lock file:  ${prefix}/var/nagios/nagios.lock
+     Init file:  ${prefix}/var/nagios/nagios.init
+    HTML URL:  http://localhost/nagios/
+    CGI URL:  http://localhost/nagios/cgi-bin/
+
 "
+
+subport ${name}3 {
+    version             3.5.1
+    master_sites        sourceforge:project/nagios/nagios-3.x/nagios-${version}
+    checksums           rmd160  0ce5693a745f617c9fbf627f18af27b793de884d \
+                        sha256  ca9dd68234fa090b3c35ecc8767b2c9eb743977eaf32612fa9b8341cc00a0f99
+    worksrcdir          ${name}
+
+    conflicts ${name}
+
+}
+
+## FIXME! universal: lot of "Undefined symbols for architecture x86_64:"
+variant universal {}
+#build.args          CFLAGS="${configure.cflags} [get_canonical_archflags cc]"
+configure.cflags-append          "${configure.cflags} [get_canonical_archflags cc]"
+
+variant nagvis description { nagvis visualization addon } {
+    set n_version       1.7
+    set n_version_minor 10
+    master_sites        sourceforge:projects/nagvis/files/NagVis ${n_version}/:nagvis
+    distfiles           nagvis-${n_version}.${n_version_minor}${extract.suffix}:nagvis
+    ## http://docs.nagvis.org/1.7/en_US/index.html
+}
