# $Id: Portfile 91655 2012-04-07 07:46:17Z jmr@macports.org $
PortSystem	1.0

name			argus-monitor
version			3.5
revision        2
categories		net
maintainers		markd
description		The All Seeing System and Network Monitoring Software
long_description	${description}
homepage		http://argus.tcp4me.com/
platforms		darwin
master_sites		http://www.tcp4me.com/code/argus-archive/
checksums		md5 7a946b17a61edeb1b455f2ab45acf77d
distfiles		argus-${version}.tgz
worksrcdir		argus-${version}

depends_lib		port:perl5.12 \
			port:postfix \
			port:openssl \
			port:freetype \
			port:gd2 \
			port:fping \
			port:db44 \
			port:p5.12-dbi \
			port:p5.12-berkeleydb \
			port:p5.12-socket6 \
			port:p5.12-gd \
			port:p5.12-time-hires \
			port:p5.12-net-ssleay \
			port:p5.12-digest-hmac \
			port:p5.12-digest-md5 \
			port:p5.12-digest-sha1 \
			port:p5.12-crypt-des

patchfiles		patch-Makefile.tplt

variant apple_postfix {
	depends_lib-delete	port:postfix
}

startupitem.create	yes
startupitem.name	argusd  
startupitem.executable	"${prefix}/sbin/argusd"

# Set the --data_dir configure argument and give me a pointer to it for later reference.
set argus_data_dir ${prefix}/var/argus-monitor

# Set the Argus htdocs directory.
set argus_htdocs ${prefix}/share/${name}/htdocs

configure.cmd		./Configure
configure.args		--bin_dir=${prefix}/bin \
			--sbin_dir=${prefix}/sbin \
			--lib_dir=${prefix}/lib/argus-monitor \
			--data_dir=${argus_data_dir} \
			--cgi_dir=${argus_htdocs}/cgi-bin

post-patch {
if { [variant_isset apple_postfix] } {
	reinplace "s|/lib/sendmail|/usr/sbin/sendmail|g" \
		${worksrcpath}/examples/config
} else {
	reinplace "s|/lib/sendmail|${prefix}/sbin/sendmail|g" \
		${worksrcpath}/examples/config
}
}

post-destroot {
	xinstall -m 755 -d ${destroot}${argus_htdocs}/sound
	xinstall -m 755 -d ${destroot}${argus_htdocs}/img
	xinstall -m 755 ${worksrcpath}/misc/whoopwhoop.wav ${destroot}${argus_htdocs}/sound	
	eval xinstall -m 640 [glob ${worksrcpath}/misc/*.gif] ${destroot}${argus_htdocs}/img
	xinstall -m 644 -W ${worksrcpath}/misc argus.css argus.js \
		${destroot}${argus_htdocs}

	file copy ${worksrcpath}/examples ${destroot}${prefix}/share/${name}

	system "chown -R www:www ${destroot}${argus_data_dir}"
	system "chown -R www:www ${destroot}${argus_htdocs}"

	destroot.keepdirs \
		${destroot}${argus_data_dir}/gdata \
		${destroot}${argus_data_dir}/perl \
		${destroot}${argus_data_dir}/stats \
		${destroot}${argus_data_dir}/html \
		${destroot}${argus_data_dir}/notify
}

post-install {
ui_msg "\n  *** To complete the Argus install ***

1) Modify the httpd.conf for Argus
----------------------------------------------
-Uncomment the line:
        AddHandler cgi-script .cgi

-Add a directive for the Argus data directory           
 
        ScriptAlias /argus \"${argus_htdocs}/cgi-bin/arguscgi\"
        <Directory \"${argus_htdocs}/cgi-bin\">
            Allow from all
            Options ExecCGI
        </Directory>


2) Setup postfix so Argus can send mail via the command-line
----------------------------------------------
	cd ${prefix}/etc/postfix
	sudo cp master.cf.sample master.cf
	sudo cp main.cf.sample main.cf
	sudo cp aliases.sample aliases

Redirect OS X's sendmail executable to the one from MacPorts.
	sudo mv /usr/sbin/sendmail /usr/sbin/sendmail.old
	sudo ln -s ${prefix}/sbin/sendmail /usr/sbin/sendmail

Startup postfix and set it to run at sytem boot.
	sudo launchctl load -w /Library/LaunchDaemons/org.macports.postfix.plist

Test postfix by sending a test email from a terminal window.
	mail joe@mycompany.com

NOTE: Make sure the SMTP server of the receiving domain will relay
      mail from your Argus workstation.


2) Setup the Argus config files
----------------------------------------------
-Remove the suffix \".example\" from the files config and user in
 ${argus_data_dir} and customize them.  Also see ${prefix}/share/${name}/examples.


3) Make the Argus files owned by the Apache user/group (default is \"www\")
----------------------------------------------
-Execute this terminal command:
	sudo chown -R <apache-user>:<apache-group> ${prefix}/share/${name}/
	sudo chown -R <apache-user>:<apache-group> ${argus_data_dir}/


4) Rename config.example and user.example to config and user and customize them.
----------------------------------------------
For full config file information, see the developer documentation at
http://argus.tcp4me.com/docs.html. But in a nutshell, it goes like this ....

-The Argus config file is hierarchical; parameters that can be specified at
 an upper level are inherited by objects below when not explicitly specified.

So you may use service groups:

	Group \"WebServers\" {
		frequency:	5min
		retries:	5
		retrydelay:	10min
		notify: mail:netadmins@mycompany.com

		Host \"webserver.mycompany.com\" {
			Service TCP/HTTP
			Service TCP/HTTPS
			Service Ping
		}

		Host \"webmail.mycompany.com\" {
			Service TCP/HTTP
			Service TCP/HTTPS
			Service TCP/POP
			Service TCP/POPS
			Service TCP/IMAP
			Service TCP/IMAPS
			Service TCP/SMTP
			Service TCP/SMTPS
			Service Ping
			Service UDP {
				port:   501
			}

		}

		Host \"dns1.mycompany.com\" {
			Service UDP/DNS

		}
	}

-Or you may use the \"shorthand\" notation and fully specify the characteristics
 of individual hosts completely.

	Host \"www.example.com\" {
		Service TCP/HTTP
		Service TCP/HTTPS
		Service Ping
		Service TCP {
			port: 12345
			info: YoyoDyne Application Server
		}
	}

NOTE: Unlike C or Perl, you cannot place the opening \{ on a different line,
      and the closing \} must be on a line by itself (with optional whitespace).

-Rename config.example to config and customize it with your login passwords.


5) Start argusd.
----------------------------------------------

-Start argusd in the foreground to test it:
	sudo argusd -fd  (foreground & debug)

-When you have argusd starting without errors, shutdown the foreground
 processs using argusctl (or Control-C) and use launchctl to start argusd
 in the background and set it to run at boot:

	argusctl shutdown
	sudo launchctl load -w /Library/LaunchDaemons/org.macports.argusd.plist 

-NOTE: Config file changes are detected automatically by Argus within a few minutes,
        but the impatient may use argusctl:

	argusctl hup 


5) Login to the Argus web interface to monitor your services.
----------------------------------------------
Login at http://localhost/argus

\n"
}
