Welcome To mkmrtg.sh

Hi! If your here it must mean your familiar with MRTG. The basis of this page is to help you with a front-end for MRTG. A quick over-view can be found to the right in the Who, What, Why, Where, How section.

Currently, mkmrtg.sh is up to Version 0.9
Remember to check out the stuff on the right.
Then click here to jump to the code. :)

------------------------------------------

Wednesday, September 10, 2008

Add-On: Timer (Updated)

I was thinking. Does my machine take to long to run through all the mrtg config files? (I graph 20+ at home and 100+ at work) I learned from a friend a while back that in shell scripting, you can improve over-all performance by making your tasks run one-after-the-other. So, if you have a LOT of stuff that runs at 1:00AM, instead of a lot crontab entries, you put all those entries into a script and let the crontab run the script you created.

If your not doing that, I suggest you do. Now, I wanted to make sure that this script is not running for more than 5 minutes. So, I created a little add-on to let me know everything is ok. :)



mrtg.sh


#! /bin/bash
ds=`date +%s`
cfg="/usr/bin/env LANG=C /etc/mrtg/bin/mrtg /etc/mrtg/monitor"
for c in `ls /etc/mrtg/monitor | grep cfg | cut -d"." -f1 | sort -u`
do
$cfg/$c.cfg
done

loc="/srv/www/htdocs/mrtg"
gl=`cat $loc/nav.html | wc -l`
cl=`expr $gl - 2`
gf=`tail -n$cl $loc/nav.html`
de=`date +%s`
dt=`expr $de - $ds`
dm=`expr $dt / 60`
echo "<html><head><title>Navigation</title><meta http-equiv=refresh content=60></head><body>" > $loc/nav.html
echo "<h4>MRTG Nodes</h4><font size=0>`date`<br>Run: $dt sec ($dm min)</font><p><table border=0>" >> $loc/nav.html
echo "$gf" >> $loc/nav.html



There you have it. Note, this assumes the location of the mkmrtg.sh output. Change the 'loc' variable (green above) if needed.

This got me to thinking... You could utilize curl to get the time it took and graph that too! Isn't MRTG GREAT!!!!

UPDATE: I changed the way it gets is config files. Now all you have to do is drop the .cfg file into the directory and it will automatically pick it up.

Friday, September 5, 2008

Version 0.9 Notes Section Added

Well, we are to Version 0.9. I want to make sure Version 1.0 has as many bugs out of it as possible and I also want to make sure it is documented well enough. So, if you had to tweak the script or something isn't quite right, please let me know.

I am pleased to note that Version 0.9 has the addition of a notes section. Rather than have you dig through the script for where to put your notes I decided to have notes entered into their own file. Hopefully this will keep things simple.

The notes should be formatted as such:
NODE1:This is my note.
NODE2:This is another note.
etc. etc. etc.

