Automasi konversi MRTG tradisional ke RRD tool Written by Administrator Saturday, 28 August 2004 14:47 -
Ide graffiti ini muncul dari artikel D. N. Indra Haryawan di http://www.infofreebsd.org dan merupakan lanjutan graffiti saya sebelumnya. Pemanfaatan rrdtool juga terilhami oleh tulisan pada site yang sama. (Maaf,.. saya lupa penulisnya) Brief : Bayangkan seandainya kita memiliki banyak host yang akan dimonitor via mrtg. Dan suatu saat kita harus mengupgrade-nya ke mode rrd yang di daemonized ? Tentunya akan cukup merepotnya bila menanganinya satu persatu... Nah loo... gimana donk ? So... akan lebih baik kalo prosesnya di automatisasi... ya Gak ? Step: 1. Download file 14all.cgi di http://my14all.sourceforge.net/ 2. Letakkan file tersebut pada path yang sama dengan file *.cfg lainnya , misal di /etc/mrtg (terserah sih,.. tapi ini favorit saya) 3. Ganti nama file hasil download tersebut menjadi 14all.cgi (or whatever), dan edit setelah baris : # (14all.cgi -> 14all.cfg) diberikan : $cfgfile = '/etc/mrtg/template-mrtg.cfg'; baris tersebut akan di parsing dan direplace oleh script 4. BUat script back up dulu #-----------------start script--------------------#!/bin/sh echo -n "Enter Path to Back Up : " read THEPATH echo "" echo -n "Enter Name Of Archive : " read ARCNAME tar -cf $ARCNAME.tar $THEPATH gzip $ARCNAME.tar echo "Done backup $THEPATH into $ARCNAME ...." #-----------------end script--------------------5. Run script di atas untuk membackup 6. Buat script conversi ini (jangan lupa edit seperlunya) #-----------------start script--------------------#!/bin/sh # This is my script to automatically convert convention mrtg .cfg files into rrd - daemonized mode # I usually use /etc/mrtg as my mrtg-path config
1/5
Automasi konversi MRTG tradisional ke RRD tool Written by Administrator Saturday, 28 August 2004 14:47 -
DIR=$1 ###################################################### # Use your own custom configuration by editing these ENABLERRD1="LogFormat: rrdtool" ENABLERRD2="PathAdd: /usr/local/mrtg-2/rrdtool/bin/" ENABLERRD3="LibAdd: /usr/local/mrtg-2/rrdtool/lib/perl/" ENABLEDAEMONIZED="RunAsDaemon: yes" RRDYES="RRD ENABLE" RRDNO="RRD DISABLE" ENABLEDAEMONOK="DAEMONIZED YES" ENABLEDAEMONNO="DAEMONIZED NO" MRTGDIR=/var/www/htdocs/mrtg CGIDIR=/var/www/cgi-bin TEMPLATECGI=/etc/mrtg/14all.cgi CFG=/etc/mrtg KEYCGI="14all" MRTGBINPATH="/usr/local/mrtg-2/bin/" STRINGINDEX="PES@Tnet POP Surabaya - MRTG " MKINDEXRRD="/etc/mrtg/make-index-rrd" #################################################### # Go To $CFG echo "Change dir to" $(pwd) cd $CFG #################################################### # Back Up Or No echo -n "Back Up old config ? [Y]" : read ANSWER1 echo "" if [ "$ANSWER1" = "" ]; then $ANSWER1 = "Y" fi echo $ANSWER1 if [ "$ANSWER1" = "Y" ]; then mkdir $CFG/backup cp *.cfg $CFG/backup fi ####################################################
2/5
Automasi konversi MRTG tradisional ke RRD tool Written by Administrator Saturday, 28 August 2004 14:47 -
# Daemonizing-ing all .cfg for a in $(ls $DIR *.cfg | grep cfg) do DAEMONFILE=$(cat $a | grep RunAsDaemon) if [ "$DAEMONFILE" = "" ]; then echo -n $a " " sleep 1 echo $ENABLEDAEMONNO "and now trying to enabled daemon mode in $a" echo $ENABLEDAEMONIZED >> $a sleep 1 fi if [ ! "$DAEMONFILE" = "" ]; then echo -n $a " " echo $ENABLEDAEMONOK fi done
#################################################### # RRD-ing all .cfg for a in $(ls $DIR *.cfg | grep cfg) do THISFILE=$(cat $a | grep LogFormat) if [ "$THISFILE" = "" ]; then echo -n $a " " echo $RRDNO "and now trying to enabled rrd tool on $a" echo $ENABLERRD1 >> $a echo $ENABLERRD2 >> $a echo $ENABLERRD3 >> $a sleep 1 fi if [ ! "$THISFILE" = "" ]; then echo -n $a " " echo $RRDYES fi sed 's/workDir/WorkDir/g' $a > tmp mv tmp $a done echo "" > $MKINDEXRRD echo "#!/bin/sh" > $MKINDEXRRD chmod +x $MKINDEXRRD for a in $(ls $DIR *.cfg | grep cfg)
3/5
Automasi konversi MRTG tradisional ke RRD tool Written by Administrator Saturday, 28 August 2004 14:47 -
do echo "" echo "Processing rrd cgi in $a" sed 's/template-mrtg.cfg/'$a'/g' $TEMPLATECGI > $CGIDIR/$a.cgi chmod +x $CGIDIR/$a.cgi chown www.www $CGIDIR/$a.cgi OUTPUTDIR=$(cat $a | grep WorkDir | tail -1 | cut -c10-) echo "WorkDir : " $OUTPUTDIR sleep 1 echo "#$MRTGBINPATH/indexmaker --rrdviewer=/cgi-bin/$a.cgi $CFG/$a --enumerate --columns=2 --title='$STRINGINDEX' --output=$OUTPUTDIR/index.html" >> $MKINDEXRRD echo "#$MRTGBINPATH/indexmaker --rrdviewer=/cgi-bin/$a.cgi $a --enumerate --columns=2 --title='$STRINGINDEX' --output=$OUTPUTDIR/index.html" echo "" done echo "###################################################" echo "There is file $MKINDEXRRD on your $CFG path. Edit this, and run to make rrd indexed automatically" echo "###################################################" exit 0
#-----------------end script---------------------
7. Chmod file diatas,... misal nama filenya converter,.. chmod +x converter 8. Edit file /etc/mrtg/make-index-rrd, seperlunya 9. Run /etc/mrtg/make-index-rrd 10. Hapus semua rekaman mrtg di crond 11. Buat customized startup, (seperti pada tulisan terhadulu) # ---------- start of script ---------#!/bin/sh DIR="/etc/mrtg" STRING1="/usr/local/mrtg-2/bin/mrtg /etc/mrtg" case "$1" in stop) for c in $(ps ax | grep mrtg | cut -c0-5) do PID=$(echo $c)
4/5
Automasi konversi MRTG tradisional ke RRD tool Written by Administrator Saturday, 28 August 2004 14:47 -
kill -9 $PID echo "Daemonized $PID Stopped" done rm -f $DIR/*.pid rm -f $DIR/*_l* exit 0 ;; start) for a in $(ls $DIR | grep .cfg) do TORUN=$(echo $a) echo -n "MRTG $TORUN " $STRING1/$TORUN & echo "" done exit 0 ;; restart) $0 stop $0 start exit $? ;; *) echo "Usage: `basename $0` { start | stop | restart}" ;; esac # ---------- end of script ----------
12. Chmod agar executable, dan sesuiakan dengan distro anda 13. Run script terakhir ini, dan... voila.... Note: Terima kasih xenogears atas tulisan yang sangat menarik ini. Sering-sering nulis yah :)
5/5