# $Id: Portfile 91783 2012-04-10 14:50:05Z snc@macports.org $

PortSystem	1.0

name			cacti
version			0.8.7i
categories		net
maintainers		markd openmaintainer
platforms		darwin

description		Cacti is a complete RRDtool network graphing solution.

long_description	Cacti is a complete network graphing solution designed \
                        to harness the power of RRDtool's data storage and \
                        graphing functions.

homepage		http://www.cacti.net
master_sites		http://www.cacti.net/downloads

distfiles		${distname}${extract.suffix}
checksums		${distname}${extract.suffix} md5 07fd1da6b0ac4912410df3aa4e451a4b

depends_lib		path:bin/mysql_config5:mysql5 \
			port:rrdtool

use_configure   no
build {}

set cactiversion 0.8.7i
set pluginversion 3.1
set cactidir ${prefix}/share/cacti

variant plugins description {The Plugin Architecture for Cacti} {
	distfiles-append cacti-${cactiversion}-PIA-${pluginversion}${extract.suffix}
	checksums-append cacti-${version}-PIA-${pluginversion}${extract.suffix} md5 669770a7837986971a279104dbb50b75
}

destroot {
# Copy Cacti files
	file mkdir ${destroot}${cactidir}
	system "cp -R ${worksrcpath}/* ${destroot}${cactidir}"

# Copy PA architecture files
	if { [variant_isset plugins] } {
	system "cp -R ${workpath}/cacti-${cactiversion}-PIA-${pluginversion}/* ${destroot}${cactidir}"
	}
}


notes "
**** To complete the Cacti installation ****

To complete the Cacti installation follow the steps below.  Read the documentation\
at http://www.cacti.net/documentation.php for operational instructions.


1) Install PHP and MySQL 5 (not covered).  These instructions assume MySQL 5 was\
   installed from MacPorts.

   Check to make sure the PHP variable \"mysql.default_socket\" is set to path\
   ${prefix}/var/run/mysql5/mysqld.sock by viewing the output of this terminal command:
	php -i

   If not, locate the php.ini file for your version of PHP and type the path there.


2) Set Cacti permissions.
   sudo chown -R <cacti-user>:<cacti-group> ${prefix}/share/${name}/


3) Setup MySQL and prepare it for Cacti.
   Configure MySQL (new MySQL installs)
	sudo -u mysql ${prefix}/lib/mysql5/bin/mysql_install_db

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

   Set MySQL to start at system boot (optional)
	sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

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

   Create a cacti MySQL user and cacti database.
	mysql5 -u root -p (login with new root password when prompted)
        mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti@localhost;
        mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti;
        mysql> SET PASSWORD FOR cacti@localhost = OLD_PASSWORD('<cactidb-pwd>');
	mysql> create database cacti;
	mysql> exit;

   Import the cacti database.
	sudo cat ${cactidir}/cacti.sql | mysql5 -u root -p cacti (cacti is the db name)

   Verify the Cacti Database.
	mysql5 -u root -p
	mysql> use cacti;
	mysql> show tables;
	mysql> exit;


4) Edit ${cactidir}/include/config.php to match your MySQL information.

	\$database_type = \"mysql\";
	\$database_default = \"cacti\";
	\$database_hostname = \"localhost\";
	\$database_username = \"cacti\";
	\$database_password = \"<my-cacti-password>\";


5) Place a symlink for Cacti inside your Apache document root.

	ln -s ${cactidir}  <Apache-docroot>/cacti


6) Edit the Cacti user's crontab file.
	sudo -u <cactiuser> crontab -e

  Insert the crontab entry below:
	*/5 * * * * ${prefix}/bin/php ${cactidir}/poller.php > /dev/null 2>&1


8) If you installed Cacti with the 'plugins' variant for Cacti Plugin Architecture support,\
   you must perform these additional steps.

   a) Import the PA schema.
	cd ${cactidir}
	sudo cat ${cactidir}/pa.sql | mysql5 -u root -p cacti (cacti is the db name)

   b) Download the particular Cacti plugin(s) you want and copy their folders to ${cactidir}/plugins/<plugin-dir>/.\
      For example:
	${cactidir}/plugins/weathermap/

   c) Edit ${cactidir}/include/global.php - modify the url_path to reflect Cacti's default URL\
      and add an entry to load each plugin you install; the weathermap plugin is an example:

	\$url_path = \"/cacti/\";

	\$plugins = array();
	\$plugins[] = 'weathermap';

   d) Enable the plugin in the Cacti web interface; this creates a top-level tab for the plugin in the Cacti interface\
	Console -> User Management  (select a Cacti user and check the 'View Weathermaps' checkboxes)


7) Go to http://localhost/cacti/install/index.php.
	The default user/password is admin/admin.  Select 'New Install', enter\
	the paths for SNMP / RRDtool / PHP (see below), and click 'Finish'.\
	You may now use Cacti at http://localhost/cacti/index.php.

Paths:
	snmpwalk binary path: /usr/bin/snmpwalk
	snmpget binary path: /usr/bin/snmpget

	RRDtool binary path: ${prefix}/bin/rrdtool
	PHP binary path: ${prefix}/bin/php (if not using MacPorts PHP, use appropriate path)
"