The notes will appear below all of the graphs.
(Just a thought, I may in the future decide to make it optional for the top or bottom. This is so if you have a 48 port switch, you don't have to scroll all the way down.)

Version 0.9

#! /bin/bash

# Version 0.9

### CONFIG ###
# What Kind Of Image Output Does Your MRTG Setup Produce? PNG or GIF?
pic="png"
# Where Is Your MRTG Output Located?
loc="/srv/www/htdocs/mrtg"
# Where Are Your Notes?
notes="/usr/local/bin/mkmrtg.sh.notes"

### USAGE ###
#` Place this script in /usr/local/bin (or /usr/bin)
# chmod 700 mkmrtg.sh
# ./mkmrtg.sh
# Note: This script assumes your nodes are all in the same place.
# Example:
# /srv/www/htdocs/mrtg/
# /srv/www/htdocs/mrtg/NODE1/
# /srv/www/htdocs/mrtg/NODE2/
# Then point your browser to the local machine (however you setup your Apache).


### RELEASE NOTES ###
# Yeah! mkmrtg.sh can now be run from anywhere on your system. My suggestion is to keep it in some place like "/usr/local/bin".
# Depending on how you installed MRTG, you may have "gif" images instead of "png" images. If so, change "png" to "gif" at the top.
# If your output from MRTG is not located in "/srv/www/htdocs/mrtg" then you need to change the location variable "loc" at the top to the place you pointed your MRTG output.
# Please make sure there are NO "-" (dashes) in your interface identifyer! Example: "eth0-1" is NOT good. Use "eth0_1" instead. :)
# NOTES Section For Your Devices. Be default it is located at /usr/local/bin/mkmrtg.sh.notes If this is not where you want your notes, change it. Notes should be added in the following syntax (making note that "folder name" should be the EXACT same as the folder name):
# [folder name]:[notes]
# Example= NODE1:Unable To Ping node1 as we are rejecting icmp so currently no data.

### FUTURE ###
# - PHP Integration
# - Web Based Mangement via PHP
# - Clean Up Coding :)

for h in `ls $loc | fgrep -v "."`
do
html="index.html"
htlc="$loc/$h"
echo "<html><head><title>MRTG:$h</title><meta http-equiv=refresh content=60></head><body>" > $htlc/$html
echo "<h3>MRTG:$h</h3><hr width=500 align=left><table border=0>" >> $htlc/$html
for s in `ls $htlc | grep $pic | grep day`
do
htnm=`echo "$s" | cut -d"." -f1 | cut -d"-" -f1`
echo "<tr><td><a href=$htnm.html><img src=$s border=0></a></td><td>$htnm</td></tr>" >> $htlc/$html
done
echo "<!-- NOTESDIV --></table>" >> $htlc/$html
echo "</body></html>" >> $htlc/$html
done

rm $loc/index.html

nvdr="$loc/nav.html"
echo "<html><head><title>Navigation</title></head><body>" > $nvdr
echo "<h4>MRTG Nodes</h4><table border=0>" >> $nvdr
for m in `find $loc | fgrep "index.html" | grep -v "~" | sort -n | cut -d"g" -f2 | cut -d"/" -f2-200`
do
indn=`echo "$m" | cut -d"/" -f1`
echo "<tr><td><a href=$m target=view><font size=2>$indn</font></a></td></tr>" >> $nvdr
done
echo "</table></body></html>" >> $nvdr

echo "<html><head><title>MRTG On `hostname`</title></head><frameset cols=200,100%><frame src=nav.html><frame src=welcome.html name=view></frameset>" > $loc/index.html

echo "<html><head><title>Welcome</title></head>" > $loc/welcome.html
echo "<h3>Welcome To MRTG!</h3>" > $loc/welcome.html
echo "<p>The 'Nodes' column on the left contains all nodes that you have selected to monitor via MRTG." >> $loc/welcome.html
echo "<p>Have fun! :D<p><font color=grey>mkmrtg.sh - Ver. 0.9" >> $loc/welcome.html
echo "<p>Script & Front-End Written By Joe McShinsky <font size=0>(Contributions Noted In Script)</font></font>" >> $loc/welcome.html

touch $notes
for n in `cat $notes | cut -d":" -f1`
do
ind=`cat $loc/$n/index.html | grep -B2000 NOTESDIV | grep -v NOTESDIV`
echo "$ind" > $loc/$n/index.html
echo "<!-- NOTESDIV --></table>" >> $loc/$n/index.html
echo "`cat $notes | grep $n`" | cut -d":" -f2-200 >> $loc/$n/index.html
echo "</body></html>" >> $loc/$n/index.html
done

Thursday, August 28, 2008

Version 0.8

#! /bin/bash

# Version 0.8

### CONFIG ###
# What Kind Of Image Output Does Your MRTG Setup Produce? PNG or GIF?
pic="png"
# Where Is Your MRTG Output Located?
loc="/srv/www/htdocs/mrtg"

### USAGE ###
#` Place this script in /usr/local/bin (or /usr/bin)
# chmod 700 mkmrtg.sh
# ./mkmrtg.sh
# Note: This script assumes your nodes are all in the same place.
# Example:
# /srv/www/htdocs/mrtg/
# /srv/www/htdocs/mrtg/NODE1/
# /srv/www/htdocs/mrtg/NODE2/
# Then point your browser to the local machine (however you setup your Apache).


### RELEASE NOTES ###
# Yeah! mkmrtg.sh can now be run from anywhere on your system. My suggestion is to keep it in some place like "/usr/local/bin".
# Depending on how you installed MRTG, you may have "gif" images instead of "png" images. If so, change "png" to "gif" at the top.
# If your output from MRTG is not located in "/srv/www/htdocs/mrtg" then you need to change the location variable "loc" at the top to the place you pointed your MRTG output.
# Please make sure there are NO "-" (dashes) in your interface identifyer! Example: "eth0-1" is NOT good. Use "eth0_1" instead. :)

### FUTURE ###
# - Notes Section via Config file
# - PHP Integration
# - Web Based Mangement via PHP
# - Clean Up Coding :)

for h in `ls $loc | fgrep -v "."`
do
html="index.html"
htlc="$loc/$h"
echo "<html><head><title>MRTG:$h</title><meta http-equiv=refresh content=60></head><body>" > $htlc/$html
echo "<h3>MRTG:$h</h3><hr width=500 align=left><table border=0>" >> $htlc/$html
for s in `ls $htlc | grep $pic | grep day`
do
htnm=`echo "$s" | cut -d"." -f1 | cut -d"-" -f1`
echo "<tr><td><a href=$htnm.html><img src=$s border=0></a></td><td>$htnm</td></tr>" >> $htlc/$html
done
echo "</table></body></html>" >> $htlc/$html
done

rm $loc/index.html

nvdr="$loc/nav.html"
echo "<html><head><title>Navigation</title></head><body>" > $nvdr
echo "<h4>MRTG Nodes</h4><table border=0>" >> $nvdr
for m in `find $loc | fgrep "index.html" | grep -v "~" | sort -n | cut -d"g" -f2 | cut -d"/" -f2-200`
do
indn=`echo "$m" | cut -d"/" -f1`
echo "<tr><td><a href=$m target=view><font size=2>$indn</font></a></td></tr>" >> $nvdr
done
echo "</table></body></html>" >> $nvdr

echo "<html><head><title>MRTG On `hostname`</title></head><frameset cols=200,100%><frame src=nav.html><frame src=welcome.html name=view></frameset>" > $loc/index.html

echo "<html><head><title>Welcome</title></head>" > $loc/welcome.html
echo "<h3>Welcome To MRTG!</h3>" > $loc/welcome.html
echo "<p>The 'Nodes' column on the left contains all nodes that you have selected to monitor via MRTG." >> $loc/welcome.html
echo "<p>Have fun! :D<p><font color=grey>mkmrtg.sh - Ver. 0.8" >> $loc/welcome.html
echo "<p>Script & Front-End Written By Joe McShinsky <font size=0>(Contributions Noted In Script)</font></font>" >> $loc/welcome.html

Version 0.7

#! /bin/bash

# Version 0.7

### RELEASE NOTES ###
# Yeah! mkmrtg.sh can now be run from anywhere on your system. My suggestion is to keep it in some place like "/usr/local/bin".
# Depending on how you installed MRTG, you may have "gif" images instead of "png" images. If so, change "png" to "gif". Its only in one spot below.
# If your output from MRTG is not located in "/srv/www/htdocs/mrtg" then you need to change the location variable "loc" below to the place you pointed your MRTG output.

### USAGE ###
#` Place this script in /usr/local/bin (or /usr/bin)
# chmod 700 mkmrtg.sh
# ./mkmrtg.sh
# Note: This script assumes your nodes are all in the same place.
# Example:
# /srv/www/htdocs/mrtg/
# /srv/www/htdocs/mrtg/NODE1/
# /srv/www/htdocs/mrtg/NODE2/
# /srv/www/htdocs/mrtg/NODE3/
# NOTE: Please make sure there are NO "-" (dashes) in your interface identifyer! Example: "eth0-1" is NOT good. Use "eth0_1" instead. :)
# Then point your browser to the local machine (however you setup your Apache).

### FUTURE ###
# - Notes Section via Config file
# - PHP Integration
# - Web Based Mangement via PHP
# - Clean Up Coding :)

loc="/srv/www/htdocs/mrtg"
for h in `ls $loc | fgrep -v "."`
do

html="index.html"
htlc="$loc/$h"

echo "<html><head><title>MRTG:$h</title><meta http-equiv=refresh content=60></head><body>" > $htlc/$html
echo "<h3>MRTG:$h</h3><hr width=500 align=left><table border=0>" >> $htlc/$html

for s in `ls $htlc | grep png | grep day`
do
htnm=`echo "$s" | cut -d"." -f1 | cut -d"-" -f1`
echo "<tr><td><a href=$htnm.html><img src=$s border=0></a></td><td>$htnm</td></tr>" >> $htlc/$html
done
echo "</table></body></html>" >> $htlc/$html
done

rm $loc/index.html

nvdr="$loc/nav.html"
echo "<html><head><title>Navigation</title></head><body>" > $nvdr
echo "<h4>MRTG Nodes</h4><table border=0>" >> $nvdr

for m in `find $loc | fgrep "index.html" | grep -v "~" | sort -n | cut -d"g" -f2 | cut -d"/" -f2-200`
#for m in `find $loc | fgrep "index.html" | grep -v "~" | sort -n | cut -d"." -f2-200 | cut -d"/" -f2-200`
do
indn=`echo "$m" | cut -d"/" -f1`
echo "<tr><td><a href=$m target=view><font size=2>$indn</font></a></td></tr>" >> $nvdr
done

echo "</table></body></html>" >> $nvdr

echo "<html><head><title>MRTG On `hostname`</title></head><frameset cols=200,100%><frame src=nav.html><frame src=welcome.html name=view></frameset>" > $loc/index.html

echo "<html><head><title>Welcome</title></head>" > $loc/welcome.html
echo "<h3>Welcome To MRTG!</h3>" > $loc/welcome.html
echo "<p>The 'Nodes' column on the left contains all nodes that you have selected to monitor via MRTG." >> $loc/welcome.html
echo "<p>Have fun! :D<p><font color=grey>mkmrtg.sh - Ver. 0.7" >> $loc/welcome.html
echo "<p>Script & Front-End Written By Joe McShinsky <font size=0>(Contributions Noted In Script)</font></font>" >> $loc/welcome.html

Monday, August 25, 2008

Version 0.6

#! /bin/bash

# Version 0.6

### RELEASE NOTES ###
# Currently, as far as I know, this needs to br run from /srv/www/htdocs/mrtg.
# Taking a quick look, I can see that I just need to update:
# for h in `ls | fgrep -v "."`
# to: for h in `ls $loc | fgrep -v "."`
# With $loc being set prior to this line.
# Depending on how you installed MRTG, you may have "gif" images instead of "png"
# images. If so, change "png" to "gif". Its only in one spot below.

### USAGE ###
# Place this script in /srv/www/htdocs/mrtg
# chmod 700 mkmrtg.sh
# ./mkmrtg.sh
# Note: This script assumes your nodes are all in the same place.
# Example:
# /srv/www/htdocs/mrtg/
# /srv/www/htdocs/mrtg/NODE1/
# /srv/www/htdocs/mrtg/NODE2/
# /srv/www/htdocs/mrtg/NODE3/
# Then point your browser to the local machine (however you setup your Apache).

### FUTURE ###
# - Update Location Problem
# - Notes Section via Config file
# - PHP Integration
# - Web Based Mangement via PHP
# - Clean Up Coding :)

for h in `ls | fgrep -v "."`
do

html="index.html"
htlc="`pwd`/$h"

echo "<html><head><title>MRTG:$h</title><meta http-equiv=refresh content=60></head><body>" > $htlc/$html
echo "<h3>MRTG:$h</h3><hr width=500 align=left><table border=0>" >> $htlc/$html

for s in `ls $htlc | grep png | grep day`
do
htnm=`echo "$s" | cut -d"." -f1 | cut -d"-" -f1`
echo "<tr><td><a href=$htnm.html><img src=$s border=0></a></td><td>$htnm</td></tr>" >> $htlc/$html
done
echo "</table></body></html>" >> $htlc/$html
done

rm index.html

nvdr="`pwd`/nav.html"
echo "<html><head><title>Navigation</title></head><body>" > $nvdr
echo "<h4>MRTG Nodes</h4><table border=0>" >> $nvdr

for m in `find | fgrep "index.html" | grep -v "~" | sort -n | cut -d"." -f2-200 | cut -d"/" -f2-200`
do
indn=`echo "$m" | cut -d"/" -f1`
echo "<tr><td><a href=$m target=view><font size=2>$indn</font></a></td></tr>" >> $nvdr
done

echo "</table></body></html>" >> $nvdr

echo "<html><head><title>MRTG On `hostname`</title></head><frameset cols=200,100%><frame src=nav.html><frame src=welcome.html name=view></frameset>" > index.html

echo "<html><head><title>Welcome</title></head>" > welcome.html
echo "<h3>Welcome To MRTG!</h3>" > welcome.html
echo "<p>The 'Nodes' column on the left contains all nodes that you have selected to monitor via MRTG." >> welcome.html
echo "<p>Have fun! :D<p><font color=grey>mkmrtg.sh - Ver. 0.6" >> welcome.html
echo "<p>Script & Front-End Written By Joe McShinsky <font size=0>(Contributions Noted In Script)</font></font>" >> welcome.html

Thursday, August 21, 2008

Screen-Shot



It may not have a lot of bells & whistles but it gets the job done and its easy to navigate.