## install.cacti-0.8.7-pgsql.sol10
## Autor: h.lehmann_AT_fh-lausitz_DOT_com
## CHANGES
## - 110428.install.cacti-0.8.7-pgsql.sol10
##   - add patches 110306.cacti.pg_concat.pgfunc.sql ff.
##   - fix parse httpdconf
## - 100930.install.cacti-0.8.7-pgsql.sol10
##   - add *patch-100930.* ff., add rotatelog.cfg
## - 100527.install.cacti-0.8.7-pgsql.sol10
##   - fix localhost.rrd-64-bit, add crontab
## - 100401.sol10.cacti.install.log


##                   HowTo install cacti+postgresql on Sol10

## - copy&paste friendly
## - based: cacti-0.8.7-pgsql
## - tested:
##   - pg-7, pg-8
##   - debian, sol10


#### variables
url=http://www.fh-lausitz.de/launic/comp/sol/100401.projekt.cacti-0.8.7-pgsql.sol10
httpdconf=/etc/apache2/httpd.conf
dirwwwdocs=/var/apache2/htdocs/
dirwwwdocs=`grep ^DocumentRoot $httpdconf | awk '{print $2}' | tail -1`
dirwwwcacti=$dirwwwdocs/cacti-0.8.7-pgsql  	## can be change later
webuser=httpd ; webgrp=staff			## ps -ef | grep httpd
webuser=`grep ^User $httpdconf | awk '{print $2}' | tail -1`
webgrp=`grep ^Group $httpdconf | awk '{print $2}' | tail -1`
nowebuser="install"			## any user without rights
dldir=/var/tmp				## downloaddir (ex /usr/src)
patch=patch 				## debian
patch=gpatch; PATH=$PATH:/opt/csw/bin  ## sol:gpatch
pgver=8  				## version postgresql (7|8)

echo "dirwwwdocs=$dirwwwdocs webuser=$webuser webgrp=$webgrp"
echo "dirwwwcacti=$dirwwwcacti"
echo "patch=$patch"
which $patch


#### download
cd $dldir
## cacti  (install from [9], not [23])
#wget -O cacti-0.8.7-pgsql.tar.gz  http://forums.cacti.net/download.php?id=10428
wget -O cacti-0.8.7-pgsql.tar.gz  "http://forums.cacti.net/download/file.php?id=10428"
## patches
wget $url/patches/cacti-0.8.7-pgsql.graphs_new.php.patch.070916-100523
wget $url/patches/cacti-0.8.7-pgsql.html_tree.err_join.patch.100526
#wget $url/patches/cacti-0.8.7-pgsql.invalid_timestamp.patch-100526
wget $url/patches/cacti-0.8.7-pgsql.invalid_timestamp.patch-100524
wget $url/patches/cacti-0.8.7-pgsql.invalid_timestamp.patch-100524-100527
wget $url/patches/cacti-0.8.7-pgsql.graphs_new.deb_fieldname.patch.0100523-100524
wget $url/patches/cacti-0.8.7-pgsql.patch-100601.guest.auth_login
wget $url/patches/cacti-0.8.7-pgsql.patch-100601.guest.auth_login.clean_html_output
wget $url/patches/cacti-0.8.7-pgsql.patch.100528.html_tree
wget $url/patches/cacti-0.8.7-pgsql.patch.100527.add_graphs.snmp_index
wget $url/patches/cacti-0.8.7-pgsql.patch.100527.adodb-lib.inc.php
wget $url/patches/cacti-0.8.7-pgsql.patch.100930.html_tree.fixselect 
wget $url/100531.cacti.conv.sql

#### install apache,php,pg etc.
## s.  100602.sol10.zone.inst.pgsql_apache_php_cacti


#### install cacti
cd $dirwwwdocs
gunzip -c $dldir/cacti-0.8.7-pgsql.tar.gz | tar -xvf -
[ "$dirwwwdocs/cacti-0.8.7" != "$dirwwwcacti" ] && mv cacti-0.8.7 $dirwwwcacti


chown -R $webuser:$webgrp $dirwwwcacti
su - $webuser 
## reload variables (s. above)

cd $dirwwwcacti


