| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
############################################################################### |
| 4 |
# gentcucci - Generate Total Control User Count (and temp) Config and Index |
| 5 |
# (pronounced like Gent Cookie) an MRTG Tool |
| 6 |
# |
| 7 |
# Version 1.0.0 |
| 8 |
# |
| 9 |
# Copyright and written by Kevin Benton, 1999. |
| 10 |
# |
| 11 |
# Please be sure that if you choose to use this code that you let Tobi or |
| 12 |
# myself know that it's useful to you. Tobi - thanks for writing MRTG and |
| 13 |
# making it freely available to those of us who weren't quite so creative. |
| 14 |
# |
| 15 |
# NOTE 1 - At the time of this writing, we've been using this script for over |
| 16 |
# a year and it's worked like a champ. Don't let the version number fool |
| 17 |
# you - this stuff is tried and tested. |
| 18 |
# |
| 19 |
# NOTE 2 - Please be sure to pick the target method below. Look for |
| 20 |
# "INTENTIONAL ERROR" in this file, uncomment the appropriate line and delete |
| 21 |
# the two "error" lines as directed. |
| 22 |
# |
| 23 |
# NOTE 3 - This could have been written in Perl to make it a lot faster, but at |
| 24 |
# the time I wrote it, I didn't know enough Perl to do it. I certainly didn't |
| 25 |
# feel like spending the time to write it in C. I may soon rewrite this |
| 26 |
# entire script in Perl not only to make it faster, but to clean things as far |
| 27 |
# as temp files go and what not. |
| 28 |
# |
| 29 |
# NOTE 4 - tcf2mrtg returns the number of users on-line for a particular |
| 30 |
# target. This works on both ARCs and NetServers and gives us the ability to |
| 31 |
# split apart DSP's. It can of course be adapted to whatever your platform |
| 32 |
# needs require. If you only need data for the HARC aggregated together, use |
| 33 |
# the MIB .1.3.6.1.4.1.429.4.2.1.10.0 or whatever is current for the HARC code |
| 34 |
# you're using. |
| 35 |
############################################################################### |
| 36 |
|
| 37 |
############################################################################### |
| 38 |
# store in users index file |
| 39 |
|
| 40 |
stf() { |
| 41 |
echo "$1" >>$TEMP_FILE |
| 42 |
} |
| 43 |
|
| 44 |
############################################################################### |
| 45 |
# store in temperature index file |
| 46 |
|
| 47 |
stfd() { |
| 48 |
echo "$1" >>$TEMP_FILE2 |
| 49 |
} |
| 50 |
|
| 51 |
############################################################################### |
| 52 |
# store in temperature config |
| 53 |
|
| 54 |
stod() { |
| 55 |
echo "$1" >>$degree_file |
| 56 |
} |
| 57 |
|
| 58 |
############################################################################### |
| 59 |
# store in users config |
| 60 |
|
| 61 |
stou() { |
| 62 |
echo "$1" >>$output_file |
| 63 |
} |
| 64 |
|
| 65 |
############################################################################### |
| 66 |
|
| 67 |
########################## CONFIGURATION PARAMETERS ########################### |
| 68 |
# output_dir is where MRTG will be storing configs. A directory www should |
| 69 |
# exist under that with the directories tcusercount and tcdegree below that. |
| 70 |
export output_dir=/usr/local/mrtg-2.8.12/local-config |
| 71 |
# output_file is the MRTG user count config file. |
| 72 |
export output_file=$output_dir/mrtg.tcusercount.cfg |
| 73 |
# degree_file is the MRTG chassis temperature config file. |
| 74 |
export degree_file=$output_dir/mrtg.tcdegree.cfg |
| 75 |
# ro_comm is the read only SNMP community to use to grab data with. |
| 76 |
export ro_comm=public |
| 77 |
########################## CONFIGURATION PARAMETERS ########################### |
| 78 |
|
| 79 |
export TEMP_FILE=/tmp/gentcuc.$$ |
| 80 |
export TEMP_FILE2=/tmp/gentcuc.$$.2 |
| 81 |
rm -f $TEMP_FILE 2>/dev/null >/dev/null |
| 82 |
trap "rm -f $TEMP_FILE $TEMP_FILE2 2>/dev/null >/dev/null ; exit" 1 2 15 |
| 83 |
touch $TEMP_FILE |
| 84 |
|
| 85 |
index=${output_dir}/www/tcusercount/index.htm |
| 86 |
bigindex=${output_dir}/www/tcusercount/bigindex.htm |
| 87 |
degreeindex=${output_dir}/www/tcdegree/index.htm |
| 88 |
bigdegreeindex=${output_dir}/www/tcdegree/bigindex.htm |
| 89 |
|
| 90 |
# Create mrtg.tcusercount.cfg header |
| 91 |
cat >$output_file <<SH_EOF1 |
| 92 |
################################################################## |
| 93 |
# CAUTION: This file is automatically generated. Do not edit. # |
| 94 |
# Changes should be made in gwcs.list only. # |
| 95 |
################################################################## |
| 96 |
|
| 97 |
Workdir: $output_dir |
| 98 |
Refresh: 300 |
| 99 |
Interval: 5 |
| 100 |
WriteExpires: Yes |
| 101 |
|
| 102 |
Directory[^]: www/tcusercount/ |
| 103 |
PageTop[^]: <H1> |
| 104 |
PageTop[\$]: Total Control Chassis User Count</H1> |
| 105 |
Options[^]: gauge noinfo |
| 106 |
YLegend[^]: Users On |
| 107 |
ShortLegend[^]: Users |
| 108 |
Title[$]: Total Control Chassis User Count |
| 109 |
XZoom[^]: 2.0 |
| 110 |
YZoom[^]: 2.0 |
| 111 |
|
| 112 |
SH_EOF1 |
| 113 |
|
| 114 |
# Create mrtg.tcdegree.cfg header |
| 115 |
cat >$degree_file <<SH_EOF2 |
| 116 |
################################################################## |
| 117 |
# CAUTION: This file is automatically generated. Do not edit. # |
| 118 |
# Changes should be made in nmcs.list only. # |
| 119 |
################################################################## |
| 120 |
|
| 121 |
Workdir: $output_dir |
| 122 |
Refresh: 300 |
| 123 |
Interval: 5 |
| 124 |
WriteExpires: Yes |
| 125 |
Directory[^]: www/tcdegree/ |
| 126 |
PageTop[^]: <H1> |
| 127 |
PageTop[\$]: Total Control Chassis Temperature</H1> |
| 128 |
Options[^]: gauge noinfo nopercent |
| 129 |
YLegend[^]: Fahrenheit |
| 130 |
ShortLegend[^]: Temp |
| 131 |
Title[$]: Total Control Chassis Temperature |
| 132 |
XZoom[^]: 2.0 |
| 133 |
YZoom[^]: 2.0 |
| 134 |
|
| 135 |
SH_EOF2 |
| 136 |
|
| 137 |
# Create master index temp file |
| 138 |
stf "<HTML>" |
| 139 |
stf "<HEAD><TITLE>Total Control SED_REPLACE_WITH_NAME</TITLE></HEAD>" |
| 140 |
stf "<BODY BGCOLOR=WHITE>" |
| 141 |
stf "<H1>Total Control SED_REPLACE_WITH_NAME</H1>" |
| 142 |
stf "Updated `date`<P>" |
| 143 |
stf "<A HREF=\"SED_REPLACE_WITH_INDEX.HTM\">Click here for SED_REPLACE_WITH_SIZE size images</A><BR>" |
| 144 |
stf "<TABLE BORDER>" |
| 145 |
|
| 146 |
# Process into mrtg.tcusercount.cfg and master user count index from gwcs.list |
| 147 |
while read line |
| 148 |
do |
| 149 |
if echo "$line" | egrep '^#' >/dev/null 2>/dev/null |
| 150 |
then |
| 151 |
continue |
| 152 |
fi |
| 153 |
if [ -z "$line" ] |
| 154 |
then |
| 155 |
continue |
| 156 |
fi |
| 157 |
target="`echo \"$line\" | cut -d: -f1 | sed -e 's/+/ /g'`" |
| 158 |
tag="`echo \"$line\" | \ |
| 159 |
cut -d: -f1 | \ |
| 160 |
sed -e 's/+/_/g' | \ |
| 161 |
sed -e 's/\_.*\@/_/g' | \ |
| 162 |
cut -d@ -f2`" |
| 163 |
title="`echo \"$line\" | cut -d: -f2`" |
| 164 |
maxb="`echo \"$line\" | cut -d: -f3`" |
| 165 |
absm="`echo \"$line\" | cut -d: -f4`" |
| 166 |
INTENTIONAL ERROR: YOU MUST PICK 1 OF THE 2 TARGETS BELOW AND DELETE THIS LINE |
| 167 |
# stou "Target[$tag]: \`/usr/local/mrtg-2.8.12/local-config/tcf2mrtg \"$target\"\`" |
| 168 |
# stou "Target[$tag]: .1.3.6.1.4.1.429.4.2.1.10.0:${ro_comm}@$target" |
| 169 |
INTENTIONAL ERROR: YOU MUST PICK ONE OF THE TARGETS ABOVE AND DELETE THIS LINE |
| 170 |
stou "Title[$tag]: $title" |
| 171 |
stou "PageTop[$tag]: $title" |
| 172 |
if [ ! "$absm" = "0" ] |
| 173 |
then |
| 174 |
stou "AbsMax[$tag]: $absm" |
| 175 |
fi |
| 176 |
stou "MaxBytes[$tag]: $maxb" |
| 177 |
stou "WithPeak[$tag]: ymwd" |
| 178 |
stou "" |
| 179 |
stf " <TR>" |
| 180 |
stf " <TD ROWSPAN=2>" |
| 181 |
stf " <CENTER><A HREF=\"$tag.html\">$title</A><BR>" |
| 182 |
stf " `/home/httpd/cgi-bin/tcnowstat \"$tag\" \"$maxb\"`<BR>" |
| 183 |
stf " Potential Users: $maxb</CENTER>" |
| 184 |
stf " <TD>Today<BR>5 Min</TD>" |
| 185 |
stf " <TD>" |
| 186 |
stf " <IMG SRC=\"$tag-day.png\" SED_REPLACE_WITH_PICSIZE>" |
| 187 |
stf " </TD>" |
| 188 |
stf " </TR>" |
| 189 |
stf " <TR>" |
| 190 |
stf " <TD>This Week<BR>30 Min</TD>" |
| 191 |
stf " <TD>" |
| 192 |
stf " <IMG SRC=\"$tag-week.png\" SED_REPLACE_WITH_PICSIZE>" |
| 193 |
stf " </TD>" |
| 194 |
stf " </TR>" |
| 195 |
done <gwcs.list |
| 196 |
|
| 197 |
stfd "<HTML>" |
| 198 |
stfd "<HEAD><TITLE>Total Control SED_REPLACE_WITH_NAME</TITLE></HEAD>" |
| 199 |
stfd "<BODY BGCOLOR=WHITE>" |
| 200 |
stfd "<H1>Total Control SED_REPLACE_WITH_NAME</H1>" |
| 201 |
stfd "Updated `date`<P>" |
| 202 |
stfd "<A HREF=\"SED_REPLACE_WITH_INDEX.HTM\">Click here for SED_REPLACE_WITH_SIZE size images</A><BR>" |
| 203 |
stfd "<TABLE BORDER>" |
| 204 |
|
| 205 |
# Process into mrtg.tcusercount.cfg and master user count index from gwcs.list |
| 206 |
while read line |
| 207 |
do |
| 208 |
if echo "$line" | egrep '^#' >/dev/null 2>/dev/null |
| 209 |
then |
| 210 |
continue |
| 211 |
fi |
| 212 |
if [ -z "$line" ] |
| 213 |
then |
| 214 |
continue |
| 215 |
fi |
| 216 |
name="`echo \"$line\" | cut -d: -f1 | sed -e 's/+/ /g'`" |
| 217 |
tag="`echo \"$line\" | cut -d: -f1 | sed -e s/+/_/g`" |
| 218 |
title="`echo \"$line\" | cut -d: -f2`" |
| 219 |
stod "##################################################################" |
| 220 |
stod "Target[$tag]: .1.3.6.1.4.1.429.1.2.2.5.0&.1.3.6.1.4.1.429.1.2.2.5.0:public@$name * 1.8 + 32" |
| 221 |
stod "Title[$tag]: $title" |
| 222 |
stod "PageTop[$tag]: $title" |
| 223 |
stod "MaxBytes[$tag]: 200" |
| 224 |
stfd " <TD ROWSPAN=2>" |
| 225 |
stfd " <CENTER><A HREF=\"$tag.html\">$title</A><BR>" |
| 226 |
stfd " `/home/httpd/cgi-bin/tcnowtemp \"$tag\"`</CENTER>" |
| 227 |
stfd " <TD>Today<BR>5 Min</TD>" |
| 228 |
stfd " <TD>" |
| 229 |
stfd " <IMG SRC=\"$tag-day.png\" SED_REPLACE_WITH_PICSIZE>" |
| 230 |
stfd " </TD>" |
| 231 |
stfd " </TR>" |
| 232 |
stfd " <TR>" |
| 233 |
stfd " <TD>This Week<BR>30 Min</TD>" |
| 234 |
stfd " <TD>" |
| 235 |
stfd " <IMG SRC=\"$tag-week.png\" SED_REPLACE_WITH_PICSIZE>" |
| 236 |
stfd " </TD>" |
| 237 |
stfd " </TR>" |
| 238 |
done <nmcs.list |
| 239 |
|
| 240 |
# close the indexes up tight |
| 241 |
stf "</TABLE></BODY></HTML>" |
| 242 |
stfd "</TABLE></BODY></HTML>" |
| 243 |
|
| 244 |
# create normal and big indexes for user count and temperature. |
| 245 |
cat $TEMP_FILE | sed -e 's/SED_REPLACE_WITH_INDEX.HTM/bigindex.htm/g' | \ |
| 246 |
sed -e 's/SED_REPLACE_WITH_SIZE/double/g' | \ |
| 247 |
sed -e 's/SED_REPLACE_WITH_NAME/User Count Analysis/g' | \ |
| 248 |
sed -e 's/SED_REPLACE_WITH_PICSIZE//g' >$index |
| 249 |
cat $TEMP_FILE | sed -e 's/SED_REPLACE_WITH_INDEX.HTM/index.htm/g' | \ |
| 250 |
sed -e 's/SED_REPLACE_WITH_SIZE/normal/g' | \ |
| 251 |
sed -e 's/SED_REPLACE_WITH_NAME/User Count Analysis/g' | \ |
| 252 |
sed -e 's/SED_REPLACE_WITH_PICSIZE/WIDTH=1000 HEIGHT=270/g' >$bigindex |
| 253 |
cat $TEMP_FILE2 | sed -e 's/SED_REPLACE_WITH_INDEX.HTM/bigindex.htm/g' | \ |
| 254 |
sed -e 's/SED_REPLACE_WITH_SIZE/double/g' | \ |
| 255 |
sed -e 's/SED_REPLACE_WITH_NAME/Chassis Temperature/g' | \ |
| 256 |
sed -e 's/SED_REPLACE_WITH_PICSIZE//g' >$degreeindex |
| 257 |
cat $TEMP_FILE2 | sed -e 's/SED_REPLACE_WITH_INDEX.HTM/index.htm/g' | \ |
| 258 |
sed -e 's/SED_REPLACE_WITH_SIZE/normal/g' | \ |
| 259 |
sed -e 's/SED_REPLACE_WITH_NAME/Chassis Temperature/g' | \ |
| 260 |
sed -e 's/SED_REPLACE_WITH_PICSIZE/WIDTH=1000 HEIGHT=270/g' >$bigdegreeindex |
| 261 |
rm $TEMP_FILE $TEMP_FILE2 |