# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id$

PortSystem          1.0
PortGroup           perl5 1.0

name                smokeping
version             2.6.11
revision            1
license             GPL-2+
categories          net perl
maintainers         nomaintainer
description         A deluxe latency logging and graphing system.
long_description    SmokePing is a deluxe latency measurement tool. \
                    It can measure, store, and display latency, latency \
                    distribution, and packet loss. SmokePing uses RRDtool \
                    to maintain a longterm data-store and to draw pretty \
                    graphs, giving up to the minute information on the \
                    state of each network connection.

platforms           darwin
homepage            http://oss.oetiker.ch/smokeping/
master_sites        http://oss.oetiker.ch/smokeping/pub/

checksums           rmd160  80722b7b30fa6ce589cc330fe8c657fc85cebc69 \
                    sha256  f2b3c386e95a74af2b1e7aec6410d0a58852339f00e9963f3c770cfd85ba30dd

patchfiles          patch-etc-config.dist.diff \
                    patch-bin-smokeping.diff \
                    patch-bin-tSmoke.diff \
                    patch-bin-smokeinfo.diff \
                    patch-bin-smokeping_cgi.diff

perl5.branches      5.24

depends_lib-append  port:perl${perl5.major} \
                    port:p${perl5.major}-cgi \
                    port:p${perl5.major}-cgi-fast \
                    port:p${perl5.major}-fcgi \
                    port:p${perl5.major}-libwww-perl \
                    port:p${perl5.major}-socket6 \
                    port:p${perl5.major}-net-snmp \
                    port:p${perl5.major}-net-telnet \
                    port:p${perl5.major}-net-dns \
                    port:p${perl5.major}-net-openssh \
                    port:p${perl5.major}-net-radius \
                    port:p${perl5.major}-perl-ldap \
                    port:p${perl5.major}-io-socket-ssl \
                    port:p${perl5.major}-io-tty \
                    port:p${perl5.major}-pathtools \
                    port:p${perl5.major}-snmp_session \
                    port:p${perl5.major}-config-grammar \
                    port:mod_fastcgi \
                    port:apache2 \
                    port:rrdtool \
                    port:fping \
                    port:curl

set smokeroot ${prefix}/lib/smokeping
set smokedata ${prefix}/var/smokeping
set smokeetc ${prefix}/etc
set macports_apache_docroot ${prefix}/apache2/htdocs

startupitem.create  yes
startupitem.name    smokeping
startupitem.executable \
                    ${prefix}/bin/smokeping --nodaemon


post-patch {
    reinplace "s|__PREFIX__|${prefix}|g" \
        ${worksrcpath}/bin/smokeping \
        ${worksrcpath}/bin/tSmoke \
        ${worksrcpath}/bin/smokeinfo \
        ${worksrcpath}/bin/smokeping_cgi \
        ${worksrcpath}/etc/config.dist

    reinplace "s|__PERL5__ARCHLIB__|${perl5.archlib}|g" \
        ${worksrcpath}/bin/smokeping \
        ${worksrcpath}/bin/tSmoke \
        ${worksrcpath}/bin/smokeinfo \
        ${worksrcpath}/bin/smokeping_cgi

    reinplace "s|/usr/bin/|${prefix}/bin/|g" \
        ${worksrcpath}/lib/Smokeping.pm \
        ${worksrcpath}/lib/Smokeping/Examples.pm \
        ${worksrcpath}/lib/Smokeping/probes/Curl.pm \
        ${worksrcpath}/lib/Smokeping/probes/RemoteFPing.pm \
        ${worksrcpath}/lib/Smokeping/probes/SSH.pm \
        ${worksrcpath}/lib/Smokeping/probes/FPing6.pm \
        ${worksrcpath}/lib/Smokeping/probes/EchoPing.pm \
        ${worksrcpath}/lib/Smokeping/probes/FPing.pm

    reinplace "s|/usr/share/smokeping/etc|${smokeetc}|g" \
        ${worksrcpath}/lib/Smokeping/probes/passwordchecker.pm
}

