gather
上传用户:shbosideng
上传日期:2013-05-04
资源大小:1555k
文件大小:2k
源码类别:

SNMP编程

开发平台:

C/C++

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