# -*- 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$

PortSystem          1.0
PortGroup           perl5 1.0

name                argus-monitor
version             3.7
revision            3
categories          net
license             Artistic
maintainers         nomaintainer
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/
distfiles           argus-${version}.tgz

checksums           rmd160  f8f9eeb6ca5451475594262efcdd571bda931f32 \
                    sha256  796f2e0783d535556f457635561bee17cb82e3805c2f99d024068187f4b6f563

worksrcdir          argus-${version}

perl5.branches      5.24

depends_lib         port:perl${perl5.major} \
                    port:postfix \
                    path:lib/libssl.dylib:openssl \
                    port:freetype \
                    port:gd2 \
                    port:fping \
                    port:db53 \
                    port:p${perl5.major}-dbi \
                    port:p${perl5.major}-berkeleydb \
                    port:p${perl5.major}-socket6 \
                    port:p${perl5.major}-gd \
                    port:p${perl5.major}-time-hires \
                    port:p${perl5.major}-net-ssleay \
                    port:p${perl5.major}-digest-hmac \
                    port:p${perl5.major}-digest-md5 \
                    port:p${perl5.major}-digest-sha1 \
                    port:p${perl5.major}-crypt-des

patchfiles          patch-Makefile.tplt.diff

variant apple_postfix description {Use installed Apple postfix instead of MacPorts version} {
    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.env-append \
                    PERLNAME=perl${perl5.major}

configure.cmd       ./Configure
configure.args      --bin_dir=${prefix}/bin \
                    --sbin_dir=${prefix}/sbin \
                    --lib_dir=${prefix}/lib/argus-monitor \
                    --data_dir=${argus_data_dir} \
                    --www_dir=${argus_htdocs}/ \
                    --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
}

notes "
  *** 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


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

\n"

livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     argus-(\[0-9.\]+).tgz