| 1 |
#!/bin/csh |
| 2 |
|
| 3 |
# run this script ever 5 minutes via cron with a crontab something like: |
| 4 |
# 1,6,11,16,21,26,31,36,41,46,51,56 * * * * /home/admin/pmgraph/bin/getstats |
| 5 |
# note that this script calls MRTG |
| 6 |
|
| 7 |
# set the names or IP's of your Portmasters |
| 8 |
set Portmaster1="sconset.nantucket.net" |
| 9 |
set Portmaster2="scallop.nantucket.net" |
| 10 |
set Portmaster3="surfside.nantucket.net" |
| 11 |
|
| 12 |
# set the SNMP read community of your Portmasters |
| 13 |
set P1comm="public" |
| 14 |
set P2comm="public" |
| 15 |
set P3comm="public" |
| 16 |
|
| 17 |
# Grab a user count for each Portmaster via the snmpwalk command |
| 18 |
# You may need to use "snmpwalk -v 1" depending on your version of snmpwalk |
| 19 |
# You may also need to grep for something other than "23" |
| 20 |
set PM1=`snmpwalk $Portmaster1 $P1comm |
| 21 |
interfaces.ifTable.ifEntry.ifType|grep 23 |wc -l` |
| 22 |
set PM2=`snmpwalk $Portmaster2 $P2comm |
| 23 |
interfaces.ifTable.ifEntry.ifType|grep 23 |wc -l` |
| 24 |
set PM3=`snmpwalk $Portmaster3 $P3comm |
| 25 |
interfaces.ifTable.ifEntry.ifType|grep 23 |wc -l` |
| 26 |
|
| 27 |
# Get a grand total of users online |
| 28 |
@ TOTAL=$PM1 + $PM2 + $PM3 |
| 29 |
|
| 30 |
# MRTG needs 4 lines of input to be happy, we're only interested in the 2nd |
| 31 |
# line and possibly the first so we fill the others with junk |
| 32 |
|
| 33 |
# write out the various logs |
| 34 |
# grand total of all your Portmasters |
| 35 |
echo "0" > /home/admin/pmgraph/bin/pmgrand |
| 36 |
echo $TOTAL >> /home/admin/pmgraph/bin/pmgrand |
| 37 |
echo "0" >> /home/admin/pmgraph/bin/pmgrand |
| 38 |
echo "0" >> /home/admin/pmgraph/bin/pmgrand |
| 39 |
|
| 40 |
# Portmaster #1 |
| 41 |
echo "0" > /home/admin/pmgraph/bin/pm1-log |
| 42 |
echo $PM1 >> /home/admin/pmgraph/bin/pm1-log |
| 43 |
echo "time" >> /home/admin/pmgraph/bin/pm1-log |
| 44 |
echo "pm1" >> /home/admin/pmgraph/bin/pm1-log |
| 45 |
|
| 46 |
# Portmaster #2 |
| 47 |
echo "0" > /home/admin/pmgraph/bin/pm2-log |
| 48 |
echo $PM2 >> /home/admin/pmgraph/bin/pm2-log |
| 49 |
echo "time" >> /home/admin/pmgraph/bin/pm2-log |
| 50 |
echo "pm2" >> /home/admin/pmgraph/bin/pm2-log |
| 51 |
|
| 52 |
# Portmaster #3 |
| 53 |
echo "0" > /home/admin/pmgraph/bin/pm3-log |
| 54 |
echo $PM3 >> /home/admin/pmgraph/bin/pm3-log |
| 55 |
echo "time" >> /home/admin/pmgraph/bin/pm3-log |
| 56 |
echo "pm3" >> /home/admin/pmgraph/bin/pm3-log |
| 57 |
|
| 58 |
# and finally, run MRTG specifying our customized .cfg file |
| 59 |
eval `/home/admin/pmgraph/bin/mrtg /home/admin/pmgraph/bin/portmaster.cfg` |