#### config
## convert cacti.sql to (postgres-7.sql, postgres-8.sql)
## - use mysql2pgsql
## - usage: copy&paste linebyline
more $dldir/100531.cacti.conv.sql 

ls -l postgres-$pgver.sql


## config config.php
ls -l lib/adodb/drivers/
## var (check it!)
dbtype=postgres
dbuser=cacti
dbpass=cacti
dbname=cacti
dbport=5432
dbip=192.168.12.14    
f=include/config.php
grep database_username $f
cp -p $f $f.old
cat $f.old | sed "s/\$database_username.*/\$database_username = \"$dbuser\";/" \ | sed "s/\$database_password.*/\$database_password = \"$dbpass\";/" \
 | sed "s/\$database_type.*/\$database_type = \"$dbtype\";/" \
 | sed "s/\$database_port.*/\$database_port = \"$dbport\";/" \
  > $f

## load DB
psql -h $dbip -U $dbuser -f postgres-$pgver.sql $dbname

#### -------------------------------------------------------------
#### patches

## s. 100522.diag.sql.cacti-0.8.7-pgsql
ls -l graphs_new.php*
cat $dldir/cacti-0.8.7-pgsql.graphs_new.php.patch.070916-100523 | $patch -p0 

## s. 100522.diag.sql.cacti-0.8.7-pgsql
## note: this patch is uggly, but working
ls -l lib/functions.php*
cat $dldir/cacti-0.8.7-pgsql.invalid_timestamp.patch-100524 | $patch -p0

## s. 100524.prob.cacti.pgsql.err_join
ls -al lib/html_tree.php*
cat $dldir/cacti-0.8.7-pgsql.html_tree.err_join.patch.100526 | $patch -p0

## s. 100524.prob.cacti.graphs_new
ls -l graphs_new.php*
cat $dldir/cacti-0.8.7-pgsql.graphs_new.deb_fieldname.patch.0100523-100524 | $patch -p0

ls -l lib/functions.php*
cat $dldir/cacti-0.8.7-pgsql.invalid_timestamp.patch-100524-100527  | $patch -p0

## s. 100526.prob.cacti.pg.no_col_oid.diag
#cat $dldir/cacti-0.8.7-pgsql.add_graphs.snmp_index.patch.100527 | patch -p0
cat $dldir/cacti-0.8.7-pgsql.patch.100527.add_graphs.snmp_index | patch -p0
cat $dldir/cacti-0.8.7-pgsql.patch.100527.adodb-lib.inc.php | patch -p0

cat $dldir/cacti-0.8.7-pgsql.patch.100528.html_tree | patch -p0

## s. 100601.prob.cacti.guest.auth_login
ls -l auth_login.php
## note: 1. patch like cacti-0.8.7f
cat $dldir/cacti-0.8.7-pgsql.patch-100601.guest.auth_login | patch -p0
cat $dldir/cacti-0.8.7-pgsql.patch-100601.guest.auth_login.clean_html_output | patch -p0
cat $dldir/cacti-0.8.7-pgsql.patch.100930.html_tree.fixselect | patch -p0



#### -------------------------------------------------------------

#### misc

## fix localhost.rrd-64-bit
## (s. 100521.prob.cacti.rrd.architecture)
cd rra
gunzip -c $dldir/localhost.rrd.xml.tgz | tar -xvf -
for i in `find . -name "*.xml"`; do $rrdtool restore $i `echo $i |sed s/.xml//g`; done



#### add crontab
# su - $webuser
tmpcron=/tmp/cron.tmp
binphp=/opt/csw/php5/bin/php 	## which php
logfile="/var/log/cacti/poller" ## /var/log/apache2/cacti_poller
crontime="0,10,20,30,40,50 * * * *" ## sol10
[ `uname -s` = "Linux" ] && crontime="*/5 * * * *"		## lnx
echo "add entry: 0,10....$binphp $dirwwwcacti/poller.php >> $l.log"
echo "save crontab $tmpcron"
## write
crontab -l > $tmpcron
cat >> $tmpcron <<EOF
$crontime l=$logfile; $binphp $dirwwwcacti/poller.php >> \$l.log 2>>\$l.err
EOF
## load
crontab $tmpcron
crontab -l
rm $tmpcron


#### using cacti
http://cactihost/cacti-0.8.7-pgsql/index.php
# login: admin admin
# - check

#### check access
## webuser must read all files, write log,rra only
cd $dirwwwcacti
chown -R $nowebuser:$webgrp .
chown -R $webuser log rra

### create rotatelog.cfg
f=/etc/logrotate.cacti.cfg
cat > $f <<EOF
# see "man logrotate" for details
## crontab: 
##  11 01 01 * *    /usr/local/etc/rotatelog -F /etc/logrotate.month.cfg
# keep 4 weeks/month worth of backlogs
rotate 4
# send errors to root
errors root@localhost
compress
# create new (empty) log files after rotating old ones
create 0640 $webuser:$webgrp 
/var/log/cacti/cacti.log {
}
/var/log/cacti/poller.log {
}
/var/log/cacti/poller.err {

}
EOF
#### ----------------------------------------------------------------
#### patches (optional, recommended)

## - details s. 110306.prob.cacti.pg_concat
num=`echo "\df concat_ws" | psql -t -h $dbip -U $dbuser $dbname`
[ $num -le 2 ] && cat $dldir/110306.cacti.pg_concat.pgfunc.sql | psql -h $dbip -U $dbuser $dbname
cat $dldir/cacti-0.8.7-pgsql.patch.110307.graphs_items.sqlconcat | patch -p0
cat $dldir/cacti-0.8.7-pgsql.patch.110317.graph_view.check_js | patch -p0
cat $dldir/cacti-0.8.7-pgsql.patch.110428.graphs.strlen | patch -p0

#### ----------------------------------------------------------------
[1] http://www.cacti.net/documentation.php

[2] http://wiki.knowledgetree.com/KnowledgeTree_3.7.*_-Install_Solaris
  KnowledgeTree 3.7.* -Install Solaris
 - cswapache2

[3] http://www.cacti.net/downloads/docs/contrib/install_solaris.html
 - 2004
 - sol9

[4] http://johannes-ruthenberg.de/php-errorlog
 - error_reporting E_ALL
 - Version ???

[5] http://www.free-it.de/archiv/talks/paper-10038/paper.html#id2459966
  Einfuehrung in Netzwerkmonitoring mit Cacti und SNMP

[6] http://www.cacti.net/downloads/docs/html/faq.html
  cacti Frequently Asked Questions

[7] http://forums.cacti.net/about5748.html
  [HOWTO] Solaris install doc
  - durcheinander
  - installation cacti selbst fehlt

[8] http://wiki.postgresql.org/wiki/Cacti
 ->  Supporting PostgreSQL data storage
  - keine konkreten Hinweise
  - supports MySQL only. There is a generic bug report named Support Multiple Databases for Cacti Engine.
  - 2005/2007

[9] http://forums.cacti.net/about23211.html
  -> cacti-0.8.7-pgsql  Scheisslink....

[10] http://osdir.com/ml/solaris.blastwave.user/2006-02/msg00035.html
- Apache2 2.2.0 php5 5.1.2
- Apache2 2.0.55 php5 5.0.5

[14] http://adodblite.sourceforge.net/index.php?start=10
- Pconnect = persisrtent ?

[15] http://www.groupe-jeremie.org/pnadodb/tute.htm
 Tutorial: Moving from MySQL to ADODB

[16] http://phplens.com/adodb/code.initialization.html
 ADOdb Library for PHP Manual

[20] http://archives.postgresql.org/pgsql-php/2002-04/msg00066.php
 - $c=(at)ADONewConnection('postgres7')

[21] http://forums.cacti.net/about1861.html&highlight=
 I have forgotten my cacti admin password

[22] https://help.ubuntu.com/community/Cacti
  Cacti on Gutsy

[23] http://www.cacti.net/downloads/docs/html/index.html

[24] http://www.infosecprojects.net/linuxtutorials/cacti-handbuch.html
  Cacti-Handbuch - Inoffizielles Cacti - Handbuch

[25] http://forums.cacti.net/about6400.html
RRD problem on Solaris 9

[26] http://www.markround.com/archives/48-Linux-iostat-monitoring-with-Cacti.html
Linux, Solaris and FreeBSD iostat monitoring with Cacti

