# $Id: Portfile,v 1.2 2006/06/04 02:50:50 markd Exp $
PortSystem      1.0

name                    netmrg
version                 0.19
categories              net
maintainers             markd@opendarwin.org
description             An RRDtool frontend for network monitoring, reporting, and graphing \
			that generates day/week/month MRTG style graphs.
long_description        ${description}
homepage                http://www.netmrg.net/
platforms               darwin
master_sites            http://www.netmrg.net/download/devel/
checksums               md5 a380390425f8f97cadaee3809042ca51

depends_lib             port:mysql5 \
			port:rrdtool \
			port:libxml2

configure.args		--with-mysql-lib-dir=${prefix}/lib/mysql5/mysql \
			--with-mysql-include-dir=${prefix}/include/mysql5/ \
			--with-snmp-lib-dir=/usr/lib \
			--with-rrdtool=${prefix}/bin

pre-fetch {
        ui_msg "\n

                   **************************************************
                   **** If MySQL is being installed during the   ****
		   **** NetMRG install (first-time MySQL        ****
		   **** install, is recommended that you pre-    ****
		   ****	install MySQL5 with the +server variant  ****
		   **** so MySQL will start system boot.  To do  ****
		   **** so:					 ****

                      1) Cancel this install now with Cntrl-C.
                      2) Type \"port install mysql5 +server\"
                      3) Re-run the NetMRG port install
                   ************************************************
                \n"
}

post-extract {
	reinplace "s|libnetsnmp.a|libnetsnmp.dylib|g" \
		${worksrcpath}/configure

	reinplace "s|<socket></socket>|<socket>${prefix}/var/run/mysql5/mysqld.sock</socket>|g" \
		${worksrcpath}/etc/netmrg.xml.in

	reinplace "s|<version>1.0</version>|<version>1.2</version>|g" \
                ${worksrcpath}/etc/netmrg.xml.in
}

post-destroot {
	xinstall -m 755 -d ${destroot}${prefix}/var/log/netmrg
	destroot.keepdirs ${destroot}${prefix}/var/log/netmrg
	system "chown -R www:www ${destroot}${prefix}/var/lib/netmrg/rrd/"
	system "chown -R www:www ${destroot}${prefix}/var/log/netmrg"
}

post-activate {

ui_msg "\n

	******************************************************************  
	****             Complete the NetMRG Installation             ****
	******************************************************************

Full information at http://wiki.netmrg.net/wiki/Users_Manual.

1) Setup MySQL

   Configure MySQL:
        sudo -u mysql ${prefix}/lib/mysql5/bin/mysql_install_db

   Start MySQL:
        sudo ${prefix}/share/mysql5/mysql/mysql.server start

   Set MySQL to run at system boot
        sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.mysql5.plist

NOTE: MySQL must have been installed with the +server variant in order to
      use launchctl to run MySQL at system boot.

   Set the root MySQL password:
   	Follow the instructions that were given after you executed 'mysql_install_db' above.


2) Install PHP 4 or 5 (not covered)        

   Set mysql.default_socket path to ${prefix}/var/run/mysql5/mysqld.sock in the PHP file:

        ./phpx/lib/php.ini (in /usr/local, ${prefix}, or /Library depending on PHP package)


3) Setup the NetMRG database
	mysql5 -u root -p
	mysql> create database netmrg;
	mysql> exit

   Import the netmrg database
	cd ${prefix}/share/netmrg/db
	cat netmrg.mysql | mysql5 -u root -p netmrg

   Verify NetMRG DB:
        mysql5 -u root -p
        mysql> use netmrg;
        mysql> show tables;
        mysql> exit;

   Set permissions on the NetMRG database
	grant all on netmrg.* to netmrg@localhost identified by 'mynetmrg-password';


4) Set a symlink from the NetMRG web frontend to your Apache root directory
	sudo ln -s ${prefix}/var/www/netmrg/webfiles /<Apache Doc Root>/netmrg


5) Edit the NetMRG preferences file ${prefix}/etc/netmrg.xml

   MySQL preferences:
		<user>netmrg</user>				(MySQL user)
                <password><my-netmrg-passsword></password>	(MySQL password)
                <db>netmrg</db>					(MySQL database name)

   Other preferences if desired: website, polling, and logging 

6) Test polling and set polling in cron

	sudo -u www ${prefix}/bin/netmrg-gatherer -a (-a is for verbose output)

   NOTE: If you do not run netmrg as user www, then set permissions to that user:
	sudo chown -R netmrg-user:netmrg-user ${prefix}/var/log/netmrg/
	sudo chown -R netmrg-user:netmrg-user ${prefix}/var/lib/netmrg/rrd

   Once you are satisfied polling is operating correctly, set the netmrg user's
   crontab to poll every 5 minutes.

        sudo -u <netmrg-user> crontab -e

        */5 * * * *  ${prefix}/bin/netmrg-gatherer


7) Point your web browser to http:/loalhost/netmrg and login to NetMRG

	The default user/pass is admin/nimda



	******************************************************************
	**** 	    Graphing an Ethernet Switch - Quickstart          ****
	******************************************************************


1) Define a custom graph template for your Ethernet switches

Click Template Graphs and click the 'Duplicate' icon beside item
'Linux Box - LAN Traffic'.  Now edit the duplicate template and change
the name and title:

Name:           Cisco - LAN Traffic
Title:          %dev_name% - %ifDescr%%n - %ifAlias% (ifAlias is optional)
Comment:        Interface: %ifDescr% - %ifAlias% (ifAlias is optional)
Vert label:     bytes / sec

Click 'Save Changes'.


2) Monitor an Ethernet switch via SNMP

Click Admin and add a Template Group called 'Cisco Switches'

Add an Ethernet switch called 'Switch-A' under Monitored Devices for the
Cisco Switches group, set the IP or hostname, SNMP version, and community string.
Click Save.

Click the Recache Interfaces' icon next to the new item Switch-A.  NetMRG will
draw a table of Switch-A's interfaces including:

-Interface index number
-Status (Up/Up, Up/Down, etc)
-Name (Fa0/1, Gig3/12, etc)
-Alias (Cisco IOS user customizable description)
-IP address (if any)
-Mac Address

Select the 'Cisco - LAN Traffic' template in the lower right corner of the window,
click the checkbox beside each interface you want to graph, and then click the
'Monitor/Graph All Checked' link.

Click Admin -> Cisco Switches -> Switch A and notice that the interface(s)
you selected are now listed as sub-devices of Switch-A.


3) View your graphs

Click Reporting -> Tree -> Cisco Switches -> Switch-A.  The orange graph icon links
will display your graphs.

'Device' graph links display graphs for all interfaces on a page.
'Sub-Device' graph links display graphs for a single sub-device interface.
\n"
}