configure.perl      ${perl5.bin}
# configure.env-append PERL5LIB=${perl5.lib}

# TODO: smokeping violates the layout of the ports-filesystems!
# configure.args-append --with-htdocs-dir=${prefix}/apache2/htdocs/smokeping

post-destroot {

# Create and retain the data directory

    xinstall -m 755 -d ${destroot}${smokedata}/log
    destroot.keepdirs ${destroot}${smokedata}/log
}

notes \
"  #### To complete the Smokeping installation ####

1) Enable mod_fastcgi (installed as a dependency of Smokeping) for MacPorts Apache 2.

   -Rdd the line below to ${prefix}/apache2/conf/httpd.conf.

	LoadModule fastcgi_module modules/mod_fastcgi.so


2)  Changes to httpd.conf for Smokeping.

   -Uncomment this line to enable the CGI script handler.

	AddHandler cgi-script .cgi

   -Add a directive for Smokeping's data directory and add
    smokeping.cgi to DirectoryIndex for a simple /smokeping url.

	Alias /smokeping \"${prefix}/var/smokeping\"
	<Directory \"${prefix}/var/smokeping\">
	    Allow from all
	    Options ExecCGI
	</Directory>

	<IfModule dir_module>
	    DirectoryIndex index.html smokeping.cgi
	</IfModule>


3) Set Smokeping data directory permissions to the Apache user and group set
   in httpd.conf.  The default Apache user and group for OS X is www.

	sudo chown -R <smokeping-user>:<smokeping-group> ${smokedata}/


4) Setup Smokeping logging.

   -Add this statement to /etc/syslog.conf.

   local1.*	${smokedata}/log/smokeping.log

   -Create a logfile to receive the log messages.

	cd ${smokedata}/log
	sudo touch smokeping.log
	sudo chmod 600 smokeping.log
	sudo chown root:admin smokeping.log

   -Then restart the syslog facility.

	sudo kill -HUP `cat /var/run/syslog.pid`


5) Rename and edit the ${smokeetc}/config sample files, then test your config file.

   -Remove the .dist extension from all files; do not change the filenames.

        cd ${smokeetc}
        sudo mv config.dist config

   -Set the DNS names for the Smokeping config file url's \"imageurl\" and \"cgiurl\".
    But you should leave all file paths alone -they are set by MacPorts.

	imgurl   = http://myhost.mycompany.com/smokeping
	cgiurl   = http://myhost.mycompany.com/smokeping/smokeping.cgi

   -Customize variables.

     * General * - owner, contact, and mailhost
     * Alerts  * - to, from addresses

   -Then clear the examples \(they have a leading '+'\) in the *** Targets ***
    section and set your own.

        + My Web Server
           menu = MyWebServer
           title = My Web Server
           host = mywebserver.mydomain.com
           alerts = bigloss,someloss,startloss

    -See sample configurations and examples in ${prefix}/share/doc/smokeping/.

    -Perform a config file test from a terminal window and correct any errors that
     are reported.

	smokeping --check


6) Start Smokeping and verify it is running.  (Give it a minute to start)

	sudo launchctl load -w /Library/LaunchDaemons/org.macports.smokeping.plist
	ps -ax |grep smoke

 1713  Ss 0:00.16 ${prefix}/bin/smokeping \[FPing\]
 1753  Ss 0:00.18 ${prefix}/bin/speedy_backend -w ${prefix}/apache2/htdocs/smokeping/smokeping.cgi
 1754  S  0:01.56 ${prefix}/bin/speedy_backend -w ${prefix}/apache2/htdocs/smokeping/smokeping.cgi


7) Check the Smokeping graphs with a web browser.

   Go to http://localhost/smokeping


8) Add or remove targets from Smokeping.

   After adding or removing targets from ${smokeetc}/config, you must reload
   Smokeping from a terminal window.

	sudo smokeping --reload